Cache translations.

Fixes: #1158
This commit is contained in:
Umair Khan 2016-07-05 16:05:51 +05:00 committed by Tim Abbott
parent 30dd8cfd4a
commit dce48d58b6
4 changed files with 14 additions and 2 deletions

View File

@ -19,7 +19,8 @@
"i18next": "3.0.0",
"i18next-parser": "0.7.0",
"i18next-xhr-backend": "0.5.4",
"i18next-browser-languagedetector": "0.3.0"
"i18next-browser-languagedetector": "0.3.0",
"i18next-localstorage-cache": "0.3.0"
},
"scripts": {},
"repository": {

View File

@ -4,6 +4,8 @@
var i18n = window.i18n = require('i18next');
var XHR = require('i18next-xhr-backend');
var lngDetector = require('i18next-browser-languagedetector');
var Cache = require('i18next-localstorage-cache');
var backendOptions = {
loadPath: '/static/locale/__lng__/translations.json'
};
@ -15,8 +17,14 @@
htmlTag: document.documentElement
};
var cacheOptions = {
enabled: true,
prefix: page_params.server_generation + ':'
};
i18n.use(XHR)
.use(lngDetector)
.use(Cache)
.init({
nsSeparator: false,
keySeparator: false,
@ -25,7 +33,8 @@
suffix: "__"
},
backend: backendOptions,
detection: detectionOptions
detection: detectionOptions,
cache: cacheOptions
}, function () {
var i;
initialized = true;

View File

@ -1799,6 +1799,7 @@ class HomeTest(AuthedTestCase):
"realm_restricted_to_domain",
"referrals",
"save_stacktraces",
"server_generation",
"share_the_love",
"show_digest_email",
"sounds_enabled",

View File

@ -931,6 +931,7 @@ def home(request):
poll_timeout = settings.POLL_TIMEOUT,
login_page = settings.HOME_NOT_LOGGED_IN,
maxfilesize = settings.MAX_FILE_UPLOAD_SIZE,
server_generation = settings.SERVER_GENERATION,
password_auth_enabled = password_auth_enabled(user_profile.realm),
have_initial_messages = user_has_messages,
subbed_info = register_ret['subscriptions'],