Saturday 15 September 2012

How to describe duration in Android? -


I am writing a small app and I have to write the period of the game event in i18n. Using the preetytime library for a date, but when I try to use datumytles or pretium, I have problems. For example, I want to say this period is 2 minutes. I need some way of passing the library which supports the I-18N and accepts milliseconds and returns the chairs.

We have the following in Android:

  com.android.internal.R.plurals.duration_minutes  

But I Can not access. Is there any way to use it correctly and not write your own plural for all languages?

Thank you

I'm not sure that you have the Android-DatUtils and PrettyTime-Library On what issue are you talking about? But I'm sure Android-DateUtils does not fully manage the plural rules of different languages ​​(especially Slavic languages ​​or Arabic) because it knows only singular and a plural form that is very easy) For example, see PrettyTime- Regarding the library, if you consider Arabic, the same objection is valid.

My recommendation:

See my library (a new one) R-Library After that you can use this code to process on millisecond input and to create a localized min-string:

  // Input long mills = 1770123; // Create a Duration Period & amp; ClockUnit & gt; Period = period. (Million, clock unit. MILIS); // normalization (round) minute duration = period With (ClockUnit.MINUTES.rounded ()); String s = PrettyTime.of (Locale.ENGLISH). Print (period, textwidth.WIDE); Println (s); // 30 min  

Examples for Korean (Answer to Gaibe Savchen's comment):

  string s = PrettyTime.of (new locale (" ")). Print (duration, textual wide); Println (s); // 30 분 (Korean translation "30 minutes")  

Examples for Arabic (right to left):

  string s = PrettyTime.of ( New locale ("AR")). Print (duration, textual wide); Println (s); This solution currently supports  56 languages ​​ (more than the preetytime-library) and three text width (full, short or narrow). Accurate plural handling is included automatically. Time 4A uses its language resources based on CLDR-data (independent of android). But you are free to override those resources by defining your assets in your property (UTF-8). 

Regarding generalization: I have just shown the version that you described in your question. However, there are several ways to normalize time in Time 4A (J). This will give you more idea how to use that feature.

If you still miss a few languages, just tell me, and I will support it in the next editions of Time 4A. Currently supported (in ISO-639-1-notation):

am ar az be bg bs ca cs da en es from the first person and h Lt LV Mk MS NB NL NL PL RTU R SU SL SL SL SL SL SR SR SV V T T UR UK U UZ VIP (and some country-specific locations, for example ZTH, NGB etc) )


No comments:

Post a Comment