0

How do you format duration in android? I want to show 3 duration choices to the user (to setup a reminder). The choices are "15 Minutes", "30 Minutes" and "45 Minutes". The requirement is that this should be as per locale (language) of the user. The app cannot use the default locale of the mobile but needs to use a locale set on the server. I am able to retrieve locale values and create a Locale object properly from the server settings but how do I show the 3 duration options so that for example "30 Minutes" will show up as its Russian equivalent string when I provide the Russian locale

  • http://stackoverflow.com/questions/9475589/how-to-get-string-from-different-locales-in-android – Gary Bak Aug 22 '16 at 18:34
  • Gary, the accepted answer there talks about ResourceBundle - not relevant to Android Resources. This question is specific to Android. – Chandra Shekar Aug 23 '16 at 13:52
  • The accepted answer also has 5 down votes, look at the second answer with the higher rating. – Gary Bak Aug 23 '16 at 14:25
  • I did see the answer below. It starts with "If you have various res folders for different locales" which is not an option for me, as the locale in my case comes from the server and I do not have any control on what new languages will be added in future. That answer does 'Resources res = getResources();' which I think gives you your own resources and not the android internal R. – Chandra Shekar Aug 23 '16 at 14:47

1 Answers1

0

You'll want to have those strings be in your strings.xml file and then provide different versions of the strings.xml for each language your app supports.

See https://developer.android.com/guide/topics/resources/localization.html

dweebo
  • 3,222
  • 1
  • 17
  • 19
  • Since locale info comes from server, I do not have control on what new languages are supported in future. So this is not an option. I know that android internal R has strings for the word "Minutes" in different languages that I may be able to use. But I could not find a way to get String values for my supplied locale. I can only get the string for the device default locale. Can anyone help get Android internal R strings for a given locale (not the device default locale)? – Chandra Shekar Aug 23 '16 at 13:42
  • I would still rather handle it myself but you could look at the source code for https://developer.android.com/reference/android/text/format/DateUtils.html class and probably find what you want there, for example com.android.internal.R.plurals.in_num_minutes; – dweebo Aug 23 '16 at 17:53