Android APP多语言SQLite

时间:2015-03-30 20:06:20

标签: android sqlite locale multilingual

我会完全翻译我的Android应用。 (这包括SQLite以手机语言显示)

这就像现在连接;

private static final int DATABASE_VERSION = 5;
    private static final String DATABASE_NAME = "quotes.db";
    private static final String DB_PATH_SUFFIX = "/databases/";
    private static final String TABLE_QUOTES = "quote";
    private static final String KEY_ID = "_id";
    static Context myContext;

    public DataBaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        myContext = context;
    }

我原本想删除名称字符串数据库,并使用strings.xml文件将名称数据库传递给它。

super(context,context.getResources()。getString(R.string.DATABASE_NAME),null,DATABASE_VERSION);

还要查找通过strings.xml传递的查询,但找不到清晰的文档。

如果我不引导一点,我将不胜感激。非常感谢。

查询示例:

// Select All Query
        String selectQuery = "SELECT name, COUNT(author_name ) AS count FROM author LEFT JOIN quote ON name = author_name WHERE name LIKE '%"
                + value + "%'  GROUP BY name ORDER BY  name ASC";

1 个答案:

答案 0 :(得分:0)

我修改了表sqlite和代码添加" + Locale.getDefault()。getLanguage()+":

String selectQuery = "SELECT quote._id, quote.author_name_"+ Locale.getDefault().getLanguage()  +", quote.qte_"+ Locale.getDefault().getLanguage()  +
            ", quote.category_name_"+ Locale.getDefault().getLanguage()  +",fav  FROM quote,author where author.name_"+ Locale.getDefault().getLanguage()+
            " = quote.author_name_"+ Locale.getDefault().getLanguage()  +" and quote.category_name_"+ Locale.getDefault().getLanguage()  +
            "!='Tips Romanticos' ORDER BY quote.author_name_"+ Locale.getDefault().getLanguage() +" "+limit;

查询结果为:

  

SELECT quote._id,quote.author_name_es,quote.qte_es,   quote.category_name_es,fav FROM quote,author where author.name_es =   quote.author_name_es和quote.category_name_es!=' Tips Romanticos'   ORDER BY quote.author_name_es LIMIT 50