diff options
author | Andrew Dolgov <[email protected]> | 2021-02-26 09:21:17 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-26 09:21:17 +0300 |
commit | 56b10fea1805b4ff0e7129adb8216d4d89b74147 (patch) | |
tree | e3693dddd57299cf64bed71872de63ec0d011a4d /js | |
parent | fd9cd5292979045581630d36b1f35333c60f420e (diff) |
pass translations to frontend as a json object
Diffstat (limited to 'js')
-rw-r--r-- | js/App.js | 16 | ||||
-rwxr-xr-x | js/common.js | 16 |
2 files changed, 31 insertions, 1 deletions
@@ -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); |