Description
java.util.Locale can represent language and country codes using 2 letters or 3 letters codes. Conversions from 2 to 3 letters codes are performed by the Locale.getISO3Language() and Locale.getISO3Country() methods.
When marshalling an ISO 19139 document, Apache SIS 0.3 uses the 3 letters variant in both cases. However this cause SIS to be unable to unmarshal its own documents, because the java.util.Locale does not recognize 3 letters country codes. Example:
Locale locale = new Locale("en", "GB"); System.out.println(locale.getLanguage()); // Prints "en" System.out.println(locale.getISO3Language()); // Prints "eng" System.out.println(locale.getDisplayLanguage()); // Prints "anglais" on a French system. System.out.println(locale.getCountry()); // Prints "GB" System.out.println(locale.getISO3Country()); // Prints "GBR" System.out.println(locale.getDisplayCountry()); // Prints "Royaume-Uni" on a French system. locale = new Locale("eng", "GBR"); // GBR is the 3 letters code for GB System.out.println(locale.getLanguage()); // Prints "eng" System.out.println(locale.getISO3Language()); // Prints "eng" System.out.println(locale.getDisplayLanguage()); // Prints "anglais" on a French system. System.out.println(locale.getCountry()); // Prints "GBR" System.out.println(locale.getISO3Country()); // MissingResourceException: Couldn't find 3-letter country code for GBR
Note that this behaviour is consistent with java.util.Locale javadoc. Looking at what OGC/ISO does on schemas.opengis.net, we can see that they use:
- 3 letters codes for languages
- 2 letters code for countries
We should align Apache SIS 0.4 on the same practice. This would allow SIS to unmarshal its own documents. However this would not solve the issue when reading a document from an other producer using the 3 letters country codes. For now we hope that those cases are rare...
Note that this JIRA task is about the country code only. Leaving the language codes as 3 letters codes leaves an other issue: while java.util.Locale works fine with them, we did not verified if java.util.ResourceBundle is capable to convert back to 2 letters language codes before to lookup for resources.
Attachments
Issue Links
- relates to
-
SIS-137 <gmd:LocalisedCharacterString> locale shall be a URI
- Open