Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DTRA] Maryia/DTRA-1219/fix: month not translated in duration #15043

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not ignore this languages, so that dates get updated when the language is switched and initMoment() is called.

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';
Copy link
Contributor Author

@maryia-deriv maryia-deriv May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'en-gb' is one of the available English locales in moment library. there is no 'en' locale.
import('moment/locale/en') was throwing: Cannot find module './en' - because there is no moment/locale/en directory in moment library in node_modules

return import(`moment/locale/${locale}`).then(() => moment.locale(locale)).catch(() => moment);
};

/**
Expand Down
Loading