luxon
luxon copied to clipboard
Locale not changing the language
Describe the bug
Hello, I'm using Luxon in React-Native project on IOS simulator. I've set Settings.defaultLocale = 'fr'
to have my date to french translations. But seems to not working, I always got english translations. I've also tried to directly modify the local in the parameters, same result.

To Reproduce
import { Settings, DateTime, Info } from "luxon";
Settings.defaultLocale = "fr";
console.log(
"DateTime.now().locale =",
DateTime.now().locale,
"Info.months =",
Info.months("long", { locale: "fr" })
);
Actual vs Expected behavior Have dates in french language
Desktop (please complete the following information):
- OS: IOS 14.5
- Browser [e.g. Chrome 84, safari 14.0]
- Luxon version : 1.27.0
Thank's for any help.
You'll need to make sure that ICU is getting loaded into your environment, because Luxon uses internationalization capabilities built into the environment, using the Intl API. For example, they come built into the browser and newer versions of Node. I'm not sure how to do that in the iOS simulator, though.
Also looking for a solution for this one – @alimtunc did you have any luck with this yet?
You'll need to make sure that ICU is getting loaded into your environment, because Luxon uses internationalization capabilities built into the environment, using the Intl API. For example, they come built into the browser and newer versions of Node. I'm not sure how to do that in the iOS simulator, though.
Ok, thank you for your reply. Do you have any link to advice ? I don't know either how to do it, maybe for android you have one ?
Also looking for a solution for this one – @alimtunc did you have any luck with this yet?
Not yet.. I did not look further because I don't know what to look, couldn't find anything on the net.. :/
I can confirm that this also happen on my end
Describe the bug
React-Native project on IOS simulator. I've set Settings.defaultLocale = 'id'
to have my date to Bahasa(Indonesia) translations. But seems to not working, I always get list of null.
However running unit test (jest) and turning on debug mode will give back the list.

To Reproduce
- Run react native app
- Disable debug on developer menu
- Run
import { Settings, Info } from "luxon";
Settings.defaultLocale = "th";
console.log('~~~', Info.months());
Environment MacOS: 12.5.1 Simulator: iOS 16.0 React native version: 0.70.3 Luxon version : 3.0.4
Some of the other weird issue of translation for Thai
The thing to check is the output of formatToParts(new Date())
instead of format()
. That's how Luxon is able to reliably extract the month names. My guess is that that it returns something odd, and Luxon can't make sense of it
I've the same issue when trying Info.months('long', {locale: "es-ES"})
or Info.months('long', {locale: "es"})
for Spanish
The array it returns is just 12 null values:
[null, null, null, null, null, null, null, null, null, null, null, null]
Environment MacOS: 13.0 Simulator: iOS 16.0 React native version: 0.70.3 Luxon version : 3.1.0
We seem to be experiencing the same issue. @ArturoTorresMartinez Were you able to solve it on your side?
The minimal reproducible example would be this:
console.log(DateTime.local().setLocale('en-IE').monthLong)
This returns the month name on Android, but null on iOS :/
Environment: MacOS: 13.2.1 Simulator: 16.4 React Native version: 0.70.9 Luxon version: 3.3.0
This problem affects react native and the Hermes engine in the iOS version, not the luxon library. It is due to missing polyfills.
Just install packages
yarn add @formatjs/intl-locale @formatjs/intl-datetimeformat @formatjs/intl-datetimeformat
And then add this in index.js
:
import '@formatjs/intl-locale/polyfill';
import '@formatjs/intl-datetimeformat/polyfill';
import '@formatjs/intl-datetimeformat/add-all-tz';
And this for all your supported languages, like:
import '@formatjs/intl-datetimeformat/locale-data/en';
import '@formatjs/intl-datetimeformat/locale-data/pl';
be careful when adding the "@formatjs/intl-locale/polyfill" fix - in my case it broke Luxon's fromISO, fromJSDate and others luxon "from.." methods on mobile. It would be better to hardcode weekdays and month names. Like it's described in https://github.com/digitalfabrik/integreat-app/pull/2322