Enabling CLDR Locale Data in Java and Groovy

By | 2016-06-30

Enabling CLDR Locale Data in Java and Groovy

Duke jdk8 1 Today a colleague asked whether I could provide a list of localized country names for Portuguese. I know that the CLDR database contains all that great localization goodness, but I didn’t have the time to dig through the raw data. Still, I wanted to help, and I know that the Java platform has included CLDR data since 1.8. I decided to create a short Groovy language script to retrieve and display the information. Because Groovy runs in the JVM, it also has access to that CLDR information.

The Groovy Script

Here’s the script I came up with. I named it “countries”.

#!/usr/bin/env groovy 
 * Created by joconner on 6/29/16.

supportedLangs = Locale.getISOLanguages();

if (!(this.args.length > 0 && supportedLangs.contains(this.args[0].toLowerCase()))) {
    printf("Usage: countries <lang_code>\n")
    printf("\t<lang_code> must be an ISO lang code. Examples: en, pt, fr, es, ja.\n")
currentLocale = new Locale.Builder().setLanguageTag(this.args[0].toLowerCase()).build()
locales = Locale.getISOCountries()
for(c in locales) {
    targetLocale = new Locale.Builder().setRegion(c).build()
    printf("%s, %s\n", targetLocale.getCountry(), targetLocale.getDisplayCountry(currentLocale))

I won’t go into the script in detail. If you are familiar with Java, you’ve probably seen these classes and methods before. The interesting thing is that the CLDR data is not enabled by default.

Enabling CLDR

For backward compatibility, CLDR locale data is not enabled by default. However, you can enable it by setting a system property on the Java command line. The system property is java.locale.providers. If you set this to the value CLDR, the JRE will use CLDR as the locale data source.

Run the above script like this to get Portuguese (pt) names for all supported ISO countries in the JRE: groovy -Djava.locale.providers=CLDR countries pt

Although this example is written in Groovy, the same system property is available with the Java command line as well. Just run your Java application like this: java -Djava.locale.providers=CLDR

Analyzing Differences

I ran the above script twice, once using CLDR data and once using the default JRE data. For the pt language, I discovered a couple differences in JDK 1.8.0_92:

BQ, Bonaire, Sint Eustatius, and Saba BQ, Bonaire, Sint Eustatius and Saba
SX, Sint Maarten SX, Sint Maarten (Dutch part)

I suspect you’ll find other and perhaps more significant differences for other languages.

Downloading Code

You can git the code for this article from my github account. Enjoy!

16 thoughts on “Enabling CLDR Locale Data in Java and Groovy

  1. Lele

    I don’t even know what to say, this made things so much eaeirs!

  2. http://www./

    That is wonderful!!!! Ms. Stritch has given me inspiration to wear a TIE w/ blazer!!!! Glad you had the pleasure of meeting up with her and a chance to take a snap-shot!

  3. Ai Apps

    Howdy I am so delighted I found your blog, I really found you by accident, while
    I was searching on Yahoo for something else, Nonetheless I am here now and would just
    like to say cheers for a tremendous post and a all round entertaining
    blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and
    also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the superb job.

  4. New Year 2017 Wishes

    I have been exploring for a little for any high quality articles or blog
    posts on this sort of house . Exploring in Yahoo I ultimately
    stumbled upon this website. Studying this info So i’m happy to
    convey that I have an incredibly good uncanny feeling I came upon just what I needed.
    I so much undoubtedly will make certain to do not omit this web site and provides it a look
    on a continuing basis.

  5. vérification tva

    Please let me know if you’re looking for a article author for your site.
    You have some really good articles and I feel I would be a good asset.

    If you ever want to take some of the load off, I’d absolutely love to write some articles for your blog
    in exchange for a link back to mine. Please blast me an email if interested.
    Many thanks!

  6. http://www./

    CATHIRIA:Tienes toda la razón, solo quien sea arrebatado de este planeta, vivo y con cuerpo físico, y llevado a ese lugar donde se celebrarán las bodas del cordero podrá comprobar que la salvación le alcanzó.Los demás se enfrentarán con impotencia y angustia a esa realidad, la gran tribulación, evento que no les acolitará sus justificaciones. FGuttmann

  7. Valencia

    I just added your weblog to my website roll, I
    pray you would take into consideration doing the same.

  8. angkakeluartogel.info

    Hi there, for all time i used to check website posts here in the early
    hours in the morning, because i like to gain knowledge of more and more.

  9. togel rgp

    An outstanding share! I’ve just forwarded this onto a coworker who had
    been doing a little homework on this. And he in fact bought me breakfast due to the fact that I
    discovered it for him… lol. So let me reword this….
    Thank YOU for the meal!! But yeah, thanx for spending the time to discuss this issue here on your web page.

  10. togel

    Unquestionably believe that which you stated.
    Your favourite justification appeared to be on the net the simplest
    factor to be aware of. I say to you, I definitely get annoyed while other folks think about
    worries that they just do not recognize about.
    You managed to hit the nail upon the top and outlined out the entire thing without having side effect , other people could take a signal.
    Will probably be back to get more. Thanks

  11. cheap NFL jerseys

    I relish, lead to I found exactly what I used to be looking for.
    You’ve ended my 4 day long hunt! God Bless you man. Have
    a nice day. Bye
    cheap NFL jerseys

  12. imshirt.info

    Hello to every body, it’s my first pay a visit
    of this weblog; this website consists of amazing and in fact fine
    stuff in favor of visitors.

  13. site

    In the event you read along with youngsters, they’ll get familiar with the letters,
    words and say for example LKG rhymes in English (for kindergarten) could also be used
    not only to teach the rhymes per se, but additionally as a means to teach
    other things like letters, common objects, numbers,
    animals, birds etc.

  14. prolong.tips

    The word used in most translations is discipline or correction.
    But unlike childhood piano lessons this is practice you’ll look
    forward to. Just suppose how quick it is to kind a message for your laptop keyboard,
    it’s much faster than the usage of your cell phone.

  15. buy iphone

    Only wanna remark that you have a very decent internet site, I love
    the design it actually stands out.

Leave a Reply

Your email address will not be published. Required fields are marked *