Skip to content

Commit 4b10f4f

Browse files
authored
fix(framework): Allow users to override default language translations (#1716)
1 parent f8b1b39 commit 4b10f4f

File tree

2 files changed

+8
-4
lines changed
  • packages
    • base/src/asset-registries
    • tools/lib/generate-json-imports

2 files changed

+8
-4
lines changed

packages/base/src/asset-registries/i18n.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const getI18nBundleData = packageName => {
2828
* @public
2929
*/
3030
const registerI18nBundle = (packageName, bundle) => {
31-
bundleURLs.set(packageName, bundle);
31+
const oldBundle = bundleURLs.get(packageName) || {};
32+
bundleURLs.set(packageName, Object.assign({}, oldBundle, bundle));
3233
};
3334

3435
/**
@@ -52,11 +53,11 @@ const fetchI18nBundle = async packageName => {
5253
const language = getLocale().getLanguage();
5354

5455
let localeId = normalizeLocale(language);
55-
while (!bundlesForPackage[localeId]) {
56+
while (localeId !== DEFAULT_LANGUAGE && !bundlesForPackage[localeId]) {
5657
localeId = nextFallbackLocale(localeId);
5758
}
5859

59-
if (localeId === DEFAULT_LANGUAGE) {
60+
if (!bundlesForPackage[localeId]) {
6061
return;
6162
}
6263

packages/tools/lib/generate-json-imports/i18n.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
const fs = require("fs");
22
const path = require('path');
33
const mkdirp = require("mkdirp");
4+
const assets = require("../../assets-meta.js");
45

56
const packageName = JSON.parse(fs.readFileSync("package.json")).name;
67

78
const inputFolder = path.normalize(process.argv[2]);
89
const outputFile = path.normalize(`${process.argv[3]}/i18n.js`);
910

11+
const defaultLanguage = assets.languages.default;
12+
1013
// All languages present in the file system
1114
const files = fs.readdirSync(inputFolder);
1215
const languages = files.map(file => {
1316
const matches = file.match(/messagebundle_(.+?).json$/);
1417
return matches ? matches[1] : undefined;
15-
}).filter(key => !!key);
18+
}).filter(key => !!key && key !== defaultLanguage);
1619

1720
let content;
1821

0 commit comments

Comments
 (0)