From 5d870988990ed6dfeb7e238dd3244fd9c6f2e7cf Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 5 Aug 2019 23:29:08 -0300 Subject: [PATCH] Add support to 3-digit locale --- client/startup/i18n.js | 9 +++++++-- server/methods/loadLocale.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/startup/i18n.js b/client/startup/i18n.js index 50d4264ac135..9352a62f718b 100644 --- a/client/startup/i18n.js +++ b/client/startup/i18n.js @@ -18,7 +18,7 @@ Meteor.startup(() => { const filterLanguage = (language) => { // Fix browsers having all-lowercase language settings eg. pt-br, en-us - const regex = /([a-z]{2})-([a-z]{2})/; + const regex = /([a-z]{2,3})-([a-z]{2,4})/; const matches = regex.exec(language); if (matches) { return `${ matches[1] }-${ matches[2].toUpperCase() }`; @@ -59,7 +59,12 @@ Meteor.startup(() => { document.documentElement.classList[isRtl(language) ? 'add' : 'remove']('rtl'); TAPi18n.setLanguage(language); - loadMomentLocale(language).then((locale) => moment.locale(locale), (error) => console.error(error)); + loadMomentLocale(language) + .then((locale) => moment.locale(locale)) + .catch((error) => { + moment.locale('en'); + console.error('Error loading moment locale:', error); + }); }; const setLanguage = (language) => { diff --git a/server/methods/loadLocale.js b/server/methods/loadLocale.js index aa3d0302a4f2..c54d046fc9dc 100644 --- a/server/methods/loadLocale.js +++ b/server/methods/loadLocale.js @@ -11,7 +11,7 @@ Meteor.methods({ try { return Assets.getText(`moment-locales/${ locale.split('-').shift().toLowerCase() }.js`); } catch (error) { - return console.log(error); + throw new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${ locale }`); } } },