mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
fix: moment js not loading some locales (#36651)
This commit is contained in:
parent
cf165c5f73
commit
a94d5eb6ae
5
.changeset/rare-fans-shake.md
Normal file
5
.changeset/rare-fans-shake.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@rocket.chat/meteor': patch
|
||||
---
|
||||
|
||||
Fixes some locale loading issues for date-time formatting functionality.
|
||||
@ -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}`);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user