Skip to content

Commit

Permalink
Backport 00b1eacad6ae2d5ea5afb1de506768e9ab960743
Browse files Browse the repository at this point in the history
  • Loading branch information
GoeLin committed Apr 3, 2024
1 parent 9f6b099 commit 83ef66a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
4 changes: 2 additions & 2 deletions make/data/lsrdata/language-subtag-registry.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File-Date: 2023-03-22
File-Date: 2023-04-13
%%
Type: language
Subtag: aa
Expand Down Expand Up @@ -42986,7 +42986,7 @@ Subtag: ajp
Description: South Levantine Arabic
Added: 2009-07-29
Deprecated: 2023-03-17
Preferred-Value: apc
Preferred-Value: ajp
Prefix: ar
Macrolanguage: ar
%%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, 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
Expand Down Expand Up @@ -40,7 +40,7 @@
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.regex.Pattern;

/**
* This tool reads the IANA Language Subtag Registry data file downloaded from
Expand Down Expand Up @@ -138,10 +138,29 @@ private static void processDeprecatedData(String type,
}
} else { // language, extlang, legacy, and redundant
if (!initialLanguageMap.containsKey(preferred)) {
sb = new StringBuilder(preferred);
sb.append(',');
sb.append(tag);
initialLanguageMap.put(preferred, sb);
// IANA update 4/13 introduced case where a preferred value
// can have a preferred value itself.
// eg: ar-ajp has pref ajp which has pref apc
boolean foundInOther = false;
Pattern pattern = Pattern.compile(","+preferred+"(,|$)");
// Check if current pref exists inside a value for another pref
List<StringBuilder> doublePrefs = initialLanguageMap
.values()
.stream()
.filter(e -> pattern.matcher(e.toString()).find())
.toList();
for (StringBuilder otherPrefVal : doublePrefs) {
otherPrefVal.append(",");
otherPrefVal.append(tag);
foundInOther = true;
}
if (!foundInOther) {
// does not exist in any other pref's values, so add as new entry
sb = new StringBuilder(preferred);
sb.append(',');
sb.append(tag);
initialLanguageMap.put(preferred, sb);
}
} else {
sb = initialLanguageMap.get(preferred);
sb.append(',');
Expand All @@ -158,7 +177,7 @@ private static void generateEquivalentMap() {
// "yue" is defined both as extlang and redundant. Remove the dup.
subtags = Arrays.stream(initialLanguageMap.get(preferred).toString().split(","))
.distinct()
.collect(Collectors.toList())
.toList()
.toArray(new String[0]);

if (subtags.length == 2) {
Expand Down Expand Up @@ -243,7 +262,7 @@ private static String generateValuesString(String[] values) {
+ " static final Map<String, String[]> multiEquivsMap;\n"
+ " static final Map<String, String> regionVariantEquivMap;\n\n"
+ " static {\n"
+ " singleEquivMap = new HashMap<>(";
+ " singleEquivMap = HashMap.newHashMap(";

private static final String footerText =
" }\n\n"
Expand All @@ -265,11 +284,11 @@ private static void generateSourceCode(String fileName) {
Paths.get(fileName))) {
writer.write(getOpenJDKCopyright());
writer.write(headerText
+ (int)(sortedLanguageMap1.size() / 0.75f + 1) + ");\n"
+ " multiEquivsMap = new HashMap<>("
+ (int)(sortedLanguageMap2.size() / 0.75f + 1) + ");\n"
+ " regionVariantEquivMap = new HashMap<>("
+ (int)(sortedRegionVariantMap.size() / 0.75f + 1) + ");\n\n"
+ sortedLanguageMap1.size() + ");\n"
+ " multiEquivsMap = HashMap.newHashMap("
+ sortedLanguageMap2.size() + ");\n"
+ " regionVariantEquivMap = HashMap.newHashMap("
+ sortedRegionVariantMap.size() + ");\n\n"
+ " // This is an auto-generated file and should not be manually edited.\n"
+ " // LSR Revision: " + LSRrevisionDate);
writer.newLine();
Expand Down
6 changes: 3 additions & 3 deletions test/jdk/java/util/Locale/LanguageSubtagRegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
/*
* @test
* @bug 8040211 8191404 8203872 8222980 8225435 8241082 8242010 8247432
* 8258795 8267038 8287180 8302512 8304761
* 8258795 8267038 8287180 8302512 8304761 8306031
* @summary Checks the IANA language subtag registry data update
* (LSR Revision: 2023-03-22) with Locale and Locale.LanguageRange
* (LSR Revision: 2023-04-13) with Locale and Locale.LanguageRange
* class methods.
* @run main LanguageSubtagRegistryTest
*/
Expand All @@ -44,7 +44,7 @@ public class LanguageSubtagRegistryTest {
static boolean err = false;

private static final String ACCEPT_LANGUAGE =
"Accept-Language: aam, adp, aeb, ajs, aog, apc, aue, bcg, bic, bpp, cey, cbr, cnp, cqu, crr, csp, csx, dif, dmw, dsz, ehs, ema,"
"Accept-Language: aam, adp, aeb, ajs, aog, apc, ajp, aue, bcg, bic, bpp, cey, cbr, cnp, cqu, crr, csp, csx, dif, dmw, dsz, ehs, ema,"
+ " en-gb-oed, gti, iba, jks, kdz, kjh, kmb, koj, kru, ksp, kwq, kxe, kzk, lgs, lii, lmm, lsb, lsc, lsn, lsv, lsw, lvi, mtm,"
+ " ngv, nns, ola, oyb, pat, phr, plu, pnd, pub, rib, rnb, rsn, scv, snz, sqx, suj, szy, taj, tdg, tjj, tjp, tpn, tvx,"
+ " umi, uss, uth, ysm, zko, wkr;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
Expand Down

0 comments on commit 83ef66a

Please sign in to comment.