android - The way to change database helper to support multiple languages? -


this dbhelper code. want ask whether possible support multiple language in database? there need use google translate api or should create database language?

private databasehelper dbhelper; private sqlitedatabase db;  private static final string k_id = "id"; private static final string k_name = "name"; private static final string k_ben = "benefit"; private static final string table = "plant";  private static class databasehelper extends sqliteopenhelper {     databasehelper(context context) {         super(context, "dbplant", null, 1);     }      public void oncreate(sqlitedatabase db) {          string sql = "create table " + table + " (" + k_id                 + " integer primary key ," + k_name + " text , " + k_ben                 + " text);";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('aloe (aloe vera)','this plant has hundreds of uses, popular being ability alleviate pain of burns , speed healing. immerse burn in cold water or apply ice until heat subsides, generously apply aloealoe may applied cut or skin abrasion, , onto skin eruptions, remarkably speeding healing. relieve pain , itching of hemorrhoids, carve out suppository sized chunk of inner leaf gel , insert rectum.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('garlic (allium sativum)','best known antibiotic effect, garlic bulbs or milder garlic greens can eaten raw @ onset of cold or flu. garlic oil used ear infections. made finely chopping enough fresh organic garlic bulbs fill jelly jar, , covering them organic olive oil.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('ginger (zinziber officiale)','ginger has carminative effect, means relieve digestive problems result in gas formation. diaphoretic, used both tea , added soaking bath stimulate sweating , reduce fevers.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('coconut','white meat , water cavity used heart conditions, dysentery, fever, pain, , digestive , bladder problems, quench thirst , aphrodisiac. treat diarrhea, meat young fruits mixed other ingredients , rubbed onto stomach. oil prepared boiling coconut milk thought of antiseptic , soothing , smoothed onto skin treat burns, ringworm , itching.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('carallia brachiata','the bark extracted petroleum ether, ethyl acetate , methanol successively. extracts screened wound healing activity excision , incision models in wistar rats. ethyl acetate , methanol extracts found possess significant wound healing activity. extracts revealed presence of sterols or triterpenoids, flavonoids, phenols, tannins, carbohydrates, fixed oils , fats.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('ficus hispida','the fruits bitter, refrigerant, astringent, acrid, anti-dysenteric, anti-inflammatory, depurative, vulnerary, haemostatic , galactagogue. useful in ulcere, leucoderma, psoriasis, anaemia, haemorrhoids, jaundice, epistaxis, stomatorrhagia, inflammations, intermittent fever , vitiated conditions of pitta.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('leea indica','a decoction of root given in colic, cooling , relieves thirst. in goa, root used in diarrheal , chronic dysentery. roasted leaves applied head in vertigo. juice of young leaves digestive. plant pacifies vitiated pitta, diarrhea, dysentery, colic, ulcers, skin diseases, , vertigo.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('mesua ferrea','flowers acrid, anodyne, digestive, constipating, , stomachic. used in treating asthma, leprosy, cough, fever, vomiting , impotency. seed oil pacifies vata, , skin diseases , rheumatism');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('trema orientalis','it has been used medicinal purposes including treatment of respiratory, inflammatory, , helminthic diseases. every part of plant used medicine in various parts of africa.');";         db.execsql(sql);         sql = "insert "                 + table                 + " ("                 + k_name                 + ","                 + k_ben                 + ") values('murraya paniculata','the decoction of leaves can used gargle treat toothache. leaves used treat pain due scalding. decoction can given orally treat body aches, tonic, , expelling tape worm');";         db.execsql(sql);     }      public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         db.execsql("drop table if exists " + table);         oncreate(db);     } }  /**  * upgrade database  */ public void reset() {     dbhelper.onupgrade(this.db, 1, 1); }  /**  * constructor  *   * @param ctx  *            activity context  */ public dbhelper(context ctx) {     dbhelper = new databasehelper(ctx); }  /**  * open database connection  *   * @return database connection  * @throws sqlexception  */ public dbhelper open() throws sqlexception {     db = dbhelper.getwritabledatabase();     return this; }  /**  * close database connection  */ public void close() {     dbhelper.close(); }  public boolean createentry(string name, string benefit) {     contentvalues cv = new contentvalues();     cv.put(k_name, name);     cv.put(k_ben, benefit);     return db.insert(table, null, cv) != -1; }  public boolean updateentry(string name, string benefit, string id) {     contentvalues cv = new contentvalues();     cv.put(k_name, name);     cv.put(k_ben, benefit);     return db.update(table, cv, k_id + " = ?", new string[] { id }) > 0; }  public plantlist getlist() {     plantlist plants = new plantlist();     cursor cur = db.rawquery("select " + k_id + " ," + k_name + " "             + table, null);      if (cur.movetofirst()) {         {             plants.adddata(cur.getstring(cur.getcolumnindex(k_id)),                     cur.getstring(cur.getcolumnindex(k_name)));         } while (cur.movetonext());     }     cur.close();     return plants; }  public plantlist getquery(string query) { //search data     plantlist plants = new plantlist();     cursor cur = db.rawquery("select " + k_id + " ," + k_name + " "             + table + " " + k_name + " '%" + query + "%'", null);      if (cur.movetofirst()) {         {             plants.adddata(cur.getstring(cur.getcolumnindex(k_id)),                     cur.getstring(cur.getcolumnindex(k_name)));         } while (cur.movetonext());     }     cur.close();     return plants; }  public string[] getdetail(string id) {     string data[] = new string[2];     cursor cur = db.query(table, new string[] { k_name, k_ben }, k_id + "="             + id, null, null, null, null);      if (cur.movetofirst()) {         data[0] = cur.getstring(cur.getcolumnindex(k_name));         data[1] = cur.getstring(cur.getcolumnindex(k_ben));     }     cur.close();     return data; }  public string getname(string id) {     string name = null;     cursor cur = db.query(table, new string[] { k_name }, k_id + "=" + id,             null, null, null, null);      if (cur.movetofirst()) {         name = cur.getstring(cur.getcolumnindex(k_name));     }     cur.close();     return name; }  public boolean deleteentry(string id) {     return db.delete(table, k_id + " = ?", new string[] { id }) > 0; } 

}

yes can use same database sqlite stores text data unicode, using unicode encoding specified when database created. database driver takes care return data unicode string in encoding used language/platform.

internally sqlite encodes strings either in utf-8 or utf-16 (there per-database option), since converts them needed (to 1 or other comparison , to/from java.lang.string in api), don't need care.

in database table can add different columns language strings different languages , fetch data particular column only.

on app can provide option user change language. @ time can change column according chosen language , add/edit action on column only.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -