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..53e550eb --- /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 "./fr-FR"; +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, +};