Do you plan to support Region Override through Unicode Locale Extension:
Unicode Locale extensions seem to be managed internally.
const custom = new Intl.Locale('en-US-u-rg-gbzzzz-hc-h24');
console.log(custom.toString()); // en-US-u-rg-gbzzzz-hc-h24
The hour cycle and region override extensions are inverted from the toString method.
So, I guess the internal implementation holds all Unicode Locale Extensions but the region override is not take into account to format number, date and so on.
const locale = new Intl.Locale('en-US-u-rg-gbzzzz');
console.log(locale.toString()); // OK: en-US-u-rg-gbzzzz
console.log(locale.language); // OK: en
console.log(locale.region); // OK: US
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log('US: ' + new Intl.DateTimeFormat('en-US').format(date)); // OK: 12/20/2012
console.log('GB: ' + new Intl.DateTimeFormat('en-GB').format(date)); // OK: 20/12/2012
console.log('GB w/ Region Override: ' + new Intl.DateTimeFormat(locale).format(date)); // KO: 12/20/2012 -> should display 20/12/2012
According to the spec, the region is used as default for:
- currency
- calendar
- week data
- time cycle
- measurement system
- unit preferences
- number format
- currency format
- date/time format
Java 10 supports region override as expected:
import java.text.DateFormat;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Currency;
import java.util.Locale;
class Main {
public static void main(String[] args) {
Locale locale = Locale.forLanguageTag("en-US-u-rg-gbzzzz");
System.out.println(locale.getLanguage());
System.out.println(locale.getCountry());
LocalDate date = LocalDate.of(2012, Month.NOVEMBER, 20);
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
System.out.println("GB: " + date.format(dtf.localizedBy(Locale.forLanguageTag("en-US")))); // OK: 12/20/12
System.out.println("GB: " + date.format(dtf.localizedBy(Locale.forLanguageTag("en-GB")))); // OK: 20/12/2012
System.out.println("GB w/ Region Override: " + date.format(dtf.localizedBy(locale))); // OK: 20/12/2012
}
}
Related issues:
Do you plan to support Region Override through Unicode Locale Extension:
Unicode Locale extensions seem to be managed internally.
The hour cycle and region override extensions are inverted from the toString method.
So, I guess the internal implementation holds all Unicode Locale Extensions but the region override is not take into account to format number, date and so on.
According to the spec, the region is used as default for:
Java 10 supports region override as expected:
Related issues: