Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize app name shown in launcher using flutter?

how to localize app name shown in the launcher?

For example, "Play Store", in Chinese is "Play 商店". Thanks.

I tried to modify android\app\src\main\AndroidManifest.xml like this:

android:label="@string/app_name"

And create files

values-zh/strings.xml
values-en/strings.xml

Example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">App name in different language</string>
</resources>

But, the app name changes only when the system language changed. Is this a common problem (or known bug?) in Android?

In windows, when the app language changes, the app name will change immediately.

So, what I really want is, when the language changes in my app, the app name in the launcher will also change, ignoring the system language.

enter image description here

like image 355
Vincent Avatar asked Feb 21 '19 05:02

Vincent


2 Answers

On Android application's android:label in AndroidManifest.xml is a fixed resource referrer and it's bind to the system language.

So as you saw you can use only configuration qualifier names (values-en, -zh, -large, -land, etc.), according to Providing Alternative Resources.

like image 107
wrozwad Avatar answered Nov 18 '22 16:11

wrozwad


Here is the recipe to localize (Internationalize) Launcher App Name in Flutter πŸ’™

For Android:

  1. Navigate to the following path: android\app\src\main\res
  2. You should find a folder called values if it does not exist, create one, this folder would be for the default locale (language).
  3. Add a file named strings.xml inside the values folder with the following code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="appName">your_app_name</string>
</resources>

NOTE: If the file already exists, then just add the appName key to it which is just this line:

<string name="appName">your_app_name</string>
  1. Change the value of the key appName with your app name for the default locale (language).
  2. Copy the values folder and its contained strings.xml file for each locale, for example if your default locale is English (en) and you want to add Arabic (ar) and Spanish (es) then you will have the following folder structure for the res folder:
β”œβ”€β”€β”€ ...
β”œβ”€β”€β”€values
β”‚   β”œβ”€β”€β”€ ...
β”‚   β”œβ”€β”€β”€ strings.xml
β”‚   └─── ...
β”œβ”€β”€β”€values-ar
β”‚   β”œβ”€β”€β”€ ...
β”‚   β”œβ”€β”€β”€ strings.xml
β”‚   └─── ...
β”œβ”€β”€β”€values-es
β”‚   β”œβ”€β”€β”€ ...
β”‚   β”œβ”€β”€β”€ strings.xml
β”‚   └─── ...
└─── ...

NOTE: You don't have to copy all the keys and values inside the strings.xml file, if you have another keys that you don't want to localize them, then you can ignore them for each locale and just include the keys you want to localize, e.g. in this case appName.

  1. For each locale, go to its values folder and change the value of the key appName inside the strings.xml file.
  2. Naviagte to AndroidManifest file in the following path: android\app\src\main\AndroidManifest.xml and change the value of android:label inside the application tag to be android:label="@string/appName".
  3. Done πŸ”₯

For IOS:

  1. Do all the steps in this answer.
  2. The only key that you would have to localize is CFBundleName which is the launcher name of the app.
  3. Done πŸ”₯
like image 2
Moaz El-sawaf Avatar answered Nov 18 '22 17:11

Moaz El-sawaf