Skip to content

Commit

Permalink
fix: do not ignore locales when switching between languages
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-deriv committed May 8, 2024
1 parent 6ca260c commit 041d3ea
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/shared/src/utils/date/date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type TExtendedMoment = typeof moment & {

// Localize moment instance with specific object
export const initMoment = (lang: string) => {
const ignored_language = ['EN', 'AR', 'BN', 'SI'];
if (!lang || ignored_language.includes(lang)) return moment;
return import(`moment/locale/${lang.toLowerCase().replace('_', '-')}`)
.then(() => moment.locale(lang.toLocaleLowerCase().replace('_', '-')))
.catch(() => moment);
const hasEnMomentLocale = ['EN', 'AR', 'BN', 'SI']; // 'AR', 'BN' & 'SI' langs have non-numeric dates ('২০২৪-০৫-০৭'), our current usage of moment requires us to make all dates numeric
if (!lang) return moment;
let locale = lang.toLowerCase().replace('_', '-');
if (hasEnMomentLocale.includes(lang)) locale = 'en-gb';
return import(`moment/locale/${locale}`).then(() => moment.locale(locale)).catch(() => moment);
};

/**
Expand Down

0 comments on commit 041d3ea

Please sign in to comment.