Vagelis Ouranos
Vagelis Ouranos

Reputation: 482

Multiple languages in android app using sqlite and xml resources

I want to support multiple languages in my app using sqlite database and xml resources. For example, the user can insert transaction objects. Each transaction has a category.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="categories">
        <item>@string/category1</item>
        <item>@string/category2</item>
        <item>@string/category3</item>
        <item>@string/category4</item>
        <item>@string/category5</item>
    </array>
</resources>   

What is the correct approach to use the above values in sqlite? Should a table be created or I can use them directly from xml?

If I want the user to be able to also add his own categories, how the multi-language thing should work?

Upvotes: 0

Views: 1235

Answers (1)

Simulant
Simulant

Reputation: 20132

Please read the two following google guides about supporting different languages and localizing: http://developer.android.com/training/basics/supporting-devices/languages.html http://developer.android.com/guide/topics/resources/localization.html

the normal way is to create a strings.xml for every language: For Storing your categories in your SQLite Database you should enumerate your Categories and store only the numbers, so you are independent of the spelling. Adding a user defined Catergory should also work this way.

MyProject/
  res/
    values/
       strings.xml
    values-es/
       strings.xml

/values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="title">My Application</string>
  <string name="hello_world">Hello World!</string>
</resources>

/values-es/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="title">Mi Aplicación</string>
  <string name="hello_world">Hola Mundo!</string>
</resources>

Upvotes: 1

Related Questions