iOS国际化总是显示英语的问题

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

这个问题提坑了我一天,实际上早已有了解决方案,而且官方文档也已经给出了答案,这里有两个方法:

实际上是一个方法,只是方法一是通过xcode来修改,方法二直接修改plist文件,方法二更直接简单,不用打开xcode

方法一

iOS applications define key application metadata, including supported locales, in an Info.plist file that is built into the application bundle. To configure the locales supported by your app, you’ll need to edit this file.

First, open your project’s ios/Runner.xcworkspace Xcode workspace file then, in the Project Navigator, open the Info.plist file under the Runner project’s Runner folder.

Next, select the Information Property List item, select Add Item from the Editor menu, then select Localizations from the pop-up menu.

Select and expand the newly-created Localizations item then, for each locale your application supports, add a new item and select the locale you wish to add from the pop-up menu in the Value field. This list should be consistent with the languages listed in the supportedLocales parameter.

即需要声明应用需要支持国际化官方文档

方法二

更简单的方法是直接打开 your_project/ios/Runner/Info.plist ,然后加入

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

修改之后如下:

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

github issue链接