mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-21 13:24:16 +00:00
i18n(refactor): load all files in a locale, not the ones defined in app.json, move env.t client code to own file, add env.isStaticPage (from isFrontPage)
This commit is contained in:
parent
01c4c4498a
commit
90e9a1aeaa
7 changed files with 35 additions and 27 deletions
|
|
@ -1,23 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
window.env = window.env || {}; //FIX tests
|
||||
|
||||
if(window.env.language && window.env.language.momentLang && window.env.language.momentLangCode){
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.text = window.env.language.momentLang;
|
||||
head.appendChild(script);
|
||||
moment.lang(window.env.language.momentLangCode);
|
||||
}
|
||||
|
||||
window.env.t = function(stringName, vars){
|
||||
var string = window.env.translations[stringName];
|
||||
if(!string) return window._.template(window.env.translations.stringNotFound, {string: stringName});
|
||||
|
||||
return vars === undefined ? string : window._.template(string, vars);
|
||||
}
|
||||
|
||||
window.habitrpg = angular.module('habitrpg',
|
||||
['ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'challengeServices',
|
||||
'authServices', 'notificationServices', 'guideServices', 'authCtrl',
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ habitrpg.directive('taskFocus',
|
|||
return function(scope, elem, attrs) {
|
||||
scope.$watch(attrs.taskFocus, function(newval) {
|
||||
if ( newval ) {
|
||||
$timeounvt(function() {
|
||||
$timeout(function() {
|
||||
elem[0].focus();
|
||||
}, 0, false);
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ habitrpg.directive('habitrpgAdsense', function() {
|
|||
template: '<div ng-transclude></div>',
|
||||
link: function ($scope, element, attrs) {}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
habitrpg.directive('whenScrolled', function() {
|
||||
return function(scope, elm, attr) {
|
||||
|
|
|
|||
20
public/js/env.js
Normal file
20
public/js/env.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"use strict";
|
||||
|
||||
window.env = window.env || {}; //FIX tests
|
||||
|
||||
// If Moment.js is loaded,
|
||||
if(window.moment && window.env.language && window.env.language.momentLang && window.env.language.momentLangCode){
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.text = window.env.language.momentLang;
|
||||
head.appendChild(script);
|
||||
window.moment.lang(window.env.language.momentLangCode);
|
||||
}
|
||||
|
||||
window.env.t = function(stringName, vars){
|
||||
var string = window.env.translations[stringName];
|
||||
if(!string) return window._.template(window.env.translations.stringNotFound, {string: stringName});
|
||||
|
||||
return vars === undefined ? string : window._.template(string, vars);
|
||||
}
|
||||
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
"bower_components/habitrpg-shared/dist/habitrpg-shared.js",
|
||||
|
||||
"js/env.js",
|
||||
|
||||
"js/app.js",
|
||||
"js/services/sharedServices.js",
|
||||
"js/services/authServices.js",
|
||||
|
|
@ -81,6 +83,7 @@
|
|||
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
|
||||
|
||||
"bower_components/angular-loading-bar/build/loading-bar.js",
|
||||
"js/env.js",
|
||||
"js/static.js",
|
||||
"js/services/notificationServices.js",
|
||||
"bower_components/habitrpg-shared/script/userServices.js",
|
||||
|
|
|
|||
|
|
@ -113,12 +113,12 @@ var getManifestFiles = function(page){
|
|||
var translations = {};
|
||||
|
||||
var loadTranslations = function(locale){
|
||||
var files = require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, 'app.json')).files;
|
||||
var files = fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale));
|
||||
translations[locale] = {};
|
||||
_.each(files, function(file){
|
||||
_.merge(translations[locale], require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, file)));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// First fetch english so we can merge with missing strings in other languages
|
||||
loadTranslations('en');
|
||||
|
|
@ -193,7 +193,11 @@ module.exports.locals = function(req, res, next) {
|
|||
getUserLanguage(req, function(err, language){
|
||||
if(err) return res.json(500, {err: err});
|
||||
|
||||
language.momentLang = (momentLangs[language.code] || undefined);
|
||||
var isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
|
||||
console.log(isStaticPage)
|
||||
|
||||
// Load moment.js language file only when not on static pages
|
||||
language.momentLang = ((!isStaticPage && momentLangs[language.code])|| undefined);
|
||||
|
||||
res.locals.habitrpg = {
|
||||
NODE_ENV: nconf.get('NODE_ENV'),
|
||||
|
|
@ -205,6 +209,7 @@ module.exports.locals = function(req, res, next) {
|
|||
getBuildUrl: getBuildUrl,
|
||||
avalaibleLanguages: avalaibleLanguages,
|
||||
language: language,
|
||||
isStaticPage: isStaticPage,
|
||||
translations: translations[language.code],
|
||||
t: function(stringName, vars){
|
||||
var string = translations[language.code][stringName];
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ router.get('/', middleware.locals, function(req, res) {
|
|||
// -------- Marketing --------
|
||||
|
||||
router.get('/static/front', middleware.locals, function(req, res) {
|
||||
var env = res.locals.habitrpg;
|
||||
env.isFrontPage = true;
|
||||
res.render('static/front', {env: env});
|
||||
res.render('static/front', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/privacy', middleware.locals, function(req, res) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ footer.footer(ng-controller='FooterCtrl')
|
|||
.span3
|
||||
h4=env.t('footerCompany')
|
||||
ul.unstyled
|
||||
if (!env.isFrontPage)
|
||||
if (!env.isStaticPage)
|
||||
li
|
||||
.btn.btn-small.btn-success(ng-click='modals.buyGems = true')
|
||||
i.icon-heart.icon-white
|
||||
|
|
|
|||
Loading…
Reference in a new issue