cmlenz@2: .. -*- mode: rst; encoding: utf-8 -*- cmlenz@2: cmlenz@2: ==================== cmlenz@2: Locale Display Names cmlenz@2: ==================== cmlenz@2: cmlenz@2: .. contents:: Contents cmlenz@2: :depth: 2 cmlenz@2: .. sectnum:: cmlenz@2: cmlenz@2: cmlenz@2: Introduction cmlenz@2: ============ cmlenz@2: cmlenz@124: While `message catalogs `_ allow you to localize any messages cmlenz@2: in your application, there are a number of strings that are used in many cmlenz@2: applications for which translations are readily available. cmlenz@2: cmlenz@2: Imagine for example you have a list of countries that users can choose from, cmlenz@2: and you'd like to display the names of those countries in the language the cmlenz@2: user prefers. Instead of translating all those country names yourself in your cmlenz@2: application, you can make use of the translations provided by the locale data cmlenz@2: included with Babel, which is based on the `Common Locale Data Repository cmlenz@2: (CLDR) `_ developed and maintained by the `Unicode cmlenz@2: Consortium `_. cmlenz@2: cmlenz@2: cmlenz@2: The ``Locale`` Class cmlenz@2: ==================== cmlenz@2: cmlenz@2: You normally access such locale data through the `Locale`_ class provided cmlenz@40: by Babel: cmlenz@40: cmlenz@40: .. code-block:: pycon cmlenz@2: cmlenz@2: >>> from babel import Locale cmlenz@2: >>> locale = Locale('en', 'US') cmlenz@2: >>> locale.territories['US'] cmlenz@2: u'United States' cmlenz@2: >>> locale = Locale('es', 'MX') cmlenz@2: >>> locale.territories['US'] cmlenz@2: u'Estados Unidos' cmlenz@2: cmlenz@2: .. _`Locale`: api/babel.core.Locale-class.html cmlenz@2: cmlenz@2: In addition to country/territory names, the locale data also provides access to cmlenz@2: names of languages, scripts, variants, time zones, and more. Some of the data cmlenz@124: is closely related to number and date formatting. cmlenz@2: cmlenz@2: Most of the corresponding ``Locale`` properties return dictionaries, where the cmlenz@2: key is a code such as the ISO country and language codes. Consult the API cmlenz@2: documentation for references to the relevant specifications. cmlenz@2: cmlenz@25: cmlenz@25: Calender Display Names cmlenz@25: ====================== cmlenz@25: cmlenz@25: The `Locale`_ class provides access to many locale display names related to cmlenz@25: calendar display, such as the names of week days or months. cmlenz@25: cmlenz@25: These display names are of course used for date formatting, but can also be cmlenz@25: used, for example, to show a list of months to the user in their preferred cmlenz@40: language: cmlenz@40: cmlenz@40: .. code-block:: pycon cmlenz@25: cmlenz@25: >>> locale = Locale('es') cmlenz@25: >>> month_names = locale.months['format']['wide'].items() cmlenz@25: >>> month_names.sort() cmlenz@25: >>> for idx, name in month_names: cmlenz@25: ... print name cmlenz@25: enero cmlenz@25: febrero cmlenz@25: marzo cmlenz@25: abril cmlenz@25: mayo cmlenz@25: junio cmlenz@25: julio cmlenz@25: agosto cmlenz@25: septiembre cmlenz@25: octubre cmlenz@25: noviembre cmlenz@25: diciembre