To enter context, if you use strings.xml
files defined for a language, you do not need a database to store some information, unless you want a different schema than the localization one.
I think that in this case you should take advantage of the support with which Android account to change the information of your UI based on the language configuration. The localization 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.
My point of view regarding your questions:
What to save in the Database? That is, the description should
be in Spanish and English. Then in the BD, in the description field
I do not think it convenient or necessary to combine the use of a database with strings.xml in this case. If you choose to use a database, you would use the same scheme used by "Android Localization". The database would contain tables texts and texts, which would contain the same field names.
Nombre
Descripcion
Precio
You simply decide which table to take the texts and the code needed to display them would not have to change.
I consider it a greater advantage instead of a single table with different field names:
Nombre_es
Nombre_en
Descripcion_es
Descripcion_en
Precio
That in code you would have to validate in which field to use, it would become unnecessarily more complex if in the future you had support for other languages ...
Do I save the name of the variable that will be stored in the file?
string.xml of each language?
It is not necessary to save the name of the variable in a database, the variable is the same within the strings.xml, but the content in each file would be in different languages.
In this case, the advantage of using Strings.xml over a database is first of all the quick access to them through the R class and the code needed for the implementation is minimal.