android - How can I show a string resource in a language and store it in other? -


i have spinner showing different options string array. selected string stored database later purposes. example, spinner shows items when in english (values-en):

<string name="none">n - none</string> <string name="month">m - once month or less</string> <string name="oweek">w - once week</string> 

the user selects 1 , string stored in database.

the problem when different locale applied. example, in spanish (values-es) have following options:

<string name="none">n - ninguno</string> <string name="month">m - una vez al mes o menos</string> <string name="oweek">w - una vez la semana</string> 

and when user selects one, string stored in spanish database. need store them in english. basically, app needs show option "n - ninguno" , store "n - none".

is there way id of selected string , store value other locale? or other solution?

as see have 2 options.

  • create column save name , actual string.

  • have default language stored in db.

i go first one, if want implement having strings in english in database , check them current language accordingly:

to string different locale, can use function.

private string getstringlocale(int resource_id, locale new_locale){     resources res = getresources();     configuration conf = res.getconfiguration();      //saving locale can restore later     locale savedlocale = conf.locale;      //set new locale depending on parameters getting     conf.locale = new_locale;     res.updateconfiguration(conf, null);      //saving string     string str = res.getstring(resource_id);      //restoring original locale     conf.locale = savedlocale;     res.updateconfiguration(conf, null);      return str; } 

and use this:

log.d("localespanish", getstringlocale(r.string.app_name, new locale("es"))); log.d("localeenglish", getstringlocale(r.string.app_name, new locale("en"))); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -