From d7c371f3330e7a2de81c76b394616defd710ce3b Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Mon, 4 Oct 2021 15:15:14 -0700 Subject: [PATCH 1/2] fix locale import for esm --- src/index.tsx | 17 ++++++++--------- src/locales/index.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/locales/index.js diff --git a/src/index.tsx b/src/index.tsx index 456b2708..aff1e874 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -17,6 +17,7 @@ import { BasicDatePicker, RangeDatePicker } from './pickers'; import { Locale, SemanticDatepickerProps } from './types'; import Calendar from './components/calendar'; import Input from './components/input'; +import localeOptions from "./locales"; const style: React.CSSProperties = { display: 'inline-block', @@ -166,17 +167,15 @@ class SemanticDatepicker extends React.Component< get locale() { const { locale } = this.props; - - let localeJson: Locale; - - try { - localeJson = require(`./locales/${locale}.json`); - } catch (e) { + + const localeKey = locale.replace("-", "_"); + + if (!localeOptions.hasOwnProperty(localeKey)) { console.warn(`"${locale}" is not a valid locale`); - localeJson = require('./locales/en-US.json'); + return localeOptions["en_US"]; } - - return localeJson; + + return localeOptions[localeKey]; } get weekdays() { diff --git a/src/locales/index.js b/src/locales/index.js new file mode 100644 index 00000000..fc710ce8 --- /dev/null +++ b/src/locales/index.js @@ -0,0 +1,45 @@ +import bg_BG from "./bg-BG"; +import ca_ES from "./ca-ES"; +import cs_CZ from "./cs-CZ"; +import de_DE from "./de-DE"; +import en_US from "./en-US"; +import es_ES from "./es-ES"; +import et_EE from "./et-EE"; +import fi_FI from "./fi-FI"; +import fr_FR from "./fi-FI"; +import he_IL from "./he-IL"; +import it_IT from './it-IT'; +import ja_JP from "./ja-JP"; +import ko_KR from "./ko-KR"; +import nb_NO from "./nb-NO"; +import nn_NO from "./nn-NO"; +import pl_PL from "./pl-PL"; +import pt_BR from "./pt-BR"; +import ru_RU from "./ru-RU"; +import sv_SE from "./sv-SE"; +import tr_TR from "./tr-TR"; +import zh_CN from "./zh-CN"; + +export default { + bg_BG, + ca_ES, + cs_CZ, + de_DE, + en_US, + es_ES, + et_EE, + fi_FI, + fr_FR, + he_IL, + it_IT, + ja_JP, + ko_KR, + nb_NO, + nn_NO, + pl_PL, + pt_BR, + ru_RU, + sv_SE, + tr_TR, + zh_CN, +}; \ No newline at end of file From 19a73eb605ce0fc3f5fbafa720b468a614cd4b6f Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Mon, 4 Oct 2021 23:26:29 -0700 Subject: [PATCH 2/2] fix a wrong locale import --- src/locales/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/locales/index.js b/src/locales/index.js index fc710ce8..53e550eb 100644 --- a/src/locales/index.js +++ b/src/locales/index.js @@ -6,7 +6,7 @@ import en_US from "./en-US"; import es_ES from "./es-ES"; import et_EE from "./et-EE"; import fi_FI from "./fi-FI"; -import fr_FR from "./fi-FI"; +import fr_FR from "./fr-FR"; import he_IL from "./he-IL"; import it_IT from './it-IT'; import ja_JP from "./ja-JP"; @@ -42,4 +42,4 @@ export default { sv_SE, tr_TR, zh_CN, -}; \ No newline at end of file +};