Today we are going to learn how we can set the title of our APP in different languages using Flutter.
For Android
The first thing we need to do is go to the title of our APP, which is located inside android\app\src\main\AndroidManifest.xml
<application android:label="app_name"
Now let’s create a variable that will allow us to change the title according to the language:
<application android:label="@string/app_name"
We have created a variable called app_name inside string.
Now we have to create these variables, for Spanish and English.
First, let’s create a string resources file for each language, the files would be res/values-en/strings.xml
and res/values-es/strings.xml
respectively.
The content of res/values-en/strings.xml
could be:
<resources> <string name="app_name">My APP</string> </resources>
And the content of res/values-es/strings.xml
could be:
<resources> <string name="app_name">Mi Aplicación</string> </resources>
And that’s it, now the title of our APP will appear according to the language set on our device.
For iOS
The first thing we need to do is go to the title of our APP, which is located inside ios\Runner\Info.plist
<
pre class=”EnlighterJSRAW” data-enlighter-language=”generic” data-enlighter-theme=”” data-enlighter-highlight=”” data-enlighter-linenumbers=”” data-enlighter-lineoffset=”” data-enlighter-title=”” data-enlighter-group=””>
Now let’s create a variable that will allow us to change the title according to the language:
<
pre class=”EnlighterJSRAW” data-enlighter-language=”generic” data-enlighter-theme=”” data-enlighter-highlight=”” data-enlighter-linenumbers=”” data-enlighter-lineoffset=”” data-enlighter-title=”” data-enlighter-group=””>
We have named it PRODUCT_NAME.
To change the application name based on the language, we are going to create specific localization files for each language we want to support. In this case, we will create InfoPlist.strings
files for English and Spanish.
- In the project directory, navigate to the path
ios/Runner
. Here, we should have folders for each language we want to support, likeen.lproj
andes.lproj
. - Inside each of these folders, create or edit the
InfoPlist.strings
file. - In
InfoPlist.strings
for English (en.lproj/InfoPlist.strings
), add the following:
"CFBundleName" = "My APP";
- In
InfoPlist.strings
for Spanish (es.lproj/InfoPlist.strings
), add the following:
"CFBundleName" = "Mi Aplicación";
With these changes, iOS will automatically select the correct application name based on the language of the user’s device.
To set English as the default language, you must ensure that all texts in your application are available in English. If the language of the user’s device is neither English nor Spanish, iOS will use English as the fallback language.