From bcbb2ec7927849117bfedac87a3726808890d19c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 25 Mar 2013 12:45:27 +0400 Subject: remove localized_js.php; integrate with other startup JS stuff --- include/functions.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 5582c2b0b..32fc5ae2a 100644 --- a/include/functions.php +++ b/include/functions.php @@ -4090,4 +4090,42 @@ return $max_ts; } + function T_js_decl($s1, $s2) { + if ($s1 && $s2) { + $s1 = preg_replace("/\n/", "", $s1); + $s2 = preg_replace("/\n/", "", $s2); + + $s1 = preg_replace("/\"/", "\\\"", $s1); + $s2 = preg_replace("/\"/", "\\\"", $s2); + + return "T_messages[\"$s1\"] = \"$s2\";\n"; + } + } + + function init_js_translations() { + + print 'var T_messages = new Object(); + + function __(msg) { + if (T_messages[msg]) { + return T_messages[msg]; + } else { + return msg; + } + } + + function ngettext(msg1, msg2, n) { + return (parseInt(n) > 1) ? msg2 : msg1; + }'; + + $l10n = _get_reader(); + + for ($i = 0; $i < $l10n->total; $i++) { + $orig = $l10n->get_original_string($i); + $translation = __($orig); + + print T_js_decl($orig, $translation); + } + } + ?> -- cgit v1.2.3