title: java Locale.Builder setExtension(Locale.UNICODE_LOCALE_EXTENSION
body: <p>I have been trying to get Java to convert numbers according to their locales.
  Came across <a href="https://stackoverflow.com/questions/29154887/setting-arabic-numbering-system-locale-doesnt-show-arabic-numbers">this post</a> which helped in a big way since pre understanding this I had devised own methods to convert numbers to specific locales (as per other confusion discussions about this topic)</p>
  
  <p>So assuming I have :</p>
  
  <pre><code>Locale arabicLocale = new Locale.Builder().setLanguage("ar").setRegion("SA")
   .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-arab").build();
  
  Locale thaiLocale = new Locale.Builder().setLanguage("th").setRegion("TH")
   .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-thai").build();
  
  Locale hinduLocale = new Locale.Builder().setLanguage("hi").setRegion("IN")
   .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-hindu").build();
  
  DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(arabicLocale);
  NumberFormat numberFormat = NumberFormat.getNumberInstance(arabicLocale);
  println" Arabic ${numberFormat.format(123.22)}"
  
  dfs = DecimalFormatSymbols.getInstance(thaiLocale);
  numberFormat = NumberFormat.getNumberInstance(thaiLocale);
  println" Thai ${numberFormat.format(123.22)}"
  
  dfs = DecimalFormatSymbols.getInstance(hinduLocale);
  numberFormat = NumberFormat.getNumberInstance(hinduLocale);
  println" Hindu ${numberFormat.format(123.22)}"
  </code></pre>
  
  <p>This produces the following output </p>
  
  <pre><code> Arabic ١٢٣٫٢٢
   Thai ๑๒๓.๒๒
   Hindu १२३.२२
  </code></pre>
  
  <p>The purpose of this post was to try to identify how I can look up or get the code itself to point to the right <code>Locale.UNICODE_LOCALE_EXTENSION</code> since the th and hindu stuff was just guess work from my end and I am having troubles understanding how I can do the same for Hebrew Chinese Japanese. Although I think Chinese and Japanese possibly use arabic number system I may be wrong on this.</p>
  
  <p>Anyhow any help / pointers on how I can either auto capture this bit of data or standards as in a page which has all the definitions which i can make an enum out of would be of great help</p>
  
  <p>I was digging deeper into <code>LocaleExtensions</code></p>
  
  <pre><code>static {
          CALENDAR_JAPANESE = new LocaleExtensions("u-ca-japanese", Character.valueOf('u'), UnicodeLocaleExtension.CA_JAPANESE);
          NUMBER_THAI = new LocaleExtensions("u-nu-thai", Character.valueOf('u'), UnicodeLocaleExtension.NU_THAI);
      }
  </code></pre>
  
  <p>So this now makes more sense <code>nu-language</code> = number <code>ca-language</code> = calendar </p>
  
  <p>But when running:</p>
  
  <pre><code>Locale japLocale = new Locale.Builder().setLanguage("ja").setRegion("JP")
                      .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-japanese").build();
  </code></pre>
  
  <p>I get English numbers. </p>
  
  <p>According to original question, the link 
  <a href="https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry" rel="nofollow noreferrer">https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry</a> </p>
  
  <p>For hebrew</p>
  
  <pre><code>Type: language
  Subtag: he
  Description: Hebrew
  Added: 2005-10-16
  Suppress-Script: Hebr
  </code></pre>
  
  <p>But when attempting below:</p>
  
  <pre><code>Locale hebrewLocale = new Locale.Builder().setLanguage("he").setRegion("IL")
                      .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-hebr").build();
  </code></pre>
  
  <p>I get <code>123.22</code></p>
  
  <p>To answer my own question you can build an enum from here <a href="http://www.oracle.com/technetwork/java/javase/java8locales-2095355.html" rel="nofollow noreferrer">http://www.oracle.com/technetwork/java/javase/java8locales-2095355.html</a></p>
  
  <pre><code>Greek (el) Greece (GR) (Grek)  el-GR
  Hebrew (iw) Israel (IL) (Hebr) iw-IL
  </code></pre>
  
  <p>So in short  </p>
  
  <p>for Greece take last field <code>el-GR</code> unicodeEXtension=<code>-u</code> number=<code>-nu</code> and one from last in lower case <code>-hebr</code> giving you <code>'el-GR-u-nu-grek'</code> for greece or same for hebrew <code>'iw-IL-u-n-hebr'</code></p>
  
  <pre><code> Locale locale = new Locale.Builder().setLanguageTag('el-GR-u-nu-grek').build();
  </code></pre>
  
  <p>Should print out greek numbers but I see English numbers it works for some countries but not others.</p>