luxon icon indicating copy to clipboard operation
luxon copied to clipboard

Locale not changing the language

Open alimtunc opened this issue 3 years ago • 10 comments

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.

Capture d’écran 2021-06-11 à 12 54 08

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.

alimtunc avatar Jun 11 '21 11:06 alimtunc

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.

icambron avatar Jun 13 '21 14:06 icambron

Also looking for a solution for this one – @alimtunc did you have any luck with this yet?

jasondibenedetto avatar Jun 22 '21 05:06 jasondibenedetto

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 ?

alimtunc avatar Jun 25 '21 11:06 alimtunc

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.. :/

alimtunc avatar Jun 25 '21 11:06 alimtunc

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.

Screen Shot 2565-10-30 at 08 50 51

To Reproduce

  1. Run react native app
  2. Disable debug on developer menu
  3. 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

Screen Shot 2565-10-29 at 12 35 43

sorakrisc avatar Oct 30 '22 01:10 sorakrisc

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

icambron avatar Nov 01 '22 21:11 icambron

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

ArturoTorresMartinez avatar Nov 01 '22 23:11 ArturoTorresMartinez

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

kubik369 avatar May 04 '23 12:05 kubik369

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';

lukaszkurantdev avatar Jun 05 '23 09:06 lukaszkurantdev

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

juliaitbaeva avatar Feb 02 '24 23:02 juliaitbaeva