Files

45 lines
1.5 KiB
TypeScript

import { getCrowdinLocale } from './shared';
let langNotSupportedMessageShown = false;
export const loadEmojiPanelI18n = async () => {
if (!window) {
return undefined;
}
const triedLocales: Array<string> = [];
const lang = getCrowdinLocale();
if (lang !== 'en') {
try {
triedLocales.push(lang);
// TODO we should replace this with a locale -> emojimart locale map. like with datefns
const langData = await import(`@emoji-mart/data/i18n/${lang}.json`);
return langData;
} catch (err) {
// this is just to make tsc happy when we are using the --en-only locale
const langCopy = lang as string;
const firstDashIndex = langCopy.indexOf('-');
if (firstDashIndex > 0) {
try {
const shortenLang = langCopy.slice(0, firstDashIndex);
triedLocales.push(shortenLang);
// TODO we should replace this with a locale -> emojimart locale map. like with datefns
const langData = await import(`@emoji-mart/data/i18n/${shortenLang}.json`);
return langData;
} catch (e) {
// don't rethrow, we want the log below to be shown
}
}
if (!langNotSupportedMessageShown) {
window?.log?.warn(
`Tried locales "${triedLocales}" is not supported by emoji-mart package. See https://github.com/missive/emoji-mart/tree/main/packages/emoji-mart-data/i18n`
);
langNotSupportedMessageShown = true;
}
}
}
return undefined;
};