@forge/api

6.4.1-next.0-experimental-90651456.4.1
out/api/i18n.js
out/api/i18n.js
+12−2
Index: package/out/api/i18n.js
===================================================================
--- package/out/api/i18n.js
+++ package/out/api/i18n.js
@@ -45,23 +45,33 @@
     translationsGetter.reset();
     translationsFunctionCache.clear();
 };
 exports.resetTranslationsCache = resetTranslationsCache;
-const getTranslations = async (locale, options = {
+const getTranslations = async (rawLocale, options = {
     fallback: true
 }) => {
+    const locale = doEnsureLocale(rawLocale);
     return await translationsGetter.getTranslations(locale, options);
 };
 exports.getTranslations = getTranslations;
-const createTranslationFunction = async (locale) => {
+const createTranslationFunction = async (rawLocale) => {
+    const locale = doEnsureLocale(rawLocale);
     let translator = translationsFunctionCache.get(locale);
     if (!translator) {
         translator = await createTranslationFunctionImpl(locale);
         translationsFunctionCache.set(locale, translator);
     }
     return translator;
 };
 exports.createTranslationFunction = createTranslationFunction;
+const doEnsureLocale = (rawLocale) => {
+    const ensuredLocale = (0, i18n_1.ensureLocale)(rawLocale);
+    if (!ensuredLocale) {
+        console.warn(`The locale "${rawLocale}" is not supported, defaulting to the default locale.`);
+        return rawLocale;
+    }
+    return ensuredLocale;
+};
 const createTranslationFunctionImpl = async (locale) => {
     const translator = new i18n_1.Translator(locale, translationsGetter);
     await translator.init();
     return (i18nKey, defaultValue) => translator.translate(i18nKey) ?? defaultValue ?? i18nKey;