简体   繁体   中英

Android APP multilanguage SQLite

I would fully translate my Android app. (this includes the SQLite is displayed on the phone language)

This is like now connect;

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;
    }

I had thought to remove the name string database and pass it the name database using the strings.xml file.

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

Also look for the query to pass on through strings.xml, but can not find clear documentation.

I would appreciate if I do not guide a little. Many Thanks.

Example the query:

// 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";

I modifing the table sqlite and code adding "+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;

The query result is:

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 and quote.category_name_es!='Tips Romanticos' ORDER BY quote.author_name_es LIMIT 50

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM