<i18n dev> RFR: 8159337: Introduce a method in Locale class to return the language tags as per RFC 5646 convention

Justin Lu jlu at openjdk.org
Wed Apr 26 22:34:56 UTC 2023


Please review this PR which adds the method `caseFoldLanguageTag(String languageTag)` to java.util.Locale.

This method case folds a language tag to adhere to _[section 2.1.1. Formatting of Language Tags of RFC5646](https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1)_. This format is defined as _"All subtags, including extension and private use subtags, use lowercase letters with two exceptions: two-letter and four-letter subtags that neither appear at the start of the tag nor occur after singletons.  Such two-letter subtags are all uppercase ... and four-letter subtags are titlecase."_.


In order to match the behavior of existing language tag related Locale methods, this method matches the 2.1.1 RFC5646 specification with the following **exceptions**:
- Will not case fold variant subtags
- Will not case fold private use subtags prefixed by "lvariant"

As an example, `caseFoldLanguageTag("JA-JPAN-JP-U-CA-JAPANESE-x-RANDOM-lvariant-JP")` returns _"ja-Jpan-JP-u-ca-japanese-x-random-lvariant-JP"_. Further examples can be seen in the test file.

-------------

Commit messages:
 - Copyright year for LangTag
 - Space
 - Add PR example to tests
 - Add case for grandfathered tag in specification
 - Consider private use variant prefix (JDK special cases)
 - Cache the potential legacy tag
 - Remove leftover comments in LanguageTag
 - Adjust imports in LanguageTag.java
 - Add implementation to LanguageTag.java
 - Add specification to Locale
 - ... and 1 more: https://git.openjdk.org/jdk/compare/d063b896...25be34d9

Changes: https://git.openjdk.org/jdk/pull/13679/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13679&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8159337
  Stats: 251 lines in 3 files changed: 247 ins; 2 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/13679.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/13679/head:pull/13679

PR: https://git.openjdk.org/jdk/pull/13679


More information about the i18n-dev mailing list