Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeModules.SettingsManager.settings doesn't have AppleLocale field on iOS 13 #26606

Closed
grindos opened this issue Sep 26, 2019 · 9 comments
Closed
Labels
API: Settings Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@grindos
Copy link

grindos commented Sep 26, 2019

React Native version:
0.59.9

iOS version on simulator:
13.0

Steps To Reproduce

  1. Check the OS type.
  2. If the OS type is not Android, try to get the locale.
  3. Get the NativeModules.SettingsManager.settings object and take AppleLocale field from it.
  4. Take only last two letters from the string to get the region name. E.g. for en-US will be returned US.

Describe what you expected to happen:
For iOS 12.2 and earlier the NativeModules.SettingsManager.settings object contained AppleLocale field, so everything worked correctly on the same React Native version. I expected that for iOS 13 it will work correctly too.

Code example:

  const locale = Platform.OS === 'android' ?
    NativeModules.I18nManager.localeIdentifier :
    NativeModules.SettingsManager.settings.AppleLocale;
  const localeLastChars = locale.slice(-2);
@grindos grindos added the Bug label Sep 26, 2019
@grindos grindos closed this as completed Sep 26, 2019
@grindos grindos reopened this Sep 26, 2019
@grindos
Copy link
Author

grindos commented Sep 26, 2019

Also was mentioned in #26540

@ghost
Copy link

ghost commented Oct 31, 2019

This is also happening to me on react-native version 0.61.3

@MrPingoo
Copy link

It's the same for me but I'm using expo

@MrPingoo
Copy link

I solved my problem with this https://docs.expo.io/versions/v34.0.0/sdk/localization/
And I used only Localization.locale

@sibelius
Copy link

sibelius commented Dec 3, 2019

try this

const getDeviceLocale = () => {
  if (Platform.OS === 'ios') {
    let locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR"
    if (locale === undefined) {
        // iOS 13 workaround, take first of AppleLanguages array  ["en", "en-NZ"]
        locale = NativeModules.SettingsManager.settings.AppleLanguages[0];
        if (locale) {
          return locale;
        }
    }
  }

  if (Platform.OS === 'android') {
    return NativeModules.I18nManager.localeIdentifier;
  }

  return 'pt-BR';
};

@secretgh
Copy link

@sibelius
That code will come back with an error evaluating the t.proptypes

@grindos
Copy link
Author

grindos commented Dec 12, 2019

@secretgh @sibelius in fact, I'm using the same workaround at this moment and it works fine, but it would be great to have not a workaround solution, but make available AppleLocale at every moment. I don't think that iOS works without locale sometimes, especially if AppleLanguages is available

@stale
Copy link

stale bot commented Mar 11, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 11, 2020
@stale
Copy link

stale bot commented Mar 18, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Mar 18, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API: Settings Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants