diff --git a/.changeset/rare-fans-shake.md b/.changeset/rare-fans-shake.md new file mode 100644 index 00000000000..c6ef66f265e --- /dev/null +++ b/.changeset/rare-fans-shake.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes some locale loading issues for date-time formatting functionality. diff --git a/apps/meteor/server/lib/getMomentLocale.ts b/apps/meteor/server/lib/getMomentLocale.ts index a55f2d601f5..2f1a8168dd5 100644 --- a/apps/meteor/server/lib/getMomentLocale.ts +++ b/apps/meteor/server/lib/getMomentLocale.ts @@ -1,15 +1,23 @@ import { Meteor } from 'meteor/meteor'; +const mapLocaleToMomentLocale: Record = { + ug: 'ug-cn', + zh: 'zh-cn', +}; + export async function getMomentLocale(locale: string): Promise { 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}`); }