From 24f06f275b94b75187a4530691412394711dd577 Mon Sep 17 00:00:00 2001 From: Chris Garrity Date: Thu, 8 Aug 2019 16:32:40 +0100 Subject: [PATCH] Use localeData from l10n Remove old tech debt. www had always imported every react-intl defined locale, and then added our custom locales. scratch-l10n defines localeData based on the currently supported languages, and it includes any necessary custom-locales, so we should use that instead of maintaining two custom locale lists. --- custom-locales.json | 46 ------------------------------------------ src/lib/intl.jsx | 20 +++--------------- src/lib/require-all.js | 5 ----- 3 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 custom-locales.json delete mode 100644 src/lib/require-all.js diff --git a/custom-locales.json b/custom-locales.json deleted file mode 100644 index c7281d3db..000000000 --- a/custom-locales.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "ab": { - "locale": "ab", - "parentLocale": "az" - }, - "an": { - "locale": "an", - "parentLocale": "ca" - }, - "cat": { - "locale": "cat", - "parentLocale": "en" - }, - "ht": { - "locale": "ht", - "parentLocale": "fr" - }, - "ja-hr": { - "locale": "ja-hr", - "parentLocale": "ja" - }, - "rap": { - "locale": "rap", - "parentLocale": "es" - }, - "la": { - "locale": "la", - "parentLocale": "it" - }, - "sc": { - "locale": "sc", - "parentLocale": "it" - }, - "yum": { - "locale": "yum", - "parentLocale": "en" - }, - "zh-cn": { - "locale": "zh-cn", - "parentLocale": "zh" - }, - "zh-tw": { - "locale": "zh-tw", - "parentLocale": "zh" - } -} diff --git a/src/lib/intl.jsx b/src/lib/intl.jsx index c29c53fab..93f61a717 100644 --- a/src/lib/intl.jsx +++ b/src/lib/intl.jsx @@ -1,21 +1,7 @@ -const requireAll = require('./require-all'); const ReactIntl = require('react-intl'); -const allLocaleData = requireAll(require.context('react-intl/locale-data', true, /^\.\/.*\.js$/)); -const customLocaleData = require('../../custom-locales.json'); - -/** - * Add all locales - */ -for (const locale in allLocaleData) { - ReactIntl.addLocaleData(allLocaleData[locale]); -} - -/** - * Add custom locales to react-intl if it doesn't have them. - */ -for (const customLocale in customLocaleData) { - ReactIntl.addLocaleData(customLocaleData[customLocale]); -} +// Add locale data to react intl for all supported languages +const localeData = require('scratch-l10n').localeData; +ReactIntl.addLocaleData(localeData); module.exports = ReactIntl; diff --git a/src/lib/require-all.js b/src/lib/require-all.js deleted file mode 100644 index 415eeecb9..000000000 --- a/src/lib/require-all.js +++ /dev/null @@ -1,5 +0,0 @@ -const requireAll = requireContext => ( - requireContext.keys().map(requireContext) -); - -module.exports = requireAll;