Skip to content

Commit

Permalink
Add support to 3-digit locale
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Aug 6, 2019
1 parent 7b7fa40 commit 5d87098
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client/startup/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }`;
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion server/methods/loadLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`);
}
}
},
Expand Down

0 comments on commit 5d87098

Please sign in to comment.