diff options
-rwxr-xr-x | classes/feeds.php | 2 | ||||
-rwxr-xr-x | classes/rpc.php | 43 | ||||
-rw-r--r-- | include/functions.php | 36 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | js/App.js | 16 | ||||
-rwxr-xr-x | js/common.js | 16 | ||||
-rw-r--r-- | prefs.php | 2 |
7 files changed, 70 insertions, 47 deletions
diff --git a/classes/feeds.php b/classes/feeds.php index 416e1c026..7ea9ca474 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -509,7 +509,7 @@ class Feeds extends Handler_Protected { "disable_cache" => (bool) $disable_cache]; // this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc - $reply['runtime-info'] = RPC::make_runtime_info(); + $reply['runtime-info'] = RPC::_make_runtime_info(); print json_encode($reply); } diff --git a/classes/rpc.php b/classes/rpc.php index a4ee77c11..ee655b3ab 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -7,6 +7,38 @@ class RPC extends Handler_Protected { return array_search($method, $csrf_ignored) !== false; }*/ + private function _translations_as_array() { + + global $text_domains; + + $rv = []; + + foreach (array_keys($text_domains) as $domain) { + $l10n = _get_reader($domain); + + for ($i = 0; $i < $l10n->total; $i++) { + if (isset($l10n->table_originals[$i * 2 + 2]) && $orig = $l10n->get_original_string($i)) { + if(strpos($orig, "\000") !== false) { // Plural forms + $key = explode(chr(0), $orig); + //print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular + //print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural + + $rv[$key[0]] = _ngettext($key[0], $key[1], 1); // Singular + $rv[$key[1]] = _ngettext($key[0], $key[1], 2); // Plural + + } else { + $translation = _dgettext($domain,$orig); + //print T_js_decl($orig, $translation); + $rv[$orig] = $translation; + } + } + } + } + + return $rv; + } + + function togglepref() { $key = clean($_REQUEST["key"]); set_pref($key, !get_pref($key)); @@ -66,7 +98,7 @@ class RPC extends Handler_Protected { function getRuntimeInfo() { $reply = [ - 'runtime-info' => $this->make_runtime_info() + 'runtime-info' => $this->_make_runtime_info() ]; print json_encode($reply); @@ -147,8 +179,9 @@ class RPC extends Handler_Protected { if ($error == Errors::E_SUCCESS) { $reply = []; - $reply['init-params'] = $this->make_init_params(); - $reply['runtime-info'] = $this->make_runtime_info(); + $reply['init-params'] = $this->_make_init_params(); + $reply['runtime-info'] = $this->_make_runtime_info(); + $reply['translations'] = $this->_translations_as_array(); print json_encode($reply); } else { @@ -377,7 +410,7 @@ class RPC extends Handler_Protected { print json_encode($rv); } - private function make_init_params() { + private function _make_init_params() { $params = array(); foreach ([Prefs::ON_CATCHUP_SHOW_NEXT_FEED, Prefs::HIDE_READ_FEEDS, @@ -440,7 +473,7 @@ class RPC extends Handler_Protected { } } - static function make_runtime_info() { + static function _make_runtime_info() { $data = array(); $pdo = Db::pdo(); diff --git a/include/functions.php b/include/functions.php index 6d845035e..d96b8c089 100644 --- a/include/functions.php +++ b/include/functions.php @@ -455,42 +455,6 @@ } } - 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); - }'; - - global $text_domains; - - foreach (array_keys($text_domains) as $domain) { - $l10n = _get_reader($domain); - - for ($i = 0; $i < $l10n->total; $i++) { - $orig = $l10n->get_original_string($i); - if(strpos($orig, "\000") !== false) { // Plural forms - $key = explode(chr(0), $orig); - print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular - print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural - } else { - $translation = _dgettext($domain,$orig); - print T_js_decl($orig, $translation); - } - } - - } - } - function get_theme_path($theme) { $check = "themes/$theme"; if (file_exists($check)) return $check; @@ -97,8 +97,6 @@ } } } - - init_js_translations(); ?> </script> @@ -17,6 +17,15 @@ const App = { hotkey_actions: {}, is_prefs: false, LABEL_BASE_INDEX: -1024, + _translations: {}, + l10n: { + ngettext: function(msg1, msg2, n) { + return self.__((parseInt(n) > 1) ? msg2 : msg1); + }, + __: function(msg) { + return App._translations[msg] ? App._translations[msg] : msg; + } + }, FormFields: { attributes_to_string: function(attributes) { return Object.keys(attributes).map((k) => @@ -525,6 +534,13 @@ const App = { PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, this._initParams); } + const translations = reply['translations']; + + if (translations) { + console.log('reading translations...'); + App._translations = translations; + } + this.initSecondStage(); }, Error: { diff --git a/js/common.js b/js/common.js index 670ee1b30..1544e6d0b 100755 --- a/js/common.js +++ b/js/common.js @@ -1,8 +1,22 @@ 'use strict'; -/* global dijit, __, App, dojo, __csrf_token */ +/* global dijit, App, dojo, __csrf_token */ /* eslint-disable no-new */ +/* exported __ */ +function __(msg) { + if (typeof App != "undefined") { + return App.l10n.__(msg); + } else { + return msg; + } +} + +/* exported ngettext */ +function ngettext(msg1, msg2, n) { + return __((parseInt(n) > 1) ? msg2 : msg1); +} + /* exported $ */ function $(id) { console.warn("FIXME: please use App.byId() or document.getElementById() instead of $():", id); @@ -79,8 +79,6 @@ } } } - - init_js_translations(); ?> </script> |