moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.25k stars 731 forks source link

Locale not changing the language #956

Open alimtunc opened 3 years ago

alimtunc commented 3 years ago

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):

Thank's for any help.

icambron commented 3 years ago

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.

jasondibenedetto commented 3 years ago

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

alimtunc commented 3 years ago

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 commented 3 years ago

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

sorakrisc commented 1 year ago

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](https://user-images.githubusercontent.com/22723894/198858787-bda3d905-821d-4ddf-a8a1-f5048feb0336.png)
icambron commented 1 year ago

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

ArturoTorresMartinez commented 1 year ago

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

kubik369 commented 1 year ago

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

lukaszkurantdev commented 1 year ago

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';
juliaitbaeva commented 7 months ago

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