2015-03-30 34 views
1

我會完全翻譯我的Android應用程序。 (這包括SQLite顯示在手機上的語言)Android APP多語言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"; 
+0

如果您切換的數據庫是基於語言的使用,那麼你不也需要查詢使用strings.xml,結果已經從翻譯的數據庫中提取,對嗎?您是否遇到粗體行的問題:super(context,context.getResources()。getString(R.string.DATABASE_NAME),null,DATABASE_VERSION); – BSMP 2015-03-30 20:23:01

+0

嗨,是的,現在我試圖通過將數據庫的名稱放在strings.xml中來實現,因爲這個想法是添加更多的語言。 'public void openDataBase()throws SQLException { \t \t File dbFile = myContext.getDatabasePath(context.getResources()。getString(R.string.DATABASE_NAME)); \t \t如果{ \t \t \t嘗試{ \t \t \t \t CopyDataBaseFromAsset()(dbFile.exists()!); \t \t \t \t System.out.println(「從資產文件夾複製成功」); \t \t \t}趕上(IOException的發送){ \t \t \t \t擲新的RuntimeException( 「錯誤創建源數據庫」,E); \t \t \t} \t \t} \t}' – EmanuelAA 2015-04-09 12:55:49

+0

搜索:光標光標= DB .rawQuery( 「選擇quote._id,quote.author_name,」 ** +資源。getSystem()。getString(R.string.quer1)+ **「quote.qte,quote.category_name,fav FROM quote,author WHERE author.name = quote.author_name AND」 + KEY_ID +「=」+ id,null ); 嘗試{ – EmanuelAA 2015-04-11 05:08:31

回答

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.na me_es = quote.author_name_es和quote.category_name_es!=「提示Romanticos」 ORDER BY quote.author_name_es限量50