fix: moment js not loading some locales (#36651)

This commit is contained in:
Yash Rajpal 2025-08-20 03:17:57 +05:30 committed by GitHub
parent cf165c5f73
commit a94d5eb6ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---
Fixes some locale loading issues for date-time formatting functionality.

View File

@ -1,15 +1,23 @@
import { Meteor } from 'meteor/meteor';
const mapLocaleToMomentLocale: Record<string, string> = {
ug: 'ug-cn',
zh: 'zh-cn',
};
export async function getMomentLocale(locale: string): Promise<string | undefined> {
const localeLower = locale.toLowerCase();
try {
return Assets.getTextAsync(`moment-locales/${localeLower}.js`);
} catch (error) {
const localesPaths = [
`moment-locales/${localeLower}.js`,
`moment-locales/${String(localeLower.split('-').shift())}.js`,
`moment-locales/${mapLocaleToMomentLocale[localeLower]}.js`,
];
for await (const localePath of localesPaths) {
try {
return Assets.getTextAsync(`moment-locales/${String(localeLower.split('-').shift())}.js`);
return await Assets.getTextAsync(localePath);
} catch (error) {
throw new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${locale}`);
continue;
}
}
throw new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${locale}`);
}