npm package diff
Package: @forge/bridge
Versions: 3.5.1-next.3-experimental-c7a7d36 - 4.0.0-next.6
File: package/out/i18n/index.js
Index: package/out/i18n/index.js
===================================================================
--- package/out/i18n/index.js
+++ package/out/i18n/index.js
@@ -0,0 +1,50 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.createTranslationFunction = exports.getTranslations = exports.resetTranslationsCache = void 0;
+const tslib_1 = require("tslib");
+const i18n_1 = require("@forge/i18n");
+const view_1 = require("../view");
+const frontendResourcesAccessor = {
+ getI18nInfoConfig: () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
+ const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${i18n_1.I18N_INFO_FILE_NAME}`);
+ if (!resp.ok) {
+ throw new Error('Failed to get i18n info config: ' + resp.statusText);
+ }
+ const info = (yield resp.json());
+ return info.config;
+ }),
+ getTranslationResource: (locale) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
+ const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${locale}.json`);
+ if (!resp.ok) {
+ throw new Error(`Failed to get translation resource for locale: ${locale}`);
+ }
+ return resp.json();
+ })
+};
+const translationsGetter = new i18n_1.TranslationsGetter(frontendResourcesAccessor);
+const resetTranslationsCache = () => {
+ translationsGetter.reset();
+};
+exports.resetTranslationsCache = resetTranslationsCache;
+const getTranslations = (locale = null, options = {
+ fallback: true
+}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
+ let targetLocale = locale;
+ if (!targetLocale) {
+ const context = yield view_1.view.getContext();
+ targetLocale = context.locale;
+ }
+ return yield translationsGetter.getTranslations(targetLocale, options);
+});
+exports.getTranslations = getTranslations;
+const createTranslationFunction = (locale = null) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
+ let targetLocale = locale;
+ if (!targetLocale) {
+ const context = yield view_1.view.getContext();
+ targetLocale = context.locale;
+ }
+ const translator = new i18n_1.Translator(targetLocale, translationsGetter);
+ yield translator.init();
+ return (i18nKey, defaultValue) => { var _a, _b; return (_b = (_a = translator.translate(i18nKey)) !== null && _a !== void 0 ? _a : defaultValue) !== null && _b !== void 0 ? _b : i18nKey; };
+});
+exports.createTranslationFunction = createTranslationFunction;