Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get localized language name from locale code

Tags:

python

locale

How can I get localized language name by specified locale code in python?

For example:

>> get_language_name('ja')
>> ('Japanese', u'日本語')
like image 670
jack Avatar asked Apr 17 '10 08:04

jack


People also ask

How do I get language code from locale?

The getLanguage() method of Locale class in Java is used to get language code for the specified locale. This will either be an empty string or a lowercase ISO 639 code. Parameters: This method does not take any parameters.

Does locale include language?

Locale is a lightweight object that contains only a few important members: A language code. An optional country or region code. An optional variant code.

Is locale same as language?

They are independent of your language. Setting a thread's locale or changing your system locale will change how numbers, dates, and times are displayed for controls created on that thread or running on your system, respectively. A language, on the other hand, is what we speak, read, and write.

What is a locale language code?

In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language code and a country/region code.


1 Answers

The Babel package can help:

>>> from babel import Locale
>>> locale = Locale('ja', 'JP')
>>> print locale.display_name
日本語 (日本)

There is also PyICU, a Python wrapper for the ICU library.

like image 51
Ned Deily Avatar answered Nov 14 '22 23:11

Ned Deily