Let's say I want to display, on the same view, the calendar in english and in french (or at least be able to toggle the language in app state).
Currently it seems the only way is to use a singleton like `LocaleConfig.defaultLocale = 'fr' but that does not seem appropriate to me. Couldn't we pass the locale as props in any component that need localization?
Agree this should be improved. Problem is that XDate locale setup is implemented as singleton. We should check if this can be improved somehow
Actually it's possible to change the singleton of xdate before re rendering and solved my usecase for translated app but it's not ideal. I'll try to add some doc about that soon it should be enough for most usecases
I remembered that locales in moment are well supported, so it should be possible to fill the arrays of LocaleConfig.locales[] by just giving the locales and some options to a 'useMomentLocales(options)' function?
I'm willing to code the changes if it will be added to the repo...
Also, why are the translations and locale not passed into the Calendar component as properties?
I think we should rather migrate away from XDate and use another date lib which does not need singleton.
+1
Is there any way to make LocaleConfig work? In the example app this part is commented on app.js file
Thanks! 馃檹
I've successfully switched from english to french with the following:
LocaleConfig.locales.en = LocaleConfig.locales[''];
LocaleConfig.locales.fr = {
monthNames: [
'Janvier',
'F茅vrier',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Ao没t',
'Septembre',
'Octobre',
'Novembre',
'D茅cembre',
],
monthNamesShort: [
'Janv.',
'F茅vr.',
'Mars',
'Avril',
'Mai',
'Juin',
'Juil.',
'Ao没t',
'Sept.',
'Oct.',
'Nov.',
'D茅c.',
],
dayNames: [
'Dimanche',
'Lundi',
'Mardi',
'Mercredi',
'Jeudi',
'Vendredi',
'Samedi',
],
dayNamesShort: ['Dim.', 'Lun.', 'Mar.', 'Mer.', 'Jeu.', 'Ven.', 'Sam.'],
};
LocaleConfig.defaultLocale = 'fr';
Then you just have to run LocaleConfig.defaultLocale = 'fr' or LocaleConfig.defaultLocale = 'en' before triggering a re-render and you'll have the calendar localized.
Thanks @slorber it works! 馃憣
This module should support i18n like moment
Thanks :) save the hour 馃憤 @slorber
It doesn't work for me. After I change the language, I also need to change its local setting by manual click the calendar one time to trigger it.
It doesn't work for me. After I change the language, I also need to change its local setting by manual click the calendar one time to trigger it.
I had the same issue if I set the LocaleConfig.defaultLocale in componentDidMount. If I place it in render instead it seems to work.
It doesn't work for me. After I change the language, I also need to change its local setting by manual click the calendar one time to trigger it.
I had the same issue if I set the
LocaleConfig.defaultLocaleincomponentDidMount. If I place it inrenderinstead it seems to work.
Hey, I add "key={locale}" to Calendars component, it works.
Most helpful comment
I've successfully switched from english to french with the following:
Then you just have to run
LocaleConfig.defaultLocale = 'fr'orLocaleConfig.defaultLocale = 'en'before triggering a re-render and you'll have the calendar localized.