Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Are the IETF BCP 47 language tags defined as enums anywhere in JDK?

For Locale.forLanguageTag() we pass values like fr-FR, jp-JP etc.

Are there any enums already provided by JDK for it? Or should the developer be writing a custom enum for that? How to handle it in i18n application?

share|improve this question
up vote 3 down vote accepted

Enum would be wrong way for this in JDK API which is supposed to serve wide variety of applications.

It would be also wrong in application development, unless the application is purposedly designed to serve a fixed, limited subset of languages - subset that is known at compile time - which, in turn, would hardly qualify as related to BCP-47.

This is because substantial attribute of BCP-47 is addressing an open-ended set of values:

Language tags are used to help identify languages, whether spoken, written, signed, or otherwise signaled, for the purpose of communication. This includes constructed and artificial languages but excludes languages not intended primarily for human communication, such as programming languages...

The ietf-languages list is an open list...

Above, in turn, makes it wrong fit for enum, which is intended to serve fixed, limited sets of values:

You should use enum types any time you need to represent a fixed set of constants. That includes natural enum types such as the planets in our solar system and data sets where you know all possible values at compile time - for example, the choices on a menu, command line flags, and so on...

share|improve this answer

JDK does not contain an enum for IETF BCP 47 language tags. Inside Oracle JDK they are expressed inside a non-public string array of a sun.util.* class. You should not get them from there.

In Java 7 you can iterate over available locales and call toLanguageTag() for each one or, as you say, create your own enum.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.