Movatterモバイル変換


[0]ホーム

URL:


JEP 128: Unicode BCP 47 Locale Matching

AuthorNaoto Sato
OwnerYuka Kamiya
TypeFeature
ScopeSE
StatusClosed / Delivered
Release8
Componentcore-libs / java.util:i18n
Discussioni18n dash dev at openjdk dot java dot net
EffortM
DurationL
Endorsed byBrian Goetz
Created2011/07/15 20:00
Updated2017/10/23 21:19
Issue8046118

Summary

Define APIs so that applications that use BCP 47 language tags (seeRFC 5646) can match them to a user's language preferences in away that conforms toRFC 4647.

Motivation

It's a common scenario across applications, platforms, and/or protocols to needto specify a set of language tags (i.e., a range of languages), and match agiven language tag against such a set, e.g., a user's preferred set oflanguages. Java SE 8 will provide a full BCP 47 implementation according toRFC 5646.

Description

Implement the functionality defined inRFC 4647, whose descriptionis as follows:

This document describes a syntax, called a "language-range", for specifyingitems in a user's list of language preferences. It also describes differentmechanisms for comparing and matching these to language tags. Two kinds ofmatching mechanisms, filtering and lookup, are defined. Filtering produces a(potentially empty) set of language tags, whereas lookup produces a singlelanguage tag. Possible applications include language negotiation or contentselection.

The basic ideas of the API to be proposed are:

  1. Implement the Language Range with aCollection<String>, and the LanguagePriority List with aList<String>.

  2. Provide a few methods that implement the following:

    • Basic filtering: Take the Basic Language Range and the Language PriorityList, and returning the filtered set of Language Tags.
    • Extended filtering: Take the Extended Language Range and the LanguagePriority List, and return the filtered set of Language Tags.
    • Lookup: Take the Basic Language Range and the Language Priority List,and return the best matched Language Tag.

Example: Here's a person who speaks Japanese("ja") as mother tongue,English("en") and German("de") as the second languages. He lives in Japan.And, here's an application which happens to have localization resource data forEnglish, French, New Caledonian Javanese, and Japanese.

The above situation could be expressed like this with the new API:

/* Basic language ranges for this user's language priority list:  *   ja-JP: Japanese used in Japan *   en-jp: English used in Japan *   de-JP: German used in Japan * * The order expresses the priority of each language for the user. * Note that each sub tag (e.g. "jp") are case insensitive and used after * normalization. */List<String> list1 = Arrays.asList("ja-JP", "en-jp", "de-JP");/* Extended language ranges for this user's language priority list:  *   ja-*-JP: Japanese used in Japan *   en-*-jp: English used in Japan *   de-*-JP: German used in Japan * * The order expresses the priority of each language for the user. * Note that each sub tag (e.g. "jp") are case insensitive and used after * normalization. */List<String> list2 = Arrays.asList("ja-*-JP", "en-*-jp", "de-*-JP");/* The app's language ranges: *   en-US: English used in the USA *   en-JP: Japanese used in the USA *   fr-FR: French used in France, *   de-de: German used in Germany *   de-CH: German used in Switzerland *   de-jp: German used in Japan *   jas-JP: New Caledonian Javanese used in Japan *   ja-US: Japanese used in the USA */  ja-Latn-JP: Japanese used in Japan, written in Latin alphabetCollection<String> ranges =    Arrays.asList("en-US", "en-JP", "fr-FR", "de-DE", "de-CH", "de-JP",                  "ja-US", "jas-JP", "ja-Latn-JP");// Matching 1: Basic filtering returns a list of "en-JP" and// "de-JP".List<Locale> tags1 = Locale.filterBasic(list1, ranges);// Matching 2: Extended filtering returns a list of "ja-Latn-JP",// "en-JP", and "de-JP".List<Locale> tags2 = Locale.filterExtended(list2, ranges);// Matching 3: Look up returns "en-JP".Locale locale = Locale.lookup(list1, ranges);</code>

Note that the API introduced here is a draft and may be changed later.

OpenJDK logo
Installing
Contributing
Sponsoring
Developers' Guide
Vulnerabilities
JDK GA/EA Builds
Mailing lists
Wiki ·IRC
Mastodon
Bluesky
Bylaws ·Census
Legal
Workshop
JEP Process
Source code
GitHub
Mercurial
Tools
Git
jtreg harness
Groups
(overview)
Adoption
Build
Client Libraries
Compatibility & Specification Review
Compiler
Conformance
Core Libraries
Governing Board
HotSpot
IDE Tooling & Support
Internationalization
JMX
Members
Networking
Porters
Quality
Security
Serviceability
Vulnerability
Web
Projects
(overview,archive)
Amber
Babylon
CRaC
Code Tools
Coin
Common VM Interface
Developers' Guide
Device I/O
Duke
Galahad
Graal
IcedTea
JDK 8 Updates
JDK 9
JDK (…,24,25,26)
JDK Updates
JMC
Jigsaw
Kona
Lanai
Leyden
Lilliput
Locale Enhancement
Loom
Memory Model Update
Metropolis
Multi-Language VM
Nashorn
New I/O
OpenJFX
Panama
Penrose
Port: AArch32
Port: AArch64
Port: BSD
Port: Haiku
Port: Mac OS X
Port: MIPS
Port: Mobile
Port: PowerPC/AIX
Port: RISC-V
Port: s390x
SCTP
Shenandoah
Skara
Sumatra
Tsan
Valhalla
Verona
VisualVM
Wakefield
Zero
ZGC
Oracle logo
© 2025 Oracle Corporation and/or its affiliates
Terms of Use · License:GPLv2 ·Privacy ·Trademarks

[8]ページ先頭

©2009-2025 Movatter.jp