RocketChat/Rocket.Chat

View on GitHub
apps/meteor/server/lib/getMomentLocale.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Meteor } from 'meteor/meteor';

export async function getMomentLocale(locale: string): Promise<string | undefined> {
    const localeLower = locale.toLowerCase();

    try {
        return Assets.getTextAsync(`moment-locales/${localeLower}.js`);
    } catch (error) {
        try {
            return Assets.getTextAsync(`moment-locales/${String(localeLower.split('-').shift())}.js`);
        } catch (error) {
            throw new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${locale}`);
        }
    }
}