|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
You can create aLocalewith any combination of valid language and country codes, but that doesn't mean that you can use it. Remember, aLocaleobject is only an identifier. You pass theLocaleobject to other objects, which then do the real work. These other objects, which we call locale-sensitive, do not know how to deal with all possibleLocaledefinitions.To find out which types of
Localedefinitions a locale-sensitive class recognizes, you invoke thegetAvailableLocalesmethod. For example, to find out whichLocaledefinitions are supported by theDateFormatclass, you could write a routine such as the following:import java.util.*; import java.text.*; public class Available { static public void main(String[] args) { Locale list[] = DateFormat.getAvailableLocales(); for (Locale aLocale : list) { System.out.println(aLocale.toString()); } } }Note that the
Stringreturned bytoStringcontains the language and country codes, separated by an underscore:ar_EG be_BY bg_BG ca_ES cs_CZ da_DK de_DE . . .If you want to display a list of
Localenames to end users, you should show them something easier to understand than the language and country codes returned bytoString. Instead you can invoke theLocale.getDisplayNamemethod, which retrieves a localizedStringof aLocaleobject. For example, whentoStringis replaced bygetDisplayNamein the preceding code, the program prints the following lines:Arabic (Egypt) Belarussian (Belarus) Bulgarian (Bulgaria) Catalan (Spain) Czech (Czech Republic) Danish (Denmark) German (Germany) . . .You may see different locale lists depending on the Java Platform implementations.