Skip to content

Node.js based forum software built for the modern web

fix: timeago locale switch

Barış Soner Uşaklı8c019a6a3b45
diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js
index 06449f107e..39a2bfce18 100644
--- a/public/src/client/account/settings.js
+++ b/public/src/client/account/settings.js
@@ -92,10 +92,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'transla
htmlEl.css('direction', translated);
});
- var stringsModule = 'timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(config.userLang);
- // without undef, requirejs won't load the strings a second time
- require.undef(stringsModule);
- require([stringsModule], function () {
+ translator.switchTimeagoLanguage(utils.userLangToTimeagoCode(config.userLang), function () {
overrides.overrideTimeago();
ajaxify.refresh();
});
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js
index 3e6981dba8..279e744648 100644
--- a/public/src/modules/translator.js
+++ b/public/src/modules/translator.js
@@ -605,7 +605,7 @@
}
var originalSettings = assign({}, jQuery.timeago.settings.strings);
- jQuery.getScript(config.assetBaseUrl + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () {
+ adaptor.switchTimeagoLanguage(languageCode + '-short', function () {
adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings);
jQuery.timeago.settings.strings = assign({}, originalSettings);
toggle();
@@ -615,12 +615,16 @@
}
},
- switchTimeagoLanguage: function switchTimeagoLanguage(callback) {
+ switchTimeagoLanguage: function switchTimeagoLanguage(langCode, callback) {
// Delete the cached shorthand strings if present
delete adaptor.timeagoShort;
- var languageCode = utils.userLangToTimeagoCode(config.userLang);
- jQuery.getScript(config.assetBaseUrl + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(callback);
+ var stringsModule = 'timeago/locales/jquery.timeago.' + langCode;
+ // without undef, requirejs won't load the strings a second time
+ require.undef(stringsModule);
+ require([stringsModule], function () {
+ callback();
+ });
},
prepareDOM: function prepareDOM() {