@forge/cli-shared
8.15.2-next.3-experimental-72ccdfa8.15.2-next.3-experimental-812ca41
out/service/i18n-resource-bundling-service.js~
out/service/i18n-resource-bundling-service.jsModified+28−1
Index: package/out/service/i18n-resource-bundling-service.js
===================================================================
--- package/out/service/i18n-resource-bundling-service.js
+++ package/out/service/i18n-resource-bundling-service.js
@@ -23,10 +23,14 @@
await fs_1.promises.copyFile(providedPath, dest);
}));
}
async createI18nInfoFile(bundleDirPath, i18nConfig, modules) {
- const i18nKeys = (0, i18n_1.extractI18nKeysFromModules)(modules);
+ const manifestKeys = (0, i18n_1.extractI18nKeysFromModules)(modules);
const translationLookup = await this.loadTranslationLookup(i18nConfig);
+ const DYNAMIC_MODULE_I18N_PREFIX = 'dynamic.';
+ const allLocaleKeys = this.extractAllKeysFromTranslationLookup(translationLookup);
+ const dynamicKeys = allLocaleKeys.filter((key) => key.startsWith(DYNAMIC_MODULE_I18N_PREFIX));
+ const i18nKeys = [...new Set([...manifestKeys, ...dynamicKeys])].sort();
const i18nInfo = this.createI18nInfo(i18nConfig, i18nKeys, translationLookup);
const i18nInfoFilePath = (0, path_1.join)(bundleDirPath, i18n_1.I18N_INFO_FILE_NAME);
await fs_1.promises.writeFile(i18nInfoFilePath, JSON.stringify(i18nInfo));
}
@@ -65,8 +69,31 @@
return [key, JSON.parse(file.toString())];
}));
return Object.fromEntries(results);
}
+ extractAllKeysFromTranslationLookup(translationLookup) {
+ const allKeys = new Set();
+ const extractKeys = (obj, prefix = '') => {
+ if (!obj || typeof obj !== 'object') {
+ return;
+ }
+ for (const [key, value] of Object.entries(obj)) {
+ const fullKey = prefix ? `${prefix}.${key}` : key;
+ if (typeof value === 'string') {
+ allKeys.add(fullKey);
+ }
+ else if (typeof value === 'object' && value !== null) {
+ extractKeys(value, fullKey);
+ }
+ }
+ };
+ for (const localeTranslations of Object.values(translationLookup)) {
+ if (localeTranslations && typeof localeTranslations === 'object') {
+ extractKeys(localeTranslations);
+ }
+ }
+ return Array.from(allKeys);
+ }
async bundle(modules, i18nConfig) {
if (!modules || !i18nConfig) {
return exports.EMPTY_I18N_RESOURCE_BUNDLE;
}