Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Locale to get Sinhala/Sri Lankan Translation

I have JSF UI application and I want to display translated country names.

I am getting country names with Java Locale. But unable to get my transalation requirement. With Java 1.6 Locale provided only 44 Unique countries.

Locale[] localeArray =  Locale.getAvailableLocales();
System.out.println("localeArray---->"+localeArray.length);  

for (Locale locale : localeArray) {     
    counter++;
    System.out.print("locale-->"+locale+"-------");
    System.out.print("locale getISO3Language-->"+locale.getISO3Language());
    System.out.println("-----locale.getDisplayCountry(locale)--->"+locale.getDisplayCountry(locale));
    System.out.println("-----locale.getDisplayCountry()--->"+locale.getDisplayCountry());
    System.out.println("-----locale.getCountry()--->"+locale.getCountry());

    System.out.println("----------------------------------------------------"+counter);
}

Please let us know how to perform my requirement ?

Oracle documentation provide link.

Is there any available Libraries other than Java to perform powerful locale specific requirement?

like image 391
Ruchira Kariyawasam Avatar asked Oct 04 '13 18:10

Ruchira Kariyawasam


1 Answers

As I already suggested in the comment, you should have tried ICU for the purpose of getting native names of Locales. The simplest possible usage example:

ULocale locale = ULocale.forLanguageTag("si-LK");
System.out.println(locale.getDisplayName(locale));

This prints:

සිංහල (ශ්‍රී ලංකාව)

I assume that the answer is correct. To convert this into the form suitable for UIViewRoot, you only need to call toLocale() method:

Locale javaLocale = locale.toLocale();

That's it.

like image 141
Paweł Dyda Avatar answered Oct 13 '22 12:10

Paweł Dyda