A database with multiple tables . One of them for example transporte
with the following attributes:
Nombre
Descripción
Precio
Initially the application will be available in two languages.
What to save in the Database? That is, the description must be in Spanish and English. So in the DB, in the description field, do I save the name of the variable that will be stored in the file string.xml
of each language? and in string.xml
each language the content will be written.
Otherwise, the database must have a field for each multilingual attribute. For example:
Nombre_es
Nombre_en
Descripcion_es
Descripcion_en
Precio
But I think this second case complicates the app more because depending on the user's current language, different SQL queries will be made.
What is the best practice to develop in this type of case?
edit
As an example I have put the content of 1 tabla
the DB but it will contain several relational tables. That's where the doubt comes from. To carry out some tasks, queries to the DB with its inner join
and other commands will be necessary.
If it were just about localizing the UI, Android already has support for localization using resources like
strings.xml
Learn more about localization on Android: Localizing with Resources
But nevertheless from what I understand you need the data you store in your database to be findable. In this case, it is best to have a multilanguage scheme in your DB.
Example: (Ignore data types)
In this way, in the main table you would have the primary key and all those attributes that do not vary according to the language, such as prices, amounts, dates, etc.
In an intermediate table between the main table and the language table you will have a row for each transport-language combination that contains the data that does vary by language, in your case
Nombre
andDescripcion
To get into context, if you use files
strings.xml
defined for a language, you don't need a database to store some information, unless you want a different localization scheme.I think in this case you should take advantage of Android's support for changing your UI information based on your language settings. The localization scheme requires you to 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 suppose that our application supports English, Spanish and Romanian languages, we must have the following folders....
The default text folder would be:
The folder to add the texts in English:
would contain:
The folder to add the texts in Spanish is:
would contain:
The folder to add the Romanian texts:
would contain:
You would have something similar to this in your project:
You simply use those descriptions defined in your
strings.xml
application wherever it is required in your application:strings.xml
The great advantage is that automatically, depending on the language defined in your operating system, it loads the defined texts in the corresponding language file .My point of view regarding your questions:
I do not think it is convenient or necessary to combine the use of a database with strings.xml in this case. If you choose to use a database, it would use the same schema used by "Android Localization". The database would contain tables texto_es and texto_en, which would contain the same field names
You simply decide which table to take the texts from and the code needed to display them shouldn't change.
I consider it is a major advantage instead of a single table with different field names:
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...
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 on a database is, first of all, the fast access to them through the R class and the code necessary for the implementation is minimal.
There is also the option to integrate multi-language in a database, implementing the technique used
QTranslate
by the WordPress pluginIn the fields, where you need to have them in more than one language:
For each language to include, you can include and identify it:
The following function is used to extract a string with a specific language.
Its use in PseudoCode