From 6279ce8f227e6338e3d6485c6511d81a4feb2fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Tue, 19 Feb 2019 04:04:05 +0900 Subject: [PATCH] Add fallback for locales (#4109) * Update index.js * Update index.js --- locales/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/locales/index.js b/locales/index.js index 96a1af38b..9642b400a 100644 --- a/locales/index.js +++ b/locales/index.js @@ -8,6 +8,19 @@ const yaml = require('js-yaml'); const langs = ['de-DE', 'en-US', 'fr-FR', 'ja-JP', 'ja-KS', 'pl-PL', 'es-ES', 'nl-NL', 'zh-CN', 'ko-KR']; const loadLocale = lang => yaml.safeLoad(fs.readFileSync(`${__dirname}/${lang}.yml`, 'utf-8')); -const locales = langs.map(lang => ({ [lang]: loadLocale(lang) })); +const locales = langs + .map(lang => [lang, loadLocale(lang)]) + .map(([lang, locale], _, locales) => { + switch (lang) { + case 'ja-JP': return [lang, locale]; + case 'en-US': return [lang, { ...locales['ja-JP'], ...locale }]; + default: return [lang, { + (lang.startsWith('ja-') ? {} : ...locales['en-US']), + ...locales['ja-JP'], + ...locale + }]; + } + }) + .map(([lang, locale]) => ({ [lang]: loadLocale(lang) })); module.exports = locales.reduce((a, b) => ({ ...a, ...b }));