From 2c836ba71fbc3e5cb4120439d74e31258b85ac23 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Nov 2023 18:00:41 +0900 Subject: [PATCH] =?UTF-8?q?enhance(build):=20=E3=83=95=E3=82=A9=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF=E5=8A=B9=E3=81=8B=E3=81=99?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=ABlocale=E3=81=AE=E7=A9=BA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E3=81=AF=E9=A0=85=E7=9B=AE=E3=81=94=E3=81=A8=E6=B6=88?= =?UTF-8?q?=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/locales/index.js b/locales/index.js index 7801f1275..67a406d98 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 ); }