question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i18n: how to use calendar in multiple locales?

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

29reactions
slorbercommented, May 11, 2018

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.

19reactions
mayconmesquitacommented, Apr 13, 2021

If anyone need this in PT-BR:

import { LocaleConfig } from 'react-native-calendars';

// pt-br localization for react-native-calendars
LocaleConfig.locales['pt-br'] = {
  monthNames: [
    'Janeiro',
    'Fevereiro',
    'Março',
    'Abril',
    'Maio',
    'Junho',
    'Julho',
    'Agosto',
    'Setembro',
    'Outubro',
    'Novembro',
    'Dezembro',
  ],
  monthNamesShort: [
    'Jan',
    'Fev',
    'Mar',
    'Abr',
    'Mai',
    'Jun',
    'Jul.',
    'Ago',
    'Set',
    'Out',
    'Nov',
    'Dec',
  ],
  dayNames: [
    'Domingo',
    'Segunda-feira',
    'Terça-feira',
    'Quarta-feira',
    'Quinta-feira',
    'Sexta-feira',
    'Sábado',
  ],
  dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
  today: 'Hoje',
};
LocaleConfig.defaultLocale = 'pt-br';

export { LocaleConfig };
Read more comments on GitHub >

github_iconTop Results From Across the Web

i18n - V-Calendar
There are multiple ways which you can configure the locale for a specific calendar. Locales may be configured globally via the defaults object...
Read more >
java - I18n and calendars - Can the calendar system remain ...
I guess that the answer could depend on the data which is only supported in one locale (chosen at time of setup), despite...
Read more >
Docs Locale - FullCalendar
You can tailor the calendar for certain languages (aka “locales”). The locale setting it the most important, as it sets the defaults of...
Read more >
Localization in Flutter Event Calendar (SfCalendar) - Syncfusion
By default, the calendar widget supports US English localizations. You can change the other languages by specifying the MaterialApp properties and adding the ......
Read more >
Internationalization (i18n) and Localization (L10n)
Internationalization (i18n) and Localization (L10n) are two important features ... Components such as calendar and schedule use a shared PrimeFaces.locales ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found