alex.b
alex.b

Reputation: 194

Can't get armenian months names

I want to print armenian month names but it doesn't work. This is my code:

Locale loc = new Locale("hy");
Calendar cal = Calendar.getInstance(loc);
System.out.println(cal.getDisplayName(Calendar.MONTH, Calendar.LONG_STANDALONE, loc));

I have tried many others abbreviation like "hye" or "arm", but nothing works. Other language such as russian "ru" work fine. I have no idee what i'm doing wrong

Upvotes: 3

Views: 595

Answers (5)

Tom Wellbrock
Tom Wellbrock

Reputation: 3042

After browsing Oracles Website I've found a list of supported languages and Locale_IDs. As it seems the language you want is not supported by JDK7 Locale.

http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html

Upvotes: 2

Pallavi Sonal
Pallavi Sonal

Reputation: 3901

There was an enhancement in JDK8 wherein the CLDR's XML-based locale data has been incorporated into the JDK 8 release, however it is disabled by default. So, if you run your code with the argument -Djava.locale.providers=CLDR or add the same through the java.locale.providers System.property in your code, hy: Armenian hy_AM: Armenian will be supported.

With JDK 9 enhancements , CLDR locale data is enabled by default. So, the code will run without adding any system property. Hope this helps.

Upvotes: 4

Thomas Fritsch
Thomas Fritsch

Reputation: 10127

With the following code you can print out all supported Calendar locales (sorted by languageTag):

Locale[] locales = Calendar.getAvailableLocales();
Arrays.sort(locales, Comparator.comparing(Locale::toLanguageTag));
for (Locale locale : locales)
    System.out.print(" " + locale.toLanguageTag());

Unfortunately, in my Oracle Java 8, there is no Armenian locale (beginning with "hy") in this list.

ar ar-AE ar-BH ar-DZ ar-EG ar-IQ ar-JO ar-KW ar-LB ar-LY ar-MA ar-OM ar-QA ar-SA ar-SD ar-SY ar-TN ar-YE be be-BY bg bg-BG ca ca-ES cs cs-CZ da da-DK de de-AT de-CH de-DE de-GR de-LU el el-CY el-GR en en-AU en-CA en-GB en-IE en-IN en-MT en-NZ en-PH en-SG en-US en-ZA es es-AR es-BO es-CL es-CO es-CR es-CU es-DO es-EC es-ES es-GT es-HN es-MX es-NI es-PA es-PE es-PR es-PY es-SV es-US es-UY es-VE et et-EE fi fi-FI fr fr-BE fr-CA fr-CH fr-FR fr-LU ga ga-IE he he-IL hi hi-IN hr hr-HR hu hu-HU id id-ID is is-IS it it-CH it-IT ja ja-JP ja-JP-u-ca-japanese-x-lvariant-JP ko ko-KR lt lt-LT lv lv-LV mk mk-MK ms ms-MY mt mt-MT nl nl-BE nl-NL nn-NO no no-NO pl pl-PL pt pt-BR pt-PT ro ro-RO ru ru-RU sk sk-SK sl sl-SI sq sq-AL sr sr-BA sr-CS sr-Latn sr-Latn-BA sr-Latn-ME sr-Latn-RS sr-ME sr-RS sv sv-SE th th-TH th-TH-u-nu-thai-x-lvariant-TH tr tr-TR uk uk-UA und vi vi-VN zh zh-CN zh-HK zh-SG zh-TW

Edit:

With Oracle Java 8 and additional option -Djava.locale.providers=CLDR as suggested in Pallavi's answer the resulting list contains the Armenian locale ("hy"):

aa af af-NA agq ak am ar ar-AE ar-BH ar-DZ ar-EG ar-IQ ar-JO ar-KW ar-LB ar-LY ar-MA ar-OM ar-QA ar-SA ar-SD ar-SY ar-TN ar-YE as asa az az-Cyrl bas be be-BY bem bez bg bg-BG bm bn bn-IN bo br brx bs byn ca ca-ES cgg chr cs cs-CZ cy da da-DK dav de de-AT de-CH de-DE de-GR de-LI de-LU dje dua dyo dz ebu ee el el-CY el-GR en en-AU en-BE en-BW en-BZ en-CA en-Dsrt en-GB en-HK en-IE en-IN en-JM en-MT en-NA en-NZ en-PH en-PK en-SG en-TT en-US en-US-POSIX en-ZA en-ZW eo es es-419 es-AR es-BO es-CL es-CO es-CR es-CU es-DO es-EC es-ES es-GQ es-GT es-HN es-MX es-NI es-PA es-PE es-PR es-PY es-SV es-US es-UY es-VE et et-EE eu ewo fa fa-AF ff fi fi-FI fil fo fr fr-BE fr-CA fr-CH fr-FR fr-LU fur ga ga-IE gd gl gsw gu guz gv ha haw he he-IL hi hi-IN hr hr-HR hu hu-HU hy ia id id-ID ig ii is is-IS it it-CH it-IT ja ja-JP ja-JP-u-ca-japanese-x-lvariant-JP jmc ka kab kam kde kea khq ki kk kl kln km kn ko ko-KR kok ksb ksf ksh kw lag lg ln lo lt lt-LT lu luo luy lv lv-LV mas mer mfe mg mgh mk mk-MK ml mr ms ms-BN ms-MY mt mt-MT mua my naq nb nd ne ne-IN nl nl-BE nl-NL nmg nn nn-NO no no-NO nr nso nus nyn om or pa pa-Arab pl pl-PL ps pt pt-BR pt-PT rm rn ro ro-RO rof ru ru-RU ru-UA rw rwk saq sbp se seh ses sg shi shi-Tfng si sk sk-SK sl sl-SI sn so sq sq-AL sr sr-BA sr-CS sr-Cyrl-BA sr-Latn sr-Latn-BA sr-Latn-ME sr-Latn-RS sr-ME sr-RS ss ssy st sv sv-FI sv-SE sw sw-KE swc ta te teo th th-TH th-TH-u-nu-thai-x-lvariant-TH ti ti-ER tig tn to tr tr-TR ts twq tzm uk uk-UA und ur ur-IN uz uz-Arab uz-Latn vai vai-Latn ve vi vi-VN vun wae wal xh xog yav yo zh zh-CN zh-HK zh-Hans-HK zh-Hans-MO zh-Hans-SG zh-Hant zh-Hant-HK zh-Hant-MO zh-SG zh-TW zu

Upvotes: 1

Meno Hochschild
Meno Hochschild

Reputation: 44061

The answer of @Pallavi is correct for Java-8 and Java-9.

However, if you are on Java-7, then you could set up your own DateFormatSymbolsProvider specialized for Armenian language via the service loader mechanism.

You will need a file within META-INF/services-subdirectory like with exactly this name:

META-INF/services/java.text.spi.DateFormatSymbolsProvider

And the content of this file should contain a line like this (please adjust the names to your real implementation class of service provider mentioned above):

mypackage.MyImplementationOfDateFormatSymbolsProvider

As soon as you have created an appropriate jar-library with this META-INF-substructure included, the new service provider for Armenian will be queried, too.

About the required text resources, I have imported the CLDR-v30-resources into my own library Time4J. Maybe you can take profit from the resource file for Armenian (also containing standalone-forms for month names) and use a part of the content for your own service provider.

Upvotes: 1

Thecave3
Thecave3

Reputation: 797

This language is not supported, but you can create your own locale by following this guide.

This is the javadoc of Locale.Builder

https://docs.oracle.com/javase/8/docs/api/java/util/Locale.Builder.html

Upvotes: 1

Related Questions