Time localization in Jod - getAsText (Locale ..) does not work correctly with some locales

getAsText() It is supposed to print a localized version according to the Locale device:

If the locale en, for example, is OK:

DateTime dt = new DateTime();
System.out.println(dt.dayOfWeek().getAsText()); 
| Tuesday

but if, for example, you change the system language to Hebrew, it is broken:

System.out.println(dt.dayOfWeek().getAsText()); 
| 3        ( <-- supposed to be "יום שלישי")

If you redefine the device locale, still some locales do not seem to work:

DateTime dt = new DateTime();
System.out.println(dt.dayOfWeek().getAsText(Locale.FRENCH)); // prints "mardi" = OK
System.out.println(dt.dayOfWeek().getAsText(new Locale("iw"))); // prints "3"
| mardi
| 3        ( <-- supposed to be "יום שלישי")

When changing the language standard of the system to iw, this code prints correctly, which means that the translation is available somewhere:

System.out.println(DateUtils.formatDateTime(this, dt, DateUtils.FORMAT_SHOW_WEEKDAY)); 
| יום שלישי

Make sure the locale is accessible:

Locale iw = new Locale("iw");
System.out.println(iw.getDisplayName() + " " + iw.toString()); // prints Hebrew iw == OK
| Hebrew iw

Any advice on how to fix this and make sure the joda getAsText / getAsShortText time will be localized? (Or how to add my translations?)

update 1

In one direction that I am trying to solve this problem, I need to add the missing translations manually.

SimpleDateFormat / , , get set DateFormatSymbols. , .

"", , ...

DateFormatSymbols dfs = DateTimeUtils.getDateFormatSymbols(iw); // << joda method
dfs.setWeekdays(new String[] { "ראשון", "שני", "שלישי", "רביעי", "חמישי","שישי", "שבת" });

, DateFormatSymbols ?

2

Joda , .
java.text.DateFormatSymbols(Locale). -,

libcore.icu.LocaleData.get(locale);

. , , , Android .

: Joda - Android. ( . 11). - .

+4

All Articles