Skip to content

Commit

Permalink
Fix moment.js usage of language and locale
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 28, 2019
1 parent 75f38b6 commit aef375c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,33 @@ function initCore() {
jQuery.globalEval = function(){};

/**
* Set users locale to moment.js as soon as possible
* Set users language and locale to moment.js as soon as possible
*/
moment.locale(OC.getLocale());
moment.locale(OC.getLanguage());
var localeData = {
months: moment.localeData().months(),
monthsShort: moment.localeData().monthsShort(),
weekdays: moment.localeData().weekdays(),
weekdaysShort: moment.localeData().weekdaysShort(),
weekdaysMin: moment.localeData().weekdaysMin(),
calendar: moment.localeData().calendar,
relativeTime: moment.localeData()._relativeTime,
};

function getBestParentLocale() {
moment.locale([
OC.getLocale(),
OC.getLocale().split('_')[0],
OC.getLanguage(),
OC.getLanguage().split('_')[0],
'en',
]);
return moment.localeData()._abbr;
}
localeData.parentLocale = getBestParentLocale();

moment.defineLocale('locale-and-language', localeData);
moment.locale('locale-and-language');

var userAgent = window.navigator.userAgent;
var msie = userAgent.indexOf('MSIE ');
Expand Down

0 comments on commit aef375c

Please sign in to comment.