dcsimg
Obtaining languages for a country
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jennifer_Morgan
Posted On:   Wednesday, November 14, 2001 07:36 AM

How can I obtain the languages spoken in a country? For example, Locale has a private method getLanguagesForCountry, but I can't use it since it's private. Is there another way to obtain the languages spoken in a given country?

Re: Obtaining languages for a country

Posted By:   Anonymous  
Posted On:   Monday, November 19, 2001 04:02 PM

This is an interesting question because the answers, none of which may be satisfactory, depend on how the information is to be used.


"I want to present countries and the languages spoken in them for purposes other than creating and using locales."


In this case, there is no particular reason to expect a general purpose language to provide the information. However, the package scope method Locale.getLanguagesForCountry() does exist. Note that no reference is given for the source of the information; we have no idea how it was derived. We don't even know if these are official languages or just that a lot of people speak them in the given country. Even so, we could grab the data and create our own array/collection for use in our programs. While this is technically copying code, it is really general data and I suspect the odds of legal problems are low. Other sources that I found are EITI's Country-Language Lookup page and
Ethnologue's Country Index. Unfortunately, neither site has the dataset in a readily computer readable format. Reader input for any sites, probably government or standards, that has this information complete in a single table is welcome. Note that this does not address the case of a foreign language speaker in a specific country.


"I want to present countries and the languages spoken in them to generate and use the resulting locales."


In this case, we are better off using Locale's getAvailableLocales() and pulling the associated countries and languages from the locales returned. The reason for this is that a locale is only an identifier ( see What is a locale and why is it useful? ) and is useful only with locale sensitive classes. Java only supports about 100 locales ( Supported Locales ) and there is generally a one to one mapping between country and language. This means that while we can create all the locales we want from the information sources listed above, NumberFormat, for example, will only properly work with the supported locales. Unless we write our own classes and/or handlers, of course.

About | Sitemap | Contact