annotate babel/core.py @ 35:0505d666fa1f

* Import datetime patterns from CLDR. * Make the date/time arguments to the formatting functions optional, defaulting to the current date/time.
author cmlenz
date Mon, 04 Jun 2007 14:28:54 +0000
parents df1e2f0ef627
children 2e143f1a0003
rev   line source
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
2 #
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
3 # Copyright (C) 2007 Edgewall Software
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
5 #
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
9 #
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
13
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
14 """Core locale representation and locale data access gateway."""
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
15
28
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
16 from babel import localedata
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
17
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
18 __all__ = ['UnknownLocaleError', 'Locale', 'negotiate', 'parse']
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
19 __docformat__ = 'restructuredtext en'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
20
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
21
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
22 class UnknownLocaleError(Exception):
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
23 """Exception thrown when a locale is requested for which no locale data
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
24 is available.
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
25 """
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
26
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
27 def __init__(self, identifier):
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
28 """Create the exception.
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
29
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
30 :param identifier: the identifier string of the unsupported locale
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
31 """
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
32 Exception.__init__(self, 'unknown locale %r' % identifier)
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
33 self.identifier = identifier
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
34
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
35
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
36 class Locale(object):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
37 """Representation of a specific locale.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
38
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
39 >>> locale = Locale('en', territory='US')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
40 >>> repr(locale)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
41 '<Locale "en_US">'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
42 >>> locale.display_name
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
43 u'English (United States)'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
44
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
45 A `Locale` object can also be instantiated from a raw locale string:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
46
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
47 >>> locale = Locale.parse('en-US', sep='-')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
48 >>> repr(locale)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
49 '<Locale "en_US">'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
50
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
51 `Locale` objects provide access to a collection of locale data, such as
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
52 territory and language names, number and date format patterns, and more:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
53
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
54 >>> locale.number_symbols['decimal']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
55 u'.'
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
56
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
57 If a locale is requested for which no locale data is available, an
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
58 `UnknownLocaleError` is raised:
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
59
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
60 >>> Locale.parse('en_DE')
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
61 Traceback (most recent call last):
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
62 ...
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
63 UnknownLocaleError: unknown locale 'en_DE'
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
64
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
65 :see: `IETF RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>`_
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
66 """
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
67
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
68 def __init__(self, language, territory=None, variant=None):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
69 """Initialize the locale object from the given identifier components.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
70
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
71 >>> locale = Locale('en', 'US')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
72 >>> locale.language
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
73 'en'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
74 >>> locale.territory
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
75 'US'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
76
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
77 :param language: the language code
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
78 :param territory: the territory (country or region) code
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
79 :param variant: the variant code
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
80 :raise `UnknownLocaleError`: if no locale data is available for the
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
81 requested locale
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
82 """
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
83 self.language = language
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
84 self.territory = territory
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
85 self.variant = variant
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
86 identifier = str(self)
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
87 try:
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
88 self._data = localedata.load(identifier)
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
89 except IOError:
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
90 raise UnknownLocaleError(identifier)
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
91
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
92 def parse(cls, identifier, sep='_'):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
93 """Create a `Locale` instance for the given locale identifier.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
94
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
95 >>> l = Locale.parse('de-DE', sep='-')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
96 >>> l.display_name
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
97 u'Deutsch (Deutschland)'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
98
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
99 If the `identifier` parameter is not a string, but actually a `Locale`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
100 object, that object is returned:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
101
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
102 >>> Locale.parse(l)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
103 <Locale "de_DE">
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
104
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
105 :param identifier: the locale identifier string
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
106 :param sep: optional component separator
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
107 :return: a corresponding `Locale` instance
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
108 :rtype: `Locale`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
109 :raise `ValueError`: if the string does not appear to be a valid locale
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
110 identifier
33
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
111 :raise `UnknownLocaleError`: if no locale data is available for the
df1e2f0ef627 Raise error on unsupported locales. Closes #5.
cmlenz
parents: 30
diff changeset
112 requested locale
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
113 """
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
114 if type(identifier) is cls:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
115 return identifier
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
116 return cls(*parse(identifier, sep=sep))
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
117 parse = classmethod(parse)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
118
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
119 def __repr__(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
120 return '<Locale "%s">' % str(self)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
121
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
122 def __str__(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
123 return '_'.join(filter(None, [self.language, self.territory,
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
124 self.variant]))
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
125
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
126 def display_name(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
127 retval = self.languages.get(self.language)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
128 if self.territory:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
129 variant = ''
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
130 if self.variant:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
131 variant = ', %s' % self.variants.get(self.variant)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
132 retval += ' (%s%s)' % (self.territories.get(self.territory), variant)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
133 return retval
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
134 display_name = property(display_name, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
135 The localized display name of the locale.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
136
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
137 >>> Locale('en').display_name
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
138 u'English'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
139 >>> Locale('en', 'US').display_name
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
140 u'English (United States)'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
141
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
142 :type: `unicode`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
143 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
144
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
145 #{ General Locale Display Names
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
146
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
147 def languages(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
148 return self._data['languages']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
149 languages = property(languages, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
150 Mapping of language codes to translated language names.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
151
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
152 >>> Locale('de', 'DE').languages['ja']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
153 u'Japanisch'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
154
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
155 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
156 :see: `ISO 639 <http://www.loc.gov/standards/iso639-2/>`_
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
157 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
158
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
159 def scripts(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
160 return self._data['scripts']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
161 scripts = property(scripts, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
162 Mapping of script codes to translated script names.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
163
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
164 >>> Locale('en', 'US').scripts['Hira']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
165 u'Hiragana'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
166
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
167 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
168 :see: `ISO 15924 <http://www.evertype.com/standards/iso15924/>`_
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
169 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
170
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
171 def territories(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
172 return self._data['territories']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
173 territories = property(territories, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
174 Mapping of script codes to translated script names.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
175
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
176 >>> Locale('es', 'CO').territories['DE']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
177 u'Alemania'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
178
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
179 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
180 :see: `ISO 3166 <http://www.iso.org/iso/en/prods-services/iso3166ma/>`_
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
181 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
182
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
183 def variants(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
184 return self._data['variants']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
185 variants = property(variants, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
186 Mapping of script codes to translated script names.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
187
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
188 >>> Locale('de', 'DE').variants['1901']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
189 u'alte deutsche Rechtschreibung'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
190
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
191 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
192 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
193
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
194 #{ Number Formatting
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
195
28
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
196 def currencies(self):
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
197 return self._data['currency_names']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
198 currencies = property(currencies, doc="""\
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
199 Mapping of currency codes to translated currency names.
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
200
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
201 >>> Locale('en').currencies['COP']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
202 u'Colombian Peso'
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
203 >>> Locale('de', 'DE').currencies['COP']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
204 u'Kolumbianischer Peso'
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
205
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
206 :type: `dict`
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
207 """)
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
208
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
209 def currency_symbols(self):
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
210 return self._data['currency_symbols']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
211 currency_symbols = property(currency_symbols, doc="""\
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
212 Mapping of currency codes to symbols.
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
213
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
214 >>> Locale('en').currency_symbols['USD']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
215 u'US$'
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
216 >>> Locale('en', 'US').currency_symbols['USD']
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
217 u'$'
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
218
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
219 :type: `dict`
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
220 """)
695884591af6 * Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents: 24
diff changeset
221
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
222 def number_symbols(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
223 return self._data['number_symbols']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
224 number_symbols = property(number_symbols, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
225 Symbols used in number formatting.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
226
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
227 >>> Locale('fr', 'FR').number_symbols['decimal']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
228 u','
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
229
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
230 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
231 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
232
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
233 def decimal_formats(self):
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
234 return self._data['decimal_formats']
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
235 decimal_formats = property(decimal_formats, doc="""\
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
236 Locale patterns for decimal number formatting.
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
237
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
238 >>> Locale('en', 'US').decimal_formats[None]
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
239 <NumberPattern u'#,##0.###'>
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
240
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
241 :type: `dict`
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
242 """)
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
243
24
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
244 def percent_formats(self):
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
245 return self._data['percent_formats']
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
246 percent_formats = property(percent_formats, doc="""\
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
247 Locale patterns for percent number formatting.
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
248
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
249 >>> Locale('en', 'US').percent_formats[None]
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
250 <NumberPattern u'#,##0%'>
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
251
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
252 :type: `dict`
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
253 """)
6c2c9fc7d787 Implemented babel.numbers.format_percent
jonas
parents: 17
diff changeset
254
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
255 #{ Calendar Information and Date Formatting
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
256
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
257 def periods(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
258 return self._data['periods']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
259 periods = property(periods, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
260 Locale display names for day periods (AM/PM).
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
261
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
262 >>> Locale('en', 'US').periods['am']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
263 u'AM'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
264
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
265 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
266 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
267
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
268 def days(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
269 return self._data['days']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
270 days = property(days, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
271 Locale display names for weekdays.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
272
17
aa33ad077d24 Minor date formatting improvements.
cmlenz
parents: 14
diff changeset
273 >>> Locale('de', 'DE').days['format']['wide'][3]
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
274 u'Donnerstag'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
275
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
276 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
277 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
278
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
279 def months(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
280 return self._data['months']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
281 months = property(months, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
282 Locale display names for months.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
283
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
284 >>> Locale('de', 'DE').months['format']['wide'][10]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
285 u'Oktober'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
286
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
287 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
288 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
289
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
290 def quarters(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
291 return self._data['quarters']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
292 quarters = property(quarters, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
293 Locale display names for quarters.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
294
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
295 >>> Locale('de', 'DE').quarters['format']['wide'][1]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
296 u'1. Quartal'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
297
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
298 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
299 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
300
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
301 def eras(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
302 return self._data['eras']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
303 eras = property(eras, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
304 Locale display names for eras.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
305
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
306 >>> Locale('en', 'US').eras['wide'][1]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
307 u'Anno Domini'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
308 >>> Locale('en', 'US').eras['abbreviated'][0]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
309 u'BC'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
310
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
311 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
312 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
313
30
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
314 def time_zones(self):
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
315 return self._data['time_zones']
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
316 time_zones = property(time_zones, doc="""\
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
317 Locale display names for time zones.
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
318
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
319 >>> Locale('en', 'US').time_zones['America/Los_Angeles']['long']['standard']
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
320 u'Pacific Standard Time'
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
321 >>> Locale('en', 'US').time_zones['Europe/Dublin']['city']
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
322 u'Dublin'
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
323
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
324 :type: `dict`
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
325 """)
9a00ac84004c Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents: 28
diff changeset
326
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
327 def first_week_day(self):
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
328 return self._data['week_data']['first_day']
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
329 first_week_day = property(first_week_day, doc="""\
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
330 The first day of a week.
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
331
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
332 >>> Locale('de', 'DE').first_week_day
17
aa33ad077d24 Minor date formatting improvements.
cmlenz
parents: 14
diff changeset
333 0
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
334 >>> Locale('en', 'US').first_week_day
17
aa33ad077d24 Minor date formatting improvements.
cmlenz
parents: 14
diff changeset
335 6
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
336
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
337 :type: `int`
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
338 """)
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
339
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
340 def weekend_start(self):
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
341 return self._data['week_data']['weekend_start']
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
342 weekend_start = property(weekend_start, doc="""\
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
343 The day the weekend starts.
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
344
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
345 >>> Locale('de', 'DE').weekend_start
17
aa33ad077d24 Minor date formatting improvements.
cmlenz
parents: 14
diff changeset
346 5
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
347
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
348 :type: `int`
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
349 """)
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
350
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
351 def weekend_end(self):
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
352 return self._data['week_data']['weekend_end']
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
353 weekend_end = property(weekend_end, doc="""\
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
354 The day the weekend ends.
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
355
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
356 >>> Locale('de', 'DE').weekend_end
17
aa33ad077d24 Minor date formatting improvements.
cmlenz
parents: 14
diff changeset
357 6
10
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
358
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
359 :type: `int`
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
360 """)
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
361
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
362 def min_week_days(self):
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
363 return self._data['week_data']['min_days']
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
364 min_week_days = property(min_week_days, doc="""\
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
365 The minimum number of days in a week so that the week is counted as the
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
366 first week of a year or month.
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
367
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
368 >>> Locale('de', 'DE').min_week_days
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
369 4
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
370
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
371 :type: `int`
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
372 """)
0ca5dd65594f Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents: 3
diff changeset
373
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
374 def date_formats(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
375 return self._data['date_formats']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
376 date_formats = property(date_formats, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
377 Locale patterns for date formatting.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
378
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
379 >>> Locale('en', 'US').date_formats['short']
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
380 <DateTimePattern u'M/d/yy'>
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
381 >>> Locale('fr', 'FR').date_formats['long']
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
382 <DateTimePattern u'd MMMM yyyy'>
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
383
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
384 :type: `dict`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
385 """)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
386
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
387 def time_formats(self):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
388 return self._data['time_formats']
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
389 time_formats = property(time_formats, doc="""\
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
390 Locale patterns for time formatting.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
391
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
392 >>> Locale('en', 'US').time_formats['short']
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
393 <DateTimePattern u'h:mm a'>
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
394 >>> Locale('fr', 'FR').time_formats['long']
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 11
diff changeset
395 <DateTimePattern u'HH:mm:ss z'>
11
11f64b232b04 Add basic support for number format patterns.
jonas
parents: 10
diff changeset
396
11f64b232b04 Add basic support for number format patterns.
jonas
parents: 10
diff changeset
397 :type: `dict`
11f64b232b04 Add basic support for number format patterns.
jonas
parents: 10
diff changeset
398 """)
11f64b232b04 Add basic support for number format patterns.
jonas
parents: 10
diff changeset
399
35
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
400 def datetime_formats(self):
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
401 return self._data['datetime_formats']
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
402 datetime_formats = property(datetime_formats, doc="""\
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
403 Locale patterns for datetime formatting.
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
404
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
405 >>> Locale('en').datetime_formats[None]
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
406 u'{1} {0}'
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
407 >>> Locale('th').datetime_formats[None]
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
408 u'{1}, {0}'
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
409
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
410 :type: `dict`
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
411 """)
0505d666fa1f * Import datetime patterns from CLDR.
cmlenz
parents: 33
diff changeset
412
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
413
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
414 def negotiate(preferred, available):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
415 """Find the best match between available and requested locale strings.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
416
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
417 >>> negotiate(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
418 'de_DE'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
419 >>> negotiate(['de_DE', 'en_US'], ['en', 'de'])
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
420 'de'
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
421
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
422 :param preferred: the list of locale strings preferred by the user
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
423 :param available: the list of locale strings available
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
424 :return: the locale identifier for the best match, or `None` if no match
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
425 was found
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
426 :rtype: `str`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
427 """
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
428 for locale in preferred:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
429 if locale in available:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
430 return locale
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
431 parts = locale.split('_')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
432 if len(parts) > 1 and parts[0] in available:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
433 return parts[0]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
434 return None
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
435
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
436 def parse(identifier, sep='_'):
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
437 """Parse a locale identifier into a ``(language, territory, variant)``
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
438 tuple.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
439
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
440 >>> parse('zh_CN')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
441 ('zh', 'CN', None)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
442
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
443 The default component separator is "_", but a different separator can be
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
444 specified using the `sep` parameter:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
445
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
446 >>> parse('zh-CN', sep='-')
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
447 ('zh', 'CN', None)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
448
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
449 :param identifier: the locale identifier string
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
450 :param sep: character that separates the different parts of the locale
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
451 string
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
452 :return: the ``(language, territory, variant)`` tuple
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
453 :rtype: `tuple`
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
454 :raise `ValueError`: if the string does not appear to be a valid locale
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
455 identifier
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
456
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
457 :see: `IETF RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>`_
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
458 """
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
459 parts = identifier.split(sep)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
460 lang, territory, variant = parts[0].lower(), None, None
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
461 if not lang.isalpha():
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
462 raise ValueError('expected only letters, got %r' % lang)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
463 if len(parts) > 1:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
464 territory = parts[1].upper().split('.', 1)[0]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
465 if not territory.isalpha():
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
466 raise ValueError('expected only letters, got %r' % territory)
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
467 if len(parts) > 2:
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
468 variant = parts[2].upper().split('.', 1)[0]
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
469 return lang, territory, variant
Copyright (C) 2012-2017 Edgewall Software