annotate babel/support.py @ 480:863bb2ae4adb stable-0.9.x

Block more msgctxt related work.
author jruigrok
date Sun, 11 Apr 2010 08:50:34 +0000
parents d1a27b087ea4
children dbb70d75718a
rev   line source
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
2 #
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2007 Edgewall Software
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
4 # All rights reserved.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
5 #
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
9 #
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
13
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
14 """Several classes and functions that help with integrating and using Babel
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
15 in applications.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
16
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
17 .. note: the code in this module is not used by Babel itself
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
18 """
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
19
101
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
20 from datetime import date, datetime, time
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
21 import gettext
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
22
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 349
diff changeset
23 try:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 349
diff changeset
24 set
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 349
diff changeset
25 except NameError:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 349
diff changeset
26 from sets import set
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 349
diff changeset
27
101
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
28 from babel.core import Locale
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
29 from babel.dates import format_date, format_datetime, format_time, LC_TIME
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
30 from babel.numbers import format_number, format_decimal, format_currency, \
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
31 format_percent, format_scientific, LC_NUMERIC
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
32 from babel.util import UTC
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
33
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
34 __all__ = ['Format', 'LazyProxy', 'Translations']
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
35 __docformat__ = 'restructuredtext en'
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
36
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
37
101
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
38 class Format(object):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
39 """Wrapper class providing the various date and number formatting functions
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
40 bound to a specific locale and time-zone.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
41
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
42 >>> fmt = Format('en_US', UTC)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
43 >>> fmt.date(date(2007, 4, 1))
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
44 u'Apr 1, 2007'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
45 >>> fmt.decimal(1.2345)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
46 u'1.234'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
47 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
48
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
49 def __init__(self, locale, tzinfo=None):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
50 """Initialize the formatter.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
51
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
52 :param locale: the locale identifier or `Locale` instance
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
53 :param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
54 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
55 self.locale = Locale.parse(locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
56 self.tzinfo = tzinfo
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
57
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
58 def date(self, date=None, format='medium'):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
59 """Return a date formatted according to the given pattern.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
60
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
61 >>> fmt = Format('en_US')
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
62 >>> fmt.date(date(2007, 4, 1))
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
63 u'Apr 1, 2007'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
64
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
65 :see: `babel.dates.format_date`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
66 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
67 return format_date(date, format, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
68
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
69 def datetime(self, datetime=None, format='medium'):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
70 """Return a date and time formatted according to the given pattern.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
71
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
72 >>> from pytz import timezone
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
73 >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
74 >>> fmt.datetime(datetime(2007, 4, 1, 15, 30))
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
75 u'Apr 1, 2007 11:30:00 AM'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
76
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
77 :see: `babel.dates.format_datetime`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
78 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
79 return format_datetime(datetime, format, tzinfo=self.tzinfo,
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
80 locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
81
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
82 def time(self, time=None, format='medium'):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
83 """Return a time formatted according to the given pattern.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
84
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
85 >>> from pytz import timezone
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
86 >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
349
7e2983180f6d Ported [385] to 0.9.x branch.
cmlenz
parents: 346
diff changeset
87 >>> fmt.time(datetime(2007, 4, 1, 15, 30))
101
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
88 u'11:30:00 AM'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
89
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
90 :see: `babel.dates.format_time`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
91 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
92 return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
93
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
94 def number(self, number):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
95 """Return an integer number formatted for the locale.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
96
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
97 >>> fmt = Format('en_US')
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
98 >>> fmt.number(1099)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
99 u'1,099'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
100
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
101 :see: `babel.numbers.format_number`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
102 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
103 return format_number(number, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
104
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
105 def decimal(self, number, format=None):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
106 """Return a decimal number formatted for the locale.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
107
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
108 >>> fmt = Format('en_US')
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
109 >>> fmt.decimal(1.2345)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
110 u'1.234'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
111
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
112 :see: `babel.numbers.format_decimal`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
113 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
114 return format_decimal(number, format, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
115
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
116 def currency(self, number, currency):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
117 """Return a number in the given currency formatted for the locale.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
118
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
119 :see: `babel.numbers.format_currency`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
120 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
121 return format_currency(number, currency, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
122
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
123 def percent(self, number, format=None):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
124 """Return a number formatted as percentage for the locale.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
125
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
126 >>> fmt = Format('en_US')
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
127 >>> fmt.percent(0.34)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
128 u'34%'
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
129
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
130 :see: `babel.numbers.format_percent`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
131 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
132 return format_percent(number, format, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
133
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
134 def scientific(self, number):
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
135 """Return a number formatted using scientific notation for the locale.
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
136
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
137 :see: `babel.numbers.format_scientific`
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
138 """
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
139 return format_scientific(number, locale=self.locale)
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
140
1312ad6b624d Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
cmlenz
parents: 100
diff changeset
141
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
142 class LazyProxy(object):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
143 """Class for proxy objects that delegate to a specified function to evaluate
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
144 the actual object.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
145
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
146 >>> def greeting(name='world'):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
147 ... return 'Hello, %s!' % name
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
148 >>> lazy_greeting = LazyProxy(greeting, name='Joe')
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
149 >>> print lazy_greeting
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
150 Hello, Joe!
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
151 >>> u' ' + lazy_greeting
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
152 u' Hello, Joe!'
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
153 >>> u'(%s)' % lazy_greeting
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
154 u'(Hello, Joe!)'
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
155
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
156 This can be used, for example, to implement lazy translation functions that
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
157 delay the actual translation until the string is actually used. The
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
158 rationale for such behavior is that the locale of the user may not always
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
159 be available. In web applications, you only know the locale when processing
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
160 a request.
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
161
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
162 The proxy implementation attempts to be as complete as possible, so that
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
163 the lazy objects should mostly work as expected, for example for sorting:
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
164
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
165 >>> greetings = [
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
166 ... LazyProxy(greeting, 'world'),
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
167 ... LazyProxy(greeting, 'Joe'),
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
168 ... LazyProxy(greeting, 'universe'),
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
169 ... ]
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
170 >>> greetings.sort()
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
171 >>> for greeting in greetings:
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
172 ... print greeting
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
173 Hello, Joe!
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
174 Hello, universe!
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
175 Hello, world!
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
176 """
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
177 __slots__ = ['_func', '_args', '_kwargs', '_value']
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
178
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
179 def __init__(self, func, *args, **kwargs):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
180 # Avoid triggering our own __setattr__ implementation
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
181 object.__setattr__(self, '_func', func)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
182 object.__setattr__(self, '_args', args)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
183 object.__setattr__(self, '_kwargs', kwargs)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
184 object.__setattr__(self, '_value', None)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
185
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
186 def value(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
187 if self._value is None:
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
188 value = self._func(*self._args, **self._kwargs)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
189 object.__setattr__(self, '_value', value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
190 return self._value
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
191 value = property(value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
192
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
193 def __contains__(self, key):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
194 return key in self.value
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
195
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
196 def __nonzero__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
197 return bool(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
198
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
199 def __dir__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
200 return dir(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
201
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
202 def __iter__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
203 return iter(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
204
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
205 def __len__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
206 return len(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
207
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
208 def __str__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
209 return str(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
210
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
211 def __unicode__(self):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
212 return unicode(self.value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
213
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
214 def __add__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
215 return self.value + other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
216
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
217 def __radd__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
218 return other + self.value
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
219
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
220 def __mod__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
221 return self.value % other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
222
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
223 def __rmod__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
224 return other % self.value
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
225
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
226 def __mul__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
227 return self.value * other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
228
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
229 def __rmul__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
230 return other * self.value
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
231
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
232 def __call__(self, *args, **kwargs):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
233 return self.value(*args, **kwargs)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
234
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
235 def __lt__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
236 return self.value < other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
237
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
238 def __le__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
239 return self.value <= other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
240
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
241 def __eq__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
242 return self.value == other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
243
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
244 def __ne__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
245 return self.value != other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
246
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
247 def __gt__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
248 return self.value > other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
249
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
250 def __ge__(self, other):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
251 return self.value >= other
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
252
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
253 def __delattr__(self, name):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
254 delattr(self.value, name)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
255
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
256 def __getattr__(self, name):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
257 return getattr(self.value, name)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
258
100
a19dff75d93b o fix misnamed vars in LazyProxy
pjenvey
parents: 61
diff changeset
259 def __setattr__(self, name, value):
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
260 setattr(self.value, name, value)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
261
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
262 def __delitem__(self, key):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
263 del self.value[key]
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
264
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
265 def __getitem__(self, key):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
266 return self.value[key]
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
267
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
268 def __setitem__(self, key, value):
100
a19dff75d93b o fix misnamed vars in LazyProxy
pjenvey
parents: 61
diff changeset
269 self.value[key] = value
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
270
407
b12eeaad51c5 Ported [442:446/trunk] to 0.9.x branch.
cmlenz
parents: 369
diff changeset
271
b12eeaad51c5 Ported [442:446/trunk] to 0.9.x branch.
cmlenz
parents: 369
diff changeset
272 class Translations(gettext.GNUTranslations, object):
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
273 """An extended translation catalog class."""
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
274
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
275 DEFAULT_DOMAIN = 'messages'
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
276
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
277 def __init__(self, fileobj=None, domain=DEFAULT_DOMAIN):
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
278 """Initialize the translations catalog.
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
279
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
280 :param fileobj: the file-like object the translation should be read
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
281 from
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
282 """
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
283 gettext.GNUTranslations.__init__(self, fp=fileobj)
346
faf0ead3a132 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 284
diff changeset
284 self.files = filter(None, [getattr(fileobj, 'name', None)])
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
285 self.domain = domain
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
286 self._domains = {}
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
287
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
288 def load(cls, dirname=None, locales=None, domain=DEFAULT_DOMAIN):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
289 """Load translations from the given directory.
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
290
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
291 :param dirname: the directory containing the ``MO`` files
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
292 :param locales: the list of locales in order of preference (items in
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
293 this list can be either `Locale` objects or locale
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
294 strings)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
295 :param domain: the message domain
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
296 :return: the loaded catalog, or a ``NullTranslations`` instance if no
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
297 matching translations were found
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
298 :rtype: `Translations`
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
299 """
346
faf0ead3a132 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 284
diff changeset
300 if locales is not None:
faf0ead3a132 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 284
diff changeset
301 if not isinstance(locales, (list, tuple)):
faf0ead3a132 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 284
diff changeset
302 locales = [locales]
faf0ead3a132 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 284
diff changeset
303 locales = [str(locale) for locale in locales]
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
304 if not domain:
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
305 domain = cls.DEFAULT_DOMAIN
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
306 filename = gettext.find(domain, dirname, locales)
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
307 if not filename:
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
308 return gettext.NullTranslations()
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
309 return cls(fileobj=open(filename, 'rb'), domain=domain)
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
310 load = classmethod(load)
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
311
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
312 def __repr__(self):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
313 return '<%s: "%s">' % (type(self).__name__,
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
314 self._info.get('project-id-version'))
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
315
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
316 def add(self, translations, merge=True):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
317 """Add the given translations to the catalog.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
318
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
319 If the domain of the translations is different than that of the
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
320 current catalog, they are added as a catalog that is only accessible
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
321 by the various ``d*gettext`` functions.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
322
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
323 :param translations: the `Translations` instance with the messages to
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
324 add
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
325 :param merge: whether translations for message domains that have
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
326 already been added should be merged with the existing
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
327 translations
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
328 :return: the `Translations` instance (``self``) so that `merge` calls
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
329 can be easily chained
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
330 :rtype: `Translations`
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
331 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
332 domain = getattr(translations, 'domain', self.DEFAULT_DOMAIN)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
333 if merge and domain == self.domain:
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
334 return self.merge(translations)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
335
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
336 existing = self._domains.get(domain)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
337 if merge and existing is not None:
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
338 existing.merge(translations)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
339 else:
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
340 translations.add_fallback(self)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
341 self._domains[domain] = translations
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
342
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
343 return self
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
344
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
345 def merge(self, translations):
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
346 """Merge the given translations into the catalog.
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
347
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
348 Message translations in the specified catalog override any messages
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
349 with the same identifier in the existing catalog.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
350
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
351 :param translations: the `Translations` instance with the messages to
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
352 merge
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
353 :return: the `Translations` instance (``self``) so that `merge` calls
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
354 can be easily chained
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
355 :rtype: `Translations`
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
356 """
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
357 if isinstance(translations, gettext.GNUTranslations):
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
358 self._catalog.update(translations._catalog)
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
359 if isinstance(translations, Translations):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
360 self.files.extend(translations.files)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
361
61
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
362 return self
da7efa40a9e2 Move `Translations` and `LazyProxy` to new `babel.support` module, which should contain any convenience code that is useful for applications using Babel/I18n, but not used by Babel itself.
cmlenz
parents:
diff changeset
363
413
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
364 def dgettext(self, domain, message):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
365 """Like ``gettext()``, but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
366 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
367 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
368 return self._domains.get(domain, self).gettext(message)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
369
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
370 def ldgettext(self, domain, message):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
371 """Like ``lgettext()``, but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
372 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
373 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
374 return self._domains.get(domain, self).lgettext(message)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
375
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
376 def dugettext(self, domain, message):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
377 """Like ``ugettext()``, but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
378 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
379 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
380 return self._domains.get(domain, self).ugettext(message)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
381
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
382 def dngettext(self, domain, singular, plural, num):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
383 """Like ``ngettext()``, but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
384 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
385 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
386 return self._domains.get(domain, self).ngettext(singular, plural, num)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
387
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
388 def ldngettext(self, domain, singular, plural, num):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
389 """Like ``lngettext()``, but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
390 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
391 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
392 return self._domains.get(domain, self).lngettext(singular, plural, num)
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
393
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
394 def dungettext(self, domain, singular, plural, num):
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
395 """Like ``ungettext()`` but look the message up in the specified
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
396 domain.
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
397 """
d1a27b087ea4 Ported [448] and [449] to 0.9.x branch.
cmlenz
parents: 407
diff changeset
398 return self._domains.get(domain, self).ungettext(singular, plural, num)
Copyright (C) 2012-2017 Edgewall Software