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 · 54 comments

Comments

@pcomans
Copy link

@pcomans pcomans 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
Copy link

@realcarlos realcarlos commented Feb 1, 2018

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

Loading

@MarkOSullivan94
Copy link

@MarkOSullivan94 MarkOSullivan94 commented Feb 1, 2018

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

Loading

@jerzykiler
Copy link

@jerzykiler jerzykiler 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 ?

Loading

@pakivika
Copy link

@pakivika pakivika 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.

Loading

@pakivika
Copy link

@pakivika pakivika commented Feb 22, 2018

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

Loading

@reni99
Copy link

@reni99 reni99 commented Mar 12, 2018

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

Loading

@rcpassos
Copy link

@rcpassos rcpassos 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;
},

Loading

@bartwaggoner
Copy link

@bartwaggoner bartwaggoner 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!

Loading

@bartwaggoner
Copy link

@bartwaggoner bartwaggoner 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)

Loading

@pakivika
Copy link

@pakivika pakivika 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.

Loading

@chinmaygarde
Copy link
Member

@chinmaygarde chinmaygarde commented Apr 1, 2018

Loading

@bartwaggoner
Copy link

@bartwaggoner bartwaggoner 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?

Loading

@zanderso
Copy link
Member

@zanderso zanderso 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'.

Loading

@alan-knight
Copy link
Contributor

@alan-knight alan-knight 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.

Loading

@cbracken
Copy link
Member

@cbracken cbracken 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.

Loading

@alan-knight
Copy link
Contributor

@alan-knight alan-knight 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.

Loading

@hyochan
Copy link

@hyochan hyochan commented Apr 30, 2018

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

Loading

@miguelpruivo
Copy link

@miguelpruivo miguelpruivo 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.

Loading

@gustav77
Copy link

@gustav77 gustav77 commented May 24, 2018

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

Loading

@arbus
Copy link

@arbus arbus 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

Loading

@gerryhigh
Copy link

@gerryhigh gerryhigh commented May 26, 2018

See also #17933

Loading

@XYliang
Copy link

@XYliang XYliang commented Apr 18, 2019

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

Loading

@psyanite
Copy link

@psyanite psyanite 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.

Loading

@danielaRiesgo
Copy link

@danielaRiesgo danielaRiesgo commented Apr 23, 2019

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

Loading

@eseidelGoogle
Copy link
Contributor

@eseidelGoogle eseidelGoogle commented Apr 23, 2019

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

Loading

@xster
Copy link
Member

@xster xster 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.

Loading

@danielaRiesgo
Copy link

@danielaRiesgo danielaRiesgo 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.

Loading

hyochan added a commit to hyochan/BooKooX that referenced this issue Sep 10, 2019
hyochan added a commit to hyochan/BooKooX that referenced this issue Sep 10, 2019
* Change app name in ios and android
   - Capitalize
* Unify the import statement in main.dart
* Enhanced [Category] model
   - Add showDelete param to show close icon when long pressed.
   - Fixed typo on image name.
   - Initial map value should trigger integer by adding .index.
   - Define `toString` for debug ease.
* Implment showCategory method
   - Add `getConsumeCategories` and `getIncomeCategories` in DbHelper to get different data at once.
   - Implement poping up the bottomSheet when clicking on the category.
   - Organize import statements.
   - Implement [CategoryItem] seperately to handle changes of state more clearly.
* Installed auto_size_text package
   - To show full text in category item.
* Fixed close icon for category_item
* Installed fluttertoast to use toast easily
* Renamed popup dialog in general.dart
* Implement category delete
   - Seperated [CategoryItem] and [CategoryList] from [LedgerItemAdd] to control state.
   - Use `Key` to re-render item in `SingleScrollView` when state changes.
* Use `SafeArea` for [CategoryList]
* Implement [CategoryAdd] screen dialog
   - Decided to put this in screen widget rather than shared since it looks more like a screen.
* Moved [CategoryAdd] to screen from shared
* Beautifully add categories in CategoryAdd screen
   - All synced with local db.
* Changed relative import path to absolute path using package:bookoo2
* Add korean to xcode localization
   - Related issue flutter/flutter#14128.
* Fix null exception when category icon add is null
* Select category and render selected in renderBox
* Added test files
   - Hard to mock sqflite currently because of the issue 
      - tekartik/sqflite#83.
@Wojak27
Copy link

@Wojak27 Wojak27 commented Sep 24, 2019

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

You've saved my project mate

Loading

@Xgamefactory
Copy link

@Xgamefactory Xgamefactory commented Oct 9, 2019

that gives build error

Runner/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file.

Loading

@joaorpalma
Copy link

@joaorpalma joaorpalma commented Oct 27, 2019

To fix this open Runner.xcworkspace, select Runner Project and in the Info tab add the Localizations that you want to support.

Loading

engine-flutter-autoroll added a commit that referenced this issue Dec 4, 2019
git@github.com:flutter/engine.git/compare/07aab98212cb...fdaa7cf

git log 07aab98..fdaa7cf --first-parent --oneline
2019-12-04 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/mac-amd64 from OSk8h... to XCAOU... (#14128)
2019-12-04 skia-flutter-autoroll@skia.org Roll src/third_party/skia 75368c3a0290..ccca30aad770 (12 commits) (#14129)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC chinmaygarde@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
@franskjv
Copy link

@franskjv franskjv commented Dec 29, 2019

Hi, I made all the steps from editing info.plist to info in Xcode, but still not working in iOS. I'm using the package flutter_i18n and it works fine on Android. Any help?

info:
Screen Shot 2019-12-29 at 11 02 13

info.plist:
Screen Shot 2019-12-29 at 11 02 24

Doctor:

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-BR)
    • Flutter version 1.12.13+hotfix.5 at /Users/franklin/Development/flutter
    • Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/franklin/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (2 available)
    • iPhone do Franklin • 8ca28e9db21289c970d810c3625aa017... • ios • iOS 13.3
    • iPhone 11 Pro Max  • 29823942-BC97-4196-B74D-A03C680F1...     • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!

Thanks.

Loading

@ale-getman
Copy link

@ale-getman ale-getman commented Jan 24, 2020

Hi, the package easy_localization also always has the result in English.
On the device I changed languages and regions. He left only one language, without English, still nothing helps.

Loading

@Jbz797
Copy link

@Jbz797 Jbz797 commented Feb 11, 2020

Same here with "easy_localization"

Loading

@HartP97
Copy link

@HartP97 HartP97 commented Feb 25, 2020

Is there an official way to fix the issue? I'm using version intl_translation 0.17.9 and here in this thread, I was only able to find workarounds so far, nothing official or with documentation on how to fix it.

Loading

@HartP97
Copy link

@HartP97 HartP97 commented Feb 26, 2020

I found the official fix in the flutter docs: https://flutter.dev/docs/development/accessibility-and-localization/internationalization
In the very bottom under the topic Appendix: Updating the iOS app bundle
(Hint: When you open it up in Xcode, by default in the left menu "Target", the Runner file with Flutter Logo is selected, you have to select the Runner file with Xcode Logo above it with the menu heading "Project" to add a new language)

Loading

@AdrianTudC
Copy link

@AdrianTudC AdrianTudC commented Feb 27, 2020

To fix this open Runner.xcworkspace, select Runner Project and in the Info tab add the Localizations that you want to support.

This seems to be very important step that I barely see mentioned. It made the app work for me both in the simulator and the phone and even with english still available in the settings as one of the languages.

Loading

@kadenchoi
Copy link

@kadenchoi kadenchoi commented Mar 12, 2020

Finally find the solution!!!
Two things need to be added in plist.info

  1. Localizations ( add your included languages )
  2. Localized resources can be mixed - YES

Loading

@lock
Copy link

@lock lock bot commented Apr 4, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

Loading

@lock lock bot locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet