[SOLVED] How to get locales?

thumbnail
Mirto Silvio Busico, modified 7 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts

Hi all,

I'm trying to get the list of available locales in a portlet.

using a code similar to https://www.programcreek.com/java-api-examples/index.php?api=com.liferay.portal.kernel.util.LocaleUtil example 4, I put in my portlet:

Locale[] locales = LanguageUtil.getAvailableLocales();

But I receive the compilation error:

Type mismatch: cannot convert from Set<Locale> to Locale[]

What I'm doing wrong?

(I'm on Liferay 7.1 CE GA 1)

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Mirto Silvio Busico:
Locale[] locales = LanguageUtil.getAvailableLocales();

But I receive the compilation error:

Type mismatch: cannot convert from Set<Locale> to Locale[]

What I'm doing wrong?

(I'm on Liferay 7.1 CE GA 1)

In Liferay 6.2, LanguageUtil.getAvailableLocales returns an array, while in Liferay 7.1, LanguageUtil.getAvailableLocales returns a Set. You'll need to adapt the code sample accordingly.

Set<Locale> locales = LanguageUtil.getAvailableLocales();
thumbnail
Mirto Silvio Busico, modified 7 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts

Thanks,

it worked.