Skip to content

Commit

Permalink
fix: timeago locale switch
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 11, 2020
1 parent 300a875 commit 8c019a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 1 addition & 4 deletions public/src/client/account/settings.js
Expand Up @@ -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();
});
Expand Down
12 changes: 8 additions & 4 deletions public/src/modules/translator.js
Expand Up @@ -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();
Expand All @@ -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() {
Expand Down

0 comments on commit 8c019a6

Please sign in to comment.