mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8204603: Short week days, NaN value and timezone name are inconsistent between CLDR and Java in zh_CN, zh_TW locales
Handled languageALiases for supported locales of CLDR. Reviewed-by: naoto
This commit is contained in:
parent
38fb1c72d8
commit
19fd830161
5 changed files with 222 additions and 15 deletions
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.util.cldr;
|
||||
|
||||
import static sun.util.locale.provider.LocaleProviderAdapter.Type;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import sun.util.locale.provider.AvailableLanguageTags;
|
||||
import sun.util.locale.provider.CalendarNameProviderImpl;
|
||||
import sun.util.locale.provider.LocaleProviderAdapter;
|
||||
|
||||
|
||||
public class CLDRCalendarNameProviderImpl extends CalendarNameProviderImpl implements AvailableLanguageTags{
|
||||
|
||||
public CLDRCalendarNameProviderImpl(Type type, Set<String> langtags) {
|
||||
super(type, langtags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupportedLocale(Locale locale) {
|
||||
if (Locale.ROOT.equals(locale)) {
|
||||
return true;
|
||||
}
|
||||
String calendarType = null;
|
||||
if (locale.hasExtensions()) {
|
||||
calendarType = locale.getUnicodeLocaleType("ca");
|
||||
locale = locale.stripExtensions();
|
||||
}
|
||||
if (calendarType != null) {
|
||||
switch (calendarType) {
|
||||
case "buddhist":
|
||||
case "japanese":
|
||||
case "gregory":
|
||||
case "islamic":
|
||||
case "roc":
|
||||
break;
|
||||
default:
|
||||
// Unknown calendar type
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return LocaleProviderAdapter.forType(Type.CLDR).isSupportedProviderLocale(locale, langtags);
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@ import java.util.Set;
|
|||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.spi.CalendarDataProvider;
|
||||
import java.util.spi.CalendarNameProvider;
|
||||
import java.util.spi.TimeZoneNameProvider;
|
||||
import sun.util.locale.provider.JRELocaleProviderAdapter;
|
||||
import sun.util.locale.provider.LocaleDataMetaInfo;
|
||||
|
@ -132,6 +133,24 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
return calendarDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalendarNameProvider getCalendarNameProvider() {
|
||||
if (calendarNameProvider == null) {
|
||||
CalendarNameProvider provider = AccessController.doPrivileged(
|
||||
(PrivilegedAction<CalendarNameProvider>) ()
|
||||
-> new CLDRCalendarNameProviderImpl(
|
||||
getAdapterType(),
|
||||
getLanguageTagSet("FormatData")));
|
||||
|
||||
synchronized (this) {
|
||||
if (calendarNameProvider == null) {
|
||||
calendarNameProvider = provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
return calendarNameProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollatorProvider getCollatorProvider() {
|
||||
return null;
|
||||
|
@ -166,7 +185,7 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
return locs;
|
||||
}
|
||||
|
||||
private Locale applyAliases(Locale loc) {
|
||||
private static Locale applyAliases(Locale loc) {
|
||||
if (langAliasesMap.isEmpty()) {
|
||||
langAliasesMap = baseMetaInfo.getLanguageAliasMap();
|
||||
}
|
||||
|
@ -264,19 +283,18 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* This method returns equivalent CLDR supported locale for zh-HK,
|
||||
* no, no-NO locales so that COMPAT locales do not precede
|
||||
* those locales during ResourceBundle search path.
|
||||
* This method returns equivalent CLDR supported locale
|
||||
* for no, no-NO locales so that COMPAT locales do not precede
|
||||
* those locales during ResourceBundle search path, also if an alias exists for a locale,
|
||||
* it returns equivalent locale, e.g for zh_HK it returns zh_Hant-HK.
|
||||
*/
|
||||
private static Locale getEquivalentLoc(Locale locale) {
|
||||
switch (locale.toString()) {
|
||||
case "zh_HK":
|
||||
return Locale.forLanguageTag("zh-Hant-HK");
|
||||
case "no":
|
||||
case "no_NO":
|
||||
return Locale.forLanguageTag("nb");
|
||||
}
|
||||
return locale;
|
||||
return applyAliases(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,8 +42,8 @@ import sun.util.calendar.Era;
|
|||
* @author Naoto Sato
|
||||
*/
|
||||
public class CalendarNameProviderImpl extends CalendarNameProvider implements AvailableLanguageTags {
|
||||
private final LocaleProviderAdapter.Type type;
|
||||
private final Set<String> langtags;
|
||||
protected final LocaleProviderAdapter.Type type;
|
||||
protected final Set<String> langtags;
|
||||
|
||||
public CalendarNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
|
||||
this.type = type;
|
||||
|
@ -248,11 +248,8 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
|
|||
if (langtags.contains(locale.toLanguageTag())) {
|
||||
return true;
|
||||
}
|
||||
if (type == LocaleProviderAdapter.Type.JRE) {
|
||||
String oldname = locale.toString().replace('_', '-');
|
||||
return langtags.contains(oldname);
|
||||
}
|
||||
return false;
|
||||
String oldname = locale.toString().replace('_', '-');
|
||||
return langtags.contains(oldname);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -131,7 +131,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
|
|||
private volatile LocaleNameProvider localeNameProvider;
|
||||
protected volatile TimeZoneNameProvider timeZoneNameProvider;
|
||||
protected volatile CalendarDataProvider calendarDataProvider;
|
||||
private volatile CalendarNameProvider calendarNameProvider;
|
||||
protected volatile CalendarNameProvider calendarNameProvider;
|
||||
|
||||
private volatile CalendarProvider calendarProvider;
|
||||
private volatile JavaTimeDateTimePatternProvider javaTimeDateTimePatternProvider;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue