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

Flutter on iOS always chooses English for localization, even if the system's preferred language is not english #14128

Closed
pcomans opened this issue Jan 16, 2018 · 43 comments

Comments

@pcomans
Copy link

commented Jan 16, 2018

Steps to Reproduce

I have two languages set up on iOS and Android:

  • German
  • English

German is the preferred language of the system, meaning the OS and most apps appear in German.

I created an app that has translations for both English and German:

    return new MaterialApp(
      localizationsDelegates: <LocalizationsDelegate<dynamic>>[
        new _MyLocalizationsDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('de', 'DE'), // German
        const Locale('en', 'US'), // English
      ],
      title: "MyApp",
      home: new Home(),
    );
class _MyLocalizationsDelegate extends LocalizationsDelegate<MyStrings> {
  @override
  Future<MyStrings> load(Locale locale) => MyStrings.load(locale);

  @override
  bool shouldReload(_MyLocalizationsDelegate old) => false;
  @override
  bool isSupported(Locale locale) =>
      locale.languageCode == 'en' ||
      locale.languageCode == 'de';
}

On Android, this app appears in German. On iOS, it appears in English.
The only way to force the app to appear in German is to remove English as a secondary language of the system.

Is this a bug? Am I missing something?

Flutter Doctor

[✓] Flutter (on Mac OS X 10.12.6 16G1036, locale en-US, channel alpha-chq)
    • Flutter at /Users/philipp/code/flutter
    • Framework revision 0bd83f8c34 (12 days ago), 2018-01-04 18:01:44 -0800
    • Engine revision edaecdc8b8
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-edge.d8ae797298c3a6cf8dc9f4558707bd2672224d3e

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/philipp/Library/Android/sdk
    • Android NDK at /Users/philipp/Library/Android/sdk/ndk-bundle
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[-] iOS toolchain - develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    ✗ Verify that all connected devices have been paired with this computer in Xcode.
      If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
      To update, run:
        brew uninstall --ignore-dependencies libimobiledevice
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    • ios-deploy 1.9.2
    • CocoaPods version 1.4.0.beta.2

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.1 Preview.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1012-b01)

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2017.2.5)
    • Flutter plugin version 18.4
    • Dart plugin version 172.4343.25
@realcarlos

This comment has been minimized.

Copy link

commented Feb 1, 2018

Yes ,same problem! Localization in Flutter is so unuseful now.

@MarkOSullivan94

This comment has been minimized.

Copy link

commented Feb 1, 2018

@realcarlos have you tested with any other languages apart from German and English?

@jerzykiler

This comment has been minimized.

Copy link

commented Feb 4, 2018

This is probably because of this:

[NSLocale currentLocale] is based on the device's Region Format settings, not the language. If the region is set to United States you will get en_US regardless of which language you're using.

from
https://stackoverflow.com/questions/1522210/nslocale-currentlocale-always-returns-en-us-not-users-current-language

Any advices on how to get the preferred language ?

@pakivika

This comment has been minimized.

Copy link

commented Feb 19, 2018

Hoping this gets prioritised. I encounter the same issue, and Flutter always picks English even when I have translations for other languages present and device set to another lang.

@pakivika

This comment has been minimized.

Copy link

commented Feb 22, 2018

I have four translations available in my app but Flutter always picks English regardless of device language.

@reni99

This comment has been minimized.

Copy link

commented Mar 12, 2018

I guess this is fixed. I am using Flutter 0.1.1, channel dev

@rcpassos

This comment has been minimized.

Copy link

commented Mar 14, 2018

I have this problem too, but only doesn't work on iOS, on android is working ok.

EDIT
On iOS the locale returns en_PT instead of pt_PT, on Android returns pt_PT as expected.
So with this code I can solve the issue, but I'm not happy with this "hack"

localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
  for (var supportedLocale in supportedLocales) {
    if (locale.countryCode == supportedLocale.countryCode) {
      return supportedLocale;
    }
  }
  return locale;
},
@bartwaggoner

This comment has been minimized.

Copy link

commented Mar 16, 2018

We have this problem, too. We are using Platform.localeName and it works for android, but always returns "en_US" for iOS. This issue could hold up the release of our product!

@bartwaggoner

This comment has been minimized.

Copy link

commented Mar 16, 2018

Note we also tried Localizations.localeOf(context) and it also returned "en_US" for iOS, regardless of the device's language (in Settings > General > Language)

@pakivika

This comment has been minimized.

Copy link

commented Apr 1, 2018

How could we get this one prioritised? This is the only bug in addition to #11648 that blocks me from releasing my app.

@chinmaygarde

This comment has been minimized.

Copy link
Member

commented Apr 1, 2018

@chinmaygarde chinmaygarde removed the framework label Apr 1, 2018

@bartwaggoner

This comment has been minimized.

Copy link

commented Apr 1, 2018

pakivika - we considered adding a language option to the app's settings dialog: perhaps that is something you could do short term in order to release?

@zanderso

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

It looks like the view controller's onLocaleUpdated (here) is correctly wired up to set Window._locale (via the engine -> the runtime controller -> the window -> dart:ui). Wiring up Window._locale to Platform.localeName is the same code as on Android so that probably works. This could be failing on iOS if the onLocaleUpdated callback isn't getting called for some reason, and then the default is 'en_US'.

@alan-knight

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

Removing the flutter-specific locale code in the VM and letting it fall back to the VM version seems to produce correct results for me on iOS. It gives me a language based on my iOS language preference, and a country based on my region. Which can lead to not very helpful locales like 'fr-US', but given what I told the OS that seems reasonable.

@cbracken

This comment has been minimized.

Copy link
Member

commented Apr 23, 2018

@alan-knight if you were able to repro this, can I get detailed repro instructions? Specifically:

  1. Was this a physical device, simulator, or both?
  2. In Settings > General > Language & Region, what are your values for:
    a. iPhone Language
    b. Preferred Language Order
    c. Region
  3. In Xcode, open ios/Runner.xcworkspace, select the Runner project in the project explorer sidebar, then click on the left-hand side of the dropdown to the right of the Run/Stop buttons (on 'Runner'), select Edit Scheme..., select 'Run' in the left column, and select the 'Options' tab. Can you verify that 'Application Language' and 'Application Region' are set to 'System Language' and 'System Region'?

I've seen a few reports relating to the 3rd item above, so worth verifying there's no override in your project config.

@alan-knight

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2018

  1. Simulator

2 a. Francais
b. Francais
Espanol
c. France

  1. Yes, they are set to System Language and System Region.
@hyochan

This comment has been minimized.

Copy link

commented Apr 30, 2018

Same problem here. Only works fine in real device. Not working in ios simulator.

@miguelpruivo

This comment has been minimized.

Copy link

commented May 22, 2018

Same problem here. I have PT and EN and it picks EN on iOS despite the device being in PT. On Android works fine tho.

Edit: As some others mentioned already, you must not have English as your optional language, otherwise it will always pick English regardless of the order. This need to be prioritized.

@gustav77

This comment has been minimized.

Copy link

commented May 24, 2018

Same problem here. Does not work neither on the real device nor in the simulator.

@arbus

This comment has been minimized.

Copy link

commented May 24, 2018

Works ok on a real device if the non-english language is the only language selected. It doesn't seem to matter if the non-english language is put at higher preference than the english one.

2018-05-24 19 22 53
2018-05-24 19 22 57

@gerryhigh

This comment has been minimized.

Copy link

commented May 26, 2018

See also #17933

@tiagosito

This comment has been minimized.

Copy link

commented Jun 28, 2018

I followed in the steps of @Sonius94 and @tvolkert and worked wonderfully... but I skipped a few steps and did not even have to open xCode

See how simple it is

just open the Info.plist file that should be on this path: your_project/ios/Runner/Info.plist
edit the file, putting this as an example, in your case put the languages you want to support
and be happy

  <key>CFBundleLocalizations</key>
  <array>
    <string>English</string>
    <string>pt</string>
    <string>es</string>
    <string>ja</string>
  </array>

The file should look pretty much like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>en</string>
  <key>CFBundleExecutable</key>
  <string>$(EXECUTABLE_NAME)</string>
  <key>CFBundleLocalizations</key>
  <array>
    <string>English</string>
    <string>pt</string>
    <string>es</string>
    <string>ja</string>
  </array>
  <key>CFBundleIdentifier</key>
  <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
.
.
.
other lines
@tiagosito

This comment has been minimized.

Copy link

commented Jun 28, 2018

Should this problem be closed? @Hixie

@miguelpruivo

This comment has been minimized.

Copy link

commented Jun 28, 2018

@Sonius94 solution worked for me. However I believe that the docs should include a reference for this as pointed out for @Hixie.

@tiagosito

This comment has been minimized.

Copy link

commented Jun 28, 2018

@miguelpruivo ops ... this really should be done urgently, thanks for reminding me of that point

@Hixie Hixie modified the milestones: bucket7, bucket8 Jul 17, 2018

@gerryhigh

This comment has been minimized.

Copy link

commented Jul 18, 2018

FYI - this is still not documented on the flutter website (e.g. https://flutter.io/tutorials/internationalization/ ). My developer was testing on iOS today and I had to google to find the answer here. /cc @eseidelGoogle

@cbracken

This comment has been minimized.

Copy link
Member

commented Jul 18, 2018

@gerryhigh this is on our radar and scheduled for our next release cycle. We keep an eye on thumbs-ups as one of several metrics we use to prioritise, so I’d definitely encourage you to upvote this and any other issues that affect you.

@aubykhan

This comment has been minimized.

Copy link

commented Jul 19, 2018

@Sonius94 you saved the day for many! Thanks!!!

@opensourcegps

This comment has been minimized.

Copy link

commented Aug 14, 2018

To add to the docs, in case you want your languages listed in iTunes (Store Information), you need to add Base Localization languages in Project info, Localizations section.

untitled

@cbracken

This comment has been minimized.

Copy link
Member

commented Sep 10, 2018

Documentation added in flutter/website#1247.

@cbracken cbracken closed this Sep 10, 2018

@cbracken cbracken moved this from Assigned to Done in cbracken tasks Sep 10, 2018

@iKK001

This comment has been minimized.

Copy link

commented Jan 25, 2019

Android worked quickly but iOS needs more patience: Finally, the two entries (the one from @cbracken [23rd April] and the one from @tvolkert [6th June] together did it for me ! Thank you both :) !

@danielaRiesgo

This comment has been minimized.

Copy link

commented Apr 17, 2019

I have the Localizations in the Info.plist and the Scheme set to System Language and Region. But, running in the simulator, I still get en_US in flutter code when the Language is es_AR. It even works inside iOS, because I've got the app name localized in the InfoPlist.strings and it's taking the correct spanish name.
Can anyone help me?

Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8661d8a (9 weeks ago) • 2019-02-14 19:19:53 -0800
Engine • revision 3757390
Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

@XYliang

This comment has been minimized.

Copy link

commented Apr 18, 2019

you should setting in xcode. select path : Runner - info- localizations . then add your support language in form list.

@psyanite

This comment has been minimized.

Copy link

commented Apr 22, 2019

Here's what I had to do

  1. Set new language as phone language, remove English from preferred language order list
  2. Update Info.plist accordingly
  3. Update Runner -> Localizations
  4. flutter clean

Read the previous comments for more information.

@danielaRiesgo

This comment has been minimized.

Copy link

commented Apr 23, 2019

I already did that, but it's not working for me. I did use Base internalization, may that be relevant?

@eseidelGoogle

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

Unclear if we need to re-open this issue? (@xster might know.)

@xster

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

@danielaRiesgo could you open a new bug with the steps you tried to follow?

It could help us figure out if our documentation at https://flutter.dev/docs/development/accessibility-and-localization/internationalization needs to be extended.

@danielaRiesgo

This comment has been minimized.

Copy link

commented Apr 25, 2019

Hi all ! I found the problem, it was our Flutter code.
At the LangLocalizationsDelegate class, localeResolutionCallback function, we did:

if (supportedLocale.languageCode == locale?.languageCode || supportedLocale.countryCode == locale?.countryCode)

instead of:

if (supportedLocale.languageCode == locale?.languageCode)

So we had es_US, and it picked english first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.