annotate babel/messages/checkers.py @ 507:b29ff192b610 stable-0.9.x

Python 2.3 compatibility: backporting r456 and r457 to 0.9 branch (see #233)
author fschwarz
date Fri, 04 Mar 2011 13:14:03 +0000
parents 07a27065102a
children
rev   line source
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
2 #
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2007 Edgewall Software
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
4 # All rights reserved.
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
5 #
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
9 #
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
13
234
ada322f472ca Add more `since` tags to stuff added in trunk.
cmlenz
parents: 220
diff changeset
14 """Various routines that help with validation of translations.
ada322f472ca Add more `since` tags to stuff added in trunk.
cmlenz
parents: 220
diff changeset
15
ada322f472ca Add more `since` tags to stuff added in trunk.
cmlenz
parents: 220
diff changeset
16 :since: version 0.9
ada322f472ca Add more `since` tags to stuff added in trunk.
cmlenz
parents: 220
diff changeset
17 """
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
18
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
19 from itertools import izip
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
20 from babel.messages.catalog import TranslationError, PYTHON_FORMAT
507
b29ff192b610 Python 2.3 compatibility: backporting r456 and r457 to 0.9 branch (see #233)
fschwarz
parents: 488
diff changeset
21 from babel.util import set
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
22
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
23 #: list of format chars that are compatible to each other
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
24 _string_format_compatibilities = [
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
25 set(['i', 'd', 'u']),
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
26 set(['x', 'X']),
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
27 set(['f', 'F', 'g', 'G'])
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
28 ]
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
29
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
30
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
31 def num_plurals(catalog, message):
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
32 """Verify the number of plurals in the translation."""
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
33 if not message.pluralizable:
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
34 if not isinstance(message.string, basestring):
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
35 raise TranslationError("Found plural forms for non-pluralizable "
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
36 "message")
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
37 return
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
38
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
39 # skip further tests if no catalog is provided.
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
40 elif catalog is None:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
41 return
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
42
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
43 msgstrs = message.string
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
44 if not isinstance(msgstrs, (list, tuple)):
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
45 msgstrs = (msgstrs,)
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
46 if len(msgstrs) != catalog.num_plurals:
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
47 raise TranslationError("Wrong number of plural forms (expected %d)" %
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
48 catalog.num_plurals)
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
49
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
50
220
677147547e2d Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
diff changeset
51 def python_format(catalog, message):
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
52 """Verify the format string placeholders in the translation."""
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
53 if 'python-format' not in message.flags:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
54 return
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
55 msgids = message.id
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
56 if not isinstance(msgids, (list, tuple)):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
57 msgids = (msgids,)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
58 msgstrs = message.string
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
59 if not isinstance(msgstrs, (list, tuple)):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
60 msgstrs = (msgstrs,)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
61
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
62 for msgid, msgstr in izip(msgids, msgstrs):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
63 if msgstr:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
64 _validate_format(msgid, msgstr)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
65
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
66
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
67 def _validate_format(format, alternative):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
68 """Test format string `alternative` against `format`. `format` can be the
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
69 msgid of a message and `alternative` one of the `msgstr`\s. The two
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
70 arguments are not interchangeable as `alternative` may contain less
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
71 placeholders if `format` uses named placeholders.
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
72
488
07a27065102a Merged revisions 458 via svnmerge from
jruigrok
parents: 369
diff changeset
73 The behavior of this function is undefined if the string does not use
07a27065102a Merged revisions 458 via svnmerge from
jruigrok
parents: 369
diff changeset
74 string formattings.
369
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
75
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
76 If the string formatting of `alternative` is compatible to `format` the
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
77 function returns `None`, otherwise a `TranslationError` is raised.
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
78
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
79 Examples for compatible format strings:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
80
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
81 >>> _validate_format('Hello %s!', 'Hallo %s!')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
82 >>> _validate_format('Hello %i!', 'Hallo %d!')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
83
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
84 Example for an incompatible format strings:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
85
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
86 >>> _validate_format('Hello %(name)s!', 'Hallo %s!')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
87 Traceback (most recent call last):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
88 ...
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
89 TranslationError: the format strings are of different kinds
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
90
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
91 This function is used by the `python_format` checker.
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
92
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
93 :param format: The original format string
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
94 :param alternative: The alternative format string that should be checked
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
95 against format
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
96 :return: None on success
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
97 :raises TranslationError: on formatting errors
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
98 """
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
99
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
100 def _parse(string):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
101 result = []
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
102 for match in PYTHON_FORMAT.finditer(string):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
103 name, format, typechar = match.groups()
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
104 if typechar == '%' and name is None:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
105 continue
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
106 result.append((name, str(typechar)))
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
107 return result
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
108
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
109 def _compatible(a, b):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
110 if a == b:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
111 return True
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
112 for set in _string_format_compatibilities:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
113 if a in set and b in set:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
114 return True
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
115 return False
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
116
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
117 def _check_positional(results):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
118 positional = None
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
119 for name, char in results:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
120 if positional is None:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
121 positional = name is None
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
122 else:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
123 if (name is None) != positional:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
124 raise TranslationError('format string mixes positional '
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
125 'and named placeholders')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
126 return bool(positional)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
127
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
128 a, b = map(_parse, (format, alternative))
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
129
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
130 # now check if both strings are positional or named
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
131 a_positional, b_positional = map(_check_positional, (a, b))
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
132 if a_positional and not b_positional and not b:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
133 raise TranslationError('placeholders are incompatible')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
134 elif a_positional != b_positional:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
135 raise TranslationError('the format strings are of different kinds')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
136
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
137 # if we are operating on positional strings both must have the
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
138 # same number of format chars and those must be compatible
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
139 if a_positional:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
140 if len(a) != len(b):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
141 raise TranslationError('positional format placeholders are '
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
142 'unbalanced')
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
143 for idx, ((_, first), (_, second)) in enumerate(izip(a, b)):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
144 if not _compatible(first, second):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
145 raise TranslationError('incompatible format for placeholder '
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
146 '%d: %r and %r are not compatible' %
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
147 (idx + 1, first, second))
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
148
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
149 # otherwise the second string must not have names the first one
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
150 # doesn't have and the types of those included must be compatible
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
151 else:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
152 type_map = dict(a)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
153 for name, typechar in b:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
154 if name not in type_map:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
155 raise TranslationError('unknown named placeholder %r' % name)
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
156 elif not _compatible(typechar, type_map[name]):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
157 raise TranslationError('incompatible format for '
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
158 'placeholder %r: '
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
159 '%r and %r are not compatible' %
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
160 (name, typechar, type_map[name]))
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
161
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
162
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
163 def _find_checkers():
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
164 try:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
165 from pkg_resources import working_set
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
166 except ImportError:
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
167 return [num_plurals, python_format]
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
168 checkers = []
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
169 for entry_point in working_set.iter_entry_points('babel.checkers'):
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
170 checkers.append(entry_point.load())
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
171 return checkers
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
172
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
173
c2ae38340540 Ported [388:405/trunk] to 0.9.x branch.
cmlenz
parents: 234
diff changeset
174 checkers = _find_checkers()
Copyright (C) 2012-2017 Edgewall Software