I have the need to find a solution to a problem with the app_name
of my android project.
The idea is that I should be able to have app_name
for both English and Spanish, but only allow me for one. Any way out?
I have the need to find a solution to a problem with the app_name
of my android project.
The idea is that I should be able to have app_name
for both English and Spanish, but only allow me for one. Any way out?
For that case you can use the multilanguage support by defining a string called app_name
in each strings.xml file defined for a different language.
<string name="app_name">Mi Aplicación</string>
These texts, in addition to the name of the application, can be applied to others in the application.
The location scheme requires that you create folders and files containing the text and its identifier in different languages as required, which will be supported by your application.
For example, if we assume that our application supports English, Spanish and Romanian languages, we should have the following folders ....
The default text folder would be:
res/values/strings.xml
The folder to add the texts in English:
res/values-en/strings.xml
would contain:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="nom">Crazy Dog</string>
<string name="desc">Crazy dog Transportation, the best company</string>
</resources>
The folder to add the texts in Spanish is:
res/values-es/strings.xml
would contain:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="nom">Perro Loco</string>
<string name="desc">Transportes Perro Loco, la mejor empresa</string>
</resources>
The folder to add the texts in Romanian:
res/values-ro/strings.xml
would contain:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="nom">Câine nebun</string>
<string name="desc">companie de transport Câine nebun, cea mai buna companie.</string>
</resources>
You would have something similar to this in your project:
Simply those descriptions defined in your strings.xml
use them where required in your application:
String strNombre = context.getResources().getString(R.string.nom);
textViewName.setText(strNombre);
String strDescripcion = context.getResources().getString(R.string.desc)
textViewDesc.setText(strDescripcion);
The great advantage is that automatically, depending on the language defined in your operating system, it loads the texts defined in the file strings.xml
of the corresponding language.
To solve this problem it would be enough to make the app support several languages. For this you can take a look at the documentation of android .
For your specific problem with the name of the App, you can do the following:
In your Manifest you must make use of the string resources, so that the device takes the corresponding language automatically, for this you use @string/
being as follows:
<application
android:name=".MyApp"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme">
On the other hand to add support for more languages, you will have to create additional values directories within res / that include a script and the ISO language code at the end of the directory name. As for example values-en , being as follows:
MyProject/
res/
values/
strings.xml
values-en/
strings.xml
Finally you will have to add the string values for each regional configuration in the corresponding file. For example:
Spanish (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Mi Aplicación</string>
</resources>
English, /values-en/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My Application</string>
</resources>
I hope it helps you