Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/rare-fans-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes some locale loading issues for date-time formatting functionality.
20 changes: 14 additions & 6 deletions apps/meteor/server/lib/getMomentLocale.ts
Original file line number Diff line number Diff line change
@@ -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