use language tags everywhere for Locales

This commit is contained in:
Robert Muir 2023-11-03 11:44:03 -04:00
parent 1274db1ae6
commit 0343e17fb7
No known key found for this signature in database
GPG Key ID: 817AE1DD322D7ECA
10 changed files with 29 additions and 15 deletions

View File

@ -20,7 +20,7 @@ import java.util.Locale;
/** A stemmer for Brazilian Portuguese words. */
class BrazilianStemmer {
private static final Locale locale = Locale.of("pt", "BR");
private static final Locale locale = Locale.forLanguageTag("pt-BR");
/** Changed term */
private String TERM;

View File

@ -33,7 +33,7 @@ class GermanStemmer {
/** Amount of characters that are removed with <code>substitute()</code> while stemming. */
private int substCount = 0;
private static final Locale locale = Locale.of("de", "DE");
private static final Locale locale = Locale.forLanguageTag("de-DE");
/**
* Stemms the given term to an unique <code>discriminator</code>.

View File

@ -38,7 +38,8 @@ public class ThaiTokenizer extends SegmentingTokenizerBase {
*/
public static final boolean DBBI_AVAILABLE;
private static final BreakIterator proto = BreakIterator.getWordInstance(Locale.of("th"));
private static final BreakIterator proto =
BreakIterator.getWordInstance(Locale.forLanguageTag("th"));
static {
// check that we have a working dictionary-based break iterator for thai

View File

@ -26,7 +26,7 @@ public class TestCollationKeyAnalyzer extends CollationTestBase {
// Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
// RuleBasedCollator. However, the Arabic Locale seems to order the Farsi
// characters properly.
private Collator collator = Collator.getInstance(Locale.of("ar"));
private Collator collator = Collator.getInstance(Locale.forLanguageTag("ar"));
private Analyzer analyzer;
@Override

View File

@ -24,7 +24,7 @@ import org.apache.lucene.util.BytesRef;
public class TestICUCollationKeyAnalyzer extends CollationTestBase {
private Collator collator = Collator.getInstance(Locale.of("fa"));
private Collator collator = Collator.getInstance(Locale.forLanguageTag("fa"));
private Analyzer analyzer;
@Override

View File

@ -49,10 +49,23 @@ public class NewLocaleTask extends PerfTask {
static Locale createLocale(String language, String country, String variant) {
if (language == null || language.length() == 0) return null;
String lang = language;
if (lang.equalsIgnoreCase("ROOT")) lang = ""; // empty language is the root locale in the JDK
if (language.equalsIgnoreCase("ROOT")) {
return Locale.ROOT;
}
return Locale.of(lang, country, variant);
StringBuilder sb = new StringBuilder();
sb.append(language);
if (country.length() > 0) {
sb.append('-');
sb.append(country);
if (variant.length() > 0) {
sb.append('-');
sb.append(variant);
}
}
return Locale.forLanguageTag(sb.toString());
}
@Override

View File

@ -793,19 +793,19 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
// ROOT locale
benchmark = execBenchmark(getLocaleConfig("ROOT"));
assertEquals(Locale.of(""), benchmark.getRunData().getLocale());
assertEquals(Locale.ROOT, benchmark.getRunData().getLocale());
// specify just a language
benchmark = execBenchmark(getLocaleConfig("de"));
assertEquals(Locale.of("de"), benchmark.getRunData().getLocale());
assertEquals(Locale.forLanguageTag("de"), benchmark.getRunData().getLocale());
// specify language + country
benchmark = execBenchmark(getLocaleConfig("en,US"));
assertEquals(Locale.of("en", "US"), benchmark.getRunData().getLocale());
assertEquals(Locale.forLanguageTag("en-US"), benchmark.getRunData().getLocale());
// specify language + country + variant
benchmark = execBenchmark(getLocaleConfig("no,NO,NY"));
assertEquals(Locale.of("no", "NO", "NY"), benchmark.getRunData().getLocale());
assertEquals(Locale.forLanguageTag("no-NO-NY"), benchmark.getRunData().getLocale());
}
private String[] getLocaleConfig(String localeParam) {

View File

@ -96,7 +96,7 @@ public class TestHtmlParser extends LuceneTestCase {
public void testTurkish() throws Exception {
final Locale saved = Locale.getDefault();
try {
Locale.setDefault(Locale.of("tr", "TR"));
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
String text =
"<html><HEAD><TITLE>ııı</TITLE></head><body>"
+ "<IMG SRC=\"../images/head.jpg\" WIDTH=570 HEIGHT=47 BORDER=0 ALT=\"ş\">"

View File

@ -421,7 +421,7 @@ public final class QueryParserPaneProvider implements QueryParserTabOperator {
.fuzzyMinSim(fuzzyMinSimFloat)
.fuzzyPrefixLength(fuzzyPrefLenInt)
.dateResolution(DateTools.Resolution.valueOf((String) dateResCB.getSelectedItem()))
.locale(Locale.of(locationTF.getText()))
.locale(Locale.forLanguageTag(locationTF.getText()))
.timeZone(TimeZone.getTimeZone(timezoneTF.getText()))
.typeMap(typeMap)
.build();

View File

@ -68,7 +68,7 @@ public class TestNLS extends LuceneTestCase {
}
public void testNLSLoading_xx_XX() {
Locale locale = Locale.of("xx", "XX", "");
Locale locale = Locale.forLanguageTag("xx-XX");
String message =
NLS.getLocalizedMessage(
MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale);