fix: moment js not loading some locales (#36651)
parent
cf165c5f73
commit
a94d5eb6ae
@ -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