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