Search code examples
androidlocale

android - set appropriate database name based on current locale in device


I want to set appropriate database name based on current locale in device. Any advice? Thanks you guys.

public class DatabaseHelper extends SQLiteAssetHelper {

private String currentLanguage = "";
private static final String DATABASE_NAME = "";
private static final int DATABASE_VERSION = 1;

public DatabaseHelper(Context context) {
    //I want the DATABASE_NAME should depends on current locale in device,
    //if the current language of device is english, DATABASE_NAME = "db_en", 
    //else it is french, DATABASE_NAME = "db_fr"
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

Solution

  • You can store your database name in the strings.xml file and localize it. More info here: http://developer.android.com/guide/topics/resources/localization.html