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