diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-11-05 18:00:41 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-11-05 18:00:41 +0900 |
| commit | 2c836ba71fbc3e5cb4120439d74e31258b85ac23 (patch) | |
| tree | bf179fd84b35ed21caa5971896ca27e863ae0327 | |
| parent | New Crowdin updates (#12244) (diff) | |
| download | sharkey-2c836ba71fbc3e5cb4120439d74e31258b85ac23.tar.gz sharkey-2c836ba71fbc3e5cb4120439d74e31258b85ac23.tar.bz2 sharkey-2c836ba71fbc3e5cb4120439d74e31258b85ac23.zip | |
enhance(build): フォールバック効かすためにlocaleの空文字は項目ごと消す
| -rw-r--r-- | locales/index.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/locales/index.js b/locales/index.js index 7801f1275b..67a406d98d 100644 --- a/locales/index.js +++ b/locales/index.js @@ -53,6 +53,19 @@ const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g') const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, import.meta.url), 'utf-8'))) || {}, a), {}); +// 空文字列が入ることがあり、フォールバックが動作しなくなるのでプロパティごと消す +const removeEmpty = (obj) => { + for (const [k, v] of Object.entries(obj)) { + if (v === '') { + delete obj[k]; + } else if (typeof v === 'object') { + removeEmpty(v); + } + } + return obj; +}; +removeEmpty(locales); + export default Object.entries(locales) .reduce((a, [k ,v]) => (a[k] = (() => { const [lang] = k.split('-'); @@ -63,7 +76,7 @@ export default Object.entries(locales) default: return merge( locales['ja-JP'], locales['en-US'], - locales[`${lang}-${primaries[lang]}`] || {}, + locales[`${lang}-${primaries[lang]}`] ?? {}, v ); } |