LoginSignup
1
1

More than 3 years have passed since last update.

Flutterでサポートされていない言語の場合に、Android端末で表示される言語

Posted at

Flutterで多言語化している最中に、supportedLocales にリストされていない言語のときに、表示される言語が意図したとおりに動かず少しハマりました。

例として以下の言語設定の場合に、 端末の言語設定がドイツ語の場合 en が使用されると思っていました。


supportedLocales: [
  const Locale('en'),
  const Locale('zh'),
  const Locale('ja'),
],

理由は公式ドキュメントの 以下の文章。

If an exact match for the device locale isn’t found, then the first supported locale with a matching languageCode is used. If that fails, then the first element of the supportedLocales list is used.

languageCodeが一致するものがない場合、リストの先頭が利用されるはず。。

ですが実行してみると中国語が表示されました。

トライアンドエラーで色々試してみた結果、Androidは端末の言語設定の優先順位も関係するようでした。
今回中国語が表示されたのは、端末の言語設定の優先順位が以下のようになっていたからでした。

  1. ドイツ語
  2. 中国語
  3. 日本語
  4. etc...

利用する言語をドイツ語の1つのみにしたところ、期待したとおり英語が表示されました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1