mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8179071: Month value is inconsistent between CLDR and Java in some locales
Handled Language aliases from CLDR SupplementalMetaData Reviewed-by: naoto
This commit is contained in:
parent
9037ee0ef1
commit
a01b2f3b73
9 changed files with 185 additions and 13 deletions
|
@ -64,8 +64,14 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
|
||||
// parent locales map
|
||||
private static volatile Map<Locale, Locale> parentLocalesMap;
|
||||
// language aliases map
|
||||
private static volatile Map<String,String> langAliasesMap;
|
||||
// cache to hold locale to locale mapping for language aliases.
|
||||
private static final Map<Locale, Locale> langAliasesCache;
|
||||
static {
|
||||
parentLocalesMap = new ConcurrentHashMap<>();
|
||||
langAliasesMap = new ConcurrentHashMap<>();
|
||||
langAliasesCache = new ConcurrentHashMap<>();
|
||||
// Assuming these locales do NOT have irregular parent locales.
|
||||
parentLocalesMap.put(Locale.ROOT, Locale.ROOT);
|
||||
parentLocalesMap.put(Locale.ENGLISH, Locale.ENGLISH);
|
||||
|
@ -160,6 +166,22 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
return locs;
|
||||
}
|
||||
|
||||
private Locale applyAliases(Locale loc) {
|
||||
if (langAliasesMap.isEmpty()) {
|
||||
langAliasesMap = baseMetaInfo.getLanguageAliasMap();
|
||||
}
|
||||
Locale locale = langAliasesCache.get(loc);
|
||||
if (locale == null) {
|
||||
String locTag = loc.toLanguageTag();
|
||||
Locale aliasLocale = langAliasesMap.containsKey(locTag)
|
||||
? Locale.forLanguageTag(langAliasesMap.get(locTag)) : loc;
|
||||
langAliasesCache.putIfAbsent(loc, aliasLocale);
|
||||
return aliasLocale;
|
||||
} else {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> createLanguageTagSet(String category) {
|
||||
// Assume all categories support the same set as AvailableLocales
|
||||
|
@ -194,7 +216,7 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
// Implementation of ResourceBundleBasedAdapter
|
||||
@Override
|
||||
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
|
||||
List<Locale> candidates = super.getCandidateLocales(baseName, locale);
|
||||
List<Locale> candidates = super.getCandidateLocales(baseName, applyAliases(locale));
|
||||
return applyParentLocales(baseName, candidates);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -58,4 +58,13 @@ public interface LocaleDataMetaInfo {
|
|||
default public Map<String, String> tzCanonicalIDs() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map for language aliases which specifies mapping from source language
|
||||
* to from which it should be replaced.
|
||||
* @return map of source language to replacement language, separated by a space.
|
||||
*/
|
||||
default public Map<String, String> getLanguageAliasMap(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue