mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8263202: Update Hebrew/Indonesian/Yiddish ISO 639 language codes to current
Reviewed-by: joehw
This commit is contained in:
parent
9c346a1ec7
commit
a4c46e1e4f
35 changed files with 345 additions and 146 deletions
|
@ -34,6 +34,7 @@ package sun.util.locale;
|
|||
|
||||
import jdk.internal.misc.CDS;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.StringJoiner;
|
||||
|
@ -98,6 +99,13 @@ public final class BaseLocale {
|
|||
|
||||
private volatile int hash;
|
||||
|
||||
/**
|
||||
* Boolean for the old ISO language code compatibility.
|
||||
*/
|
||||
private static final boolean OLD_ISO_CODES = GetPropertyAction.privilegedGetProperties()
|
||||
.getProperty("java.locale.useOldISOCodes", "false")
|
||||
.equalsIgnoreCase("true");
|
||||
|
||||
// This method must be called with normalize = false only when creating the
|
||||
// Locale.* constants and non-normalized BaseLocale$Keys used for lookup.
|
||||
private BaseLocale(String language, String script, String region, String variant,
|
||||
|
@ -153,19 +161,22 @@ public final class BaseLocale {
|
|||
|
||||
// JDK uses deprecated ISO639.1 language codes for he, yi and id
|
||||
if (!language.isEmpty()) {
|
||||
if (language.equals("he")) {
|
||||
language = "iw";
|
||||
} else if (language.equals("yi")) {
|
||||
language = "ji";
|
||||
} else if (language.equals("id")) {
|
||||
language = "in";
|
||||
}
|
||||
language = convertOldISOCodes(language);
|
||||
}
|
||||
|
||||
Key key = new Key(language, script, region, variant, false);
|
||||
return Cache.CACHE.get(key);
|
||||
}
|
||||
|
||||
public static String convertOldISOCodes(String language) {
|
||||
return switch (language) {
|
||||
case "he", "iw" -> OLD_ISO_CODES ? "iw" : "he";
|
||||
case "id", "in" -> OLD_ISO_CODES ? "in" : "id";
|
||||
case "yi", "ji" -> OLD_ISO_CODES ? "ji" : "yi";
|
||||
default -> language;
|
||||
};
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, 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
|
||||
|
@ -208,6 +208,17 @@ public abstract class Bundles {
|
|||
Class<ResourceBundle> bundleClass = (Class<ResourceBundle>) c;
|
||||
bundle = bundleAccess.newResourceBundle(bundleClass);
|
||||
}
|
||||
if (bundle == null) {
|
||||
var otherBundleName = toOtherBundleName(baseName, bundleName, targetLocale);
|
||||
if (!bundleName.equals(otherBundleName)) {
|
||||
c = Class.forName(Bundles.class.getModule(), otherBundleName);
|
||||
if (c != null && ResourceBundle.class.isAssignableFrom(c)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<ResourceBundle> bundleClass = (Class<ResourceBundle>) c;
|
||||
bundle = bundleAccess.newResourceBundle(bundleClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
cacheKey.setCause(e);
|
||||
}
|
||||
|
@ -345,27 +356,55 @@ public abstract class Bundles {
|
|||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the other bundle name for languages that have changed,
|
||||
* i.e. "he", "id", and "yi"
|
||||
*
|
||||
* @param baseName ResourceBundle base name
|
||||
* @param bundleName ResourceBundle bundle name
|
||||
* @param locale locale
|
||||
* @return the other bundle name, or the same name for non-legacy ISO languages
|
||||
*/
|
||||
public static String toOtherBundleName(String baseName, String bundleName, Locale locale) {
|
||||
var simpleName= baseName.substring(baseName.lastIndexOf('.') + 1);
|
||||
var suffix = bundleName.substring(bundleName.lastIndexOf(simpleName) + simpleName.length());
|
||||
var otherSuffix = switch(locale.getLanguage()) {
|
||||
case "he" -> suffix.replaceFirst("^_he(_.*)?$", "_iw$1");
|
||||
case "id" -> suffix.replaceFirst("^_id(_.*)?$", "_in$1");
|
||||
case "yi" -> suffix.replaceFirst("^_yi(_.*)?$", "_ji$1");
|
||||
case "iw" -> suffix.replaceFirst("^_iw(_.*)?$", "_he$1");
|
||||
case "in" -> suffix.replaceFirst("^_in(_.*)?$", "_id$1");
|
||||
case "ji" -> suffix.replaceFirst("^_ji(_.*)?$", "_yi$1");
|
||||
default -> suffix;
|
||||
};
|
||||
|
||||
if (suffix.equals(otherSuffix)) {
|
||||
return bundleName;
|
||||
} else {
|
||||
return bundleName.substring(0, bundleName.lastIndexOf(suffix)) + otherSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Strategy interface defines methods that are called by Bundles.of during
|
||||
* the resource bundle loading process.
|
||||
*/
|
||||
public static interface Strategy {
|
||||
public interface Strategy {
|
||||
/**
|
||||
* Returns a list of locales to be looked up for bundle loading.
|
||||
*/
|
||||
public List<Locale> getCandidateLocales(String baseName, Locale locale);
|
||||
List<Locale> getCandidateLocales(String baseName, Locale locale);
|
||||
|
||||
/**
|
||||
* Returns the bundle name for the given baseName and locale.
|
||||
*/
|
||||
public String toBundleName(String baseName, Locale locale);
|
||||
String toBundleName(String baseName, Locale locale);
|
||||
|
||||
/**
|
||||
* Returns the service provider type for the given baseName
|
||||
* and locale, or null if no service providers should be used.
|
||||
*/
|
||||
public Class<? extends ResourceBundleProvider> getResourceBundleProviderType(String baseName,
|
||||
Class<? extends ResourceBundleProvider> getResourceBundleProviderType(String baseName,
|
||||
Locale locale);
|
||||
}
|
||||
|
||||
|
@ -374,7 +413,7 @@ public abstract class Bundles {
|
|||
* BundleReference.
|
||||
*/
|
||||
private static interface CacheKeyReference {
|
||||
public CacheKey getCacheKey();
|
||||
CacheKey getCacheKey();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, 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
|
||||
|
@ -216,6 +216,13 @@ public class LocaleData {
|
|||
protected String toBundleName(String baseName, Locale locale) {
|
||||
return LocaleDataStrategy.INSTANCE.toBundleName(baseName, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the other bundle name for legacy ISO 639 languages.
|
||||
*/
|
||||
protected String toOtherBundleName(String baseName, String bundleName, Locale locale) {
|
||||
return Bundles.toOtherBundleName(baseName, bundleName, locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue