Search code examples
androidsqlitedatabase-designandroid-sqlite

How to design SQLite DB so it can be used for multiple languages?


I'm working on an Android app that for now is just in English, but in the future I want to have it support multiple languages. Most of my content will be in an SQLite database, but I can't figure out how to design it in such a way that later I can add more languages to it.


Solution

  • It's not that hard. You need one extra table for all languages / locales that you want to support

    id - locale
    1 - de
    2 - en
    3 - fr
    ...
    

    And every table that contains text that you need in different languages should have a reference (foreign key) to the locale table and then one entry per language version

    id - id_locale - content
    1 - 1 - something German
    1 - 2 - something English
    1 - 3 - something French
    2 - 1 - something else in German
    ...
    

    Also add a unique constraint on (id, id_locale)