Mercurial > genshi > mirror
annotate genshi/filters/tests/i18n.py @ 1017:9c4fafa85f4a stable-0.7.x
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
author | hodgestar |
---|---|
date | Thu, 09 Jan 2014 21:25:21 +0000 |
parents | 7f8b4df4f862 |
children |
rev | line source |
---|---|
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2 # |
897 | 3 # Copyright (C) 2007-2010 Edgewall Software |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
5 # |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
9 # |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
13 |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
14 from datetime import datetime |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
15 import doctest |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
16 from gettext import NullTranslations |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
17 import unittest |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
18 |
667
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
19 from genshi.core import Attrs |
849 | 20 from genshi.template import MarkupTemplate, Context |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
21 from genshi.filters.i18n import Translator, extract |
667
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
22 from genshi.input import HTML |
933 | 23 from genshi.compat import IS_PYTHON2, StringIO |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
24 |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
25 |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
26 class DummyTranslations(NullTranslations): |
849 | 27 _domains = {} |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
28 |
849 | 29 def __init__(self, catalog=()): |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
30 NullTranslations.__init__(self) |
849 | 31 self._catalog = catalog or {} |
32 self.plural = lambda n: n != 1 | |
33 | |
34 def add_domain(self, domain, catalog): | |
35 translation = DummyTranslations(catalog) | |
36 translation.add_fallback(self) | |
37 self._domains[domain] = translation | |
38 | |
39 def _domain_call(self, func, domain, *args, **kwargs): | |
40 return getattr(self._domains.get(domain, self), func)(*args, **kwargs) | |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
41 |
933 | 42 if IS_PYTHON2: |
43 def ugettext(self, message): | |
44 missing = object() | |
45 tmsg = self._catalog.get(message, missing) | |
46 if tmsg is missing: | |
47 if self._fallback: | |
48 return self._fallback.ugettext(message) | |
49 return unicode(message) | |
50 return tmsg | |
51 else: | |
52 def gettext(self, message): | |
53 missing = object() | |
54 tmsg = self._catalog.get(message, missing) | |
55 if tmsg is missing: | |
56 if self._fallback: | |
57 return self._fallback.gettext(message) | |
58 return unicode(message) | |
59 return tmsg | |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
60 |
933 | 61 if IS_PYTHON2: |
62 def dugettext(self, domain, message): | |
63 return self._domain_call('ugettext', domain, message) | |
64 else: | |
65 def dgettext(self, domain, message): | |
66 return self._domain_call('gettext', domain, message) | |
849 | 67 |
68 def ungettext(self, msgid1, msgid2, n): | |
69 try: | |
70 return self._catalog[(msgid1, self.plural(n))] | |
71 except KeyError: | |
72 if self._fallback: | |
73 return self._fallback.ngettext(msgid1, msgid2, n) | |
74 if n == 1: | |
75 return msgid1 | |
76 else: | |
77 return msgid2 | |
78 | |
933 | 79 if not IS_PYTHON2: |
80 ngettext = ungettext | |
81 del ungettext | |
82 | |
83 if IS_PYTHON2: | |
84 def dungettext(self, domain, singular, plural, numeral): | |
85 return self._domain_call('ungettext', domain, singular, plural, numeral) | |
86 else: | |
87 def dngettext(self, domain, singular, plural, numeral): | |
88 return self._domain_call('ngettext', domain, singular, plural, numeral) | |
849 | 89 |
788
31432f30a6fb
Change `Translator` class to accept either a `gettext`-style function, or an object compatible with the `NullTranslations` / `GNUTranslations` interface.
cmlenz
parents:
787
diff
changeset
|
90 |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
91 class TranslatorTestCase(unittest.TestCase): |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
92 |
667
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
93 def test_translate_included_attribute_text(self): |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
94 """ |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
95 Verify that translated attributes end up in a proper `Attrs` instance. |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
96 """ |
933 | 97 html = HTML(u"""<html> |
667
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
98 <span title="Foo"></span> |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
99 </html>""") |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
100 translator = Translator(lambda s: u"Voh") |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
101 stream = list(html.filter(translator)) |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
102 kind, data, pos = stream[2] |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
103 assert isinstance(data[1], Attrs) |
c9a084ffaee6
Fix case where attributes weren't properly wrapped in an `Attrs` instance if one or more of them were translated by the I18n filter, potentially breaking things further down the chain. Closes #162.
cmlenz
parents:
600
diff
changeset
|
104 |
594
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
105 def test_extract_without_text(self): |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
106 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
107 <p title="Bar">Foo</p> |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
108 ${ngettext("Singular", "Plural", num)} |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
109 </html>""") |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
110 translator = Translator(extract_text=False) |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
111 messages = list(translator.extract(tmpl.stream)) |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
112 self.assertEqual(1, len(messages)) |
858 | 113 self.assertEqual((3, 'ngettext', ('Singular', 'Plural', None), []), |
594
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
114 messages[0]) |
2bbaa61b328f
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
115 |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
116 def test_extract_plural_form(self): |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
117 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
118 ${ngettext("Singular", "Plural", num)} |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
119 </html>""") |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
120 translator = Translator() |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
121 messages = list(translator.extract(tmpl.stream)) |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
122 self.assertEqual(1, len(messages)) |
858 | 123 self.assertEqual((2, 'ngettext', ('Singular', 'Plural', None), []), |
565
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
124 messages[0]) |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
125 |
600
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
126 def test_extract_funky_plural_form(self): |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
127 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
128 ${ngettext(len(items), *widget.display_names)} |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
129 </html>""") |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
130 translator = Translator() |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
131 messages = list(translator.extract(tmpl.stream)) |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
132 self.assertEqual(1, len(messages)) |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
133 self.assertEqual((2, 'ngettext', (None, None), []), messages[0]) |
600
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
134 |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
135 def test_extract_gettext_with_unicode_string(self): |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
136 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
137 ${gettext("Grüße")} |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
138 </html>""") |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
139 translator = Translator() |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
140 messages = list(translator.extract(tmpl.stream)) |
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
141 self.assertEqual(1, len(messages)) |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
142 self.assertEqual((2, 'gettext', u'Gr\xfc\xdfe', []), messages[0]) |
600
23a4784203ae
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
143 |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
144 def test_extract_included_attribute_text(self): |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
145 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
146 <span title="Foo"></span> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
147 </html>""") |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
148 translator = Translator() |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
149 messages = list(translator.extract(tmpl.stream)) |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
150 self.assertEqual(1, len(messages)) |
858 | 151 self.assertEqual((2, None, 'Foo', []), messages[0]) |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
152 |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
153 def test_extract_attribute_expr(self): |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
154 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
155 <input type="submit" value="${_('Save')}" /> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
156 </html>""") |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
157 translator = Translator() |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
158 messages = list(translator.extract(tmpl.stream)) |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
159 self.assertEqual(1, len(messages)) |
858 | 160 self.assertEqual((2, '_', 'Save', []), messages[0]) |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
161 |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
162 def test_extract_non_included_attribute_interpolated(self): |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
163 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
164 <a href="#anchor_${num}">Foo</a> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
165 </html>""") |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
166 translator = Translator() |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
167 messages = list(translator.extract(tmpl.stream)) |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
168 self.assertEqual(1, len(messages)) |
858 | 169 self.assertEqual((2, None, 'Foo', []), messages[0]) |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
170 |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
171 def test_extract_text_from_sub(self): |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
172 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
173 <py:if test="foo">Foo</py:if> |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
174 </html>""") |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
175 translator = Translator() |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
176 messages = list(translator.extract(tmpl.stream)) |
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
177 self.assertEqual(1, len(messages)) |
858 | 178 self.assertEqual((2, None, 'Foo', []), messages[0]) |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
179 |
522
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
180 def test_ignore_tag_with_fixed_xml_lang(self): |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
181 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
182 <p xml:lang="en">(c) 2007 Edgewall Software</p> |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
183 </html>""") |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
184 translator = Translator() |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
185 messages = list(translator.extract(tmpl.stream)) |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
186 self.assertEqual(0, len(messages)) |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
187 |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
188 def test_extract_tag_with_variable_xml_lang(self): |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
189 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
190 <p xml:lang="${lang}">(c) 2007 Edgewall Software</p> |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
191 </html>""") |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
192 translator = Translator() |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
193 messages = list(translator.extract(tmpl.stream)) |
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
194 self.assertEqual(1, len(messages)) |
858 | 195 self.assertEqual((2, None, '(c) 2007 Edgewall Software', []), |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
196 messages[0]) |
522
082535e5087c
The I18n filter now skips the content of elements that have an `xml:lang` attribute with a fixed string value. Basically, `xml:lang` can now be used as a flag to mark specific sections as not needing localization.
cmlenz
parents:
485
diff
changeset
|
197 |
535
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
198 def test_ignore_attribute_with_expression(self): |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
199 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
200 <input type="submit" value="Reply" title="Reply to comment $num" /> |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
201 </html>""") |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
202 translator = Translator() |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
203 messages = list(translator.extract(tmpl.stream)) |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
204 self.assertEqual(0, len(messages)) |
35a413f3f1dd
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
205 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
206 def test_translate_with_translations_object(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
207 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
208 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
209 <p i18n:msg="" i18n:comment="As in foo bar">Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
210 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
211 translator = Translator(DummyTranslations({'Foo': 'Voh'})) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
212 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
213 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
214 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
215 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
216 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
217 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
218 class MsgDirectiveTestCase(unittest.TestCase): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
219 |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
220 def test_extract_i18n_msg(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
221 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
222 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
223 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
224 Please see <a href="help.html">Help</a> for details. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
225 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
226 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
227 translator = Translator() |
849 | 228 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
229 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
230 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
231 self.assertEqual('Please see [1:Help] for details.', messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
232 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
233 def test_translate_i18n_msg(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
234 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
235 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
236 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
237 Please see <a href="help.html">Help</a> for details. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
238 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
239 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
240 gettext = lambda s: u"Für Details siehe bitte [1:Hilfe]." |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
241 translator = Translator(gettext) |
849 | 242 translator.setup(tmpl) |
933 | 243 self.assertEqual(u"""<html> |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
244 <p>Für Details siehe bitte <a href="help.html">Hilfe</a>.</p> |
933 | 245 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
246 |
869
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
247 def test_extract_i18n_msg_nonewline(self): |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
248 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
249 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
250 <p i18n:msg="">Please see <a href="help.html">Help</a></p> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
251 </html>""") |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
252 translator = Translator() |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
253 tmpl.add_directives(Translator.NAMESPACE, translator) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
254 messages = list(translator.extract(tmpl.stream)) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
255 self.assertEqual(1, len(messages)) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
256 self.assertEqual('Please see [1:Help]', messages[0][2]) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
257 |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
258 def test_translate_i18n_msg_nonewline(self): |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
259 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
260 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
261 <p i18n:msg="">Please see <a href="help.html">Help</a></p> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
262 </html>""") |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
263 gettext = lambda s: u"Für Details siehe bitte [1:Hilfe]" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
264 translator = Translator(gettext) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
265 translator.setup(tmpl) |
933 | 266 self.assertEqual(u"""<html> |
869
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
267 <p>Für Details siehe bitte <a href="help.html">Hilfe</a></p> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
268 </html>""", tmpl.generate().render()) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
269 |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
270 def test_extract_i18n_msg_elt_nonewline(self): |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
271 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
272 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
273 <i18n:msg>Please see <a href="help.html">Help</a></i18n:msg> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
274 </html>""") |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
275 translator = Translator() |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
276 tmpl.add_directives(Translator.NAMESPACE, translator) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
277 messages = list(translator.extract(tmpl.stream)) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
278 self.assertEqual(1, len(messages)) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
279 self.assertEqual('Please see [1:Help]', messages[0][2]) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
280 |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
281 def test_translate_i18n_msg_elt_nonewline(self): |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
282 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
283 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
284 <i18n:msg>Please see <a href="help.html">Help</a></i18n:msg> |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
285 </html>""") |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
286 gettext = lambda s: u"Für Details siehe bitte [1:Hilfe]" |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
287 translator = Translator(gettext) |
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
288 translator.setup(tmpl) |
933 | 289 self.assertEqual(u"""<html> |
869
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
290 Für Details siehe bitte <a href="help.html">Hilfe</a> |
933 | 291 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) |
869
013623773357
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
292 |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
293 def test_extract_i18n_msg_with_attributes(self): |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
294 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
295 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
296 <p i18n:msg="" title="A helpful paragraph"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
297 Please see <a href="help.html" title="Click for help">Help</a> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
298 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
299 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
300 translator = Translator() |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
301 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
302 messages = list(translator.extract(tmpl.stream)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
303 self.assertEqual(3, len(messages)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
304 self.assertEqual('A helpful paragraph', messages[0][2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
305 self.assertEqual(3, messages[0][0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
306 self.assertEqual('Click for help', messages[1][2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
307 self.assertEqual(4, messages[1][0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
308 self.assertEqual('Please see [1:Help]', messages[2][2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
309 self.assertEqual(3, messages[2][0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
310 |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
311 def test_translate_i18n_msg_with_attributes(self): |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
312 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
313 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
314 <p i18n:msg="" title="A helpful paragraph"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
315 Please see <a href="help.html" title="Click for help">Help</a> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
316 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
317 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
318 translator = Translator(lambda msgid: { |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
319 'A helpful paragraph': 'Ein hilfreicher Absatz', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
320 'Click for help': u'Klicken für Hilfe', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
321 'Please see [1:Help]': u'Siehe bitte [1:Hilfe]' |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
322 }[msgid]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
323 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
324 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
325 <p title="Ein hilfreicher Absatz">Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a></p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
326 </html>""", tmpl.generate().render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
327 |
893 | 328 def test_extract_i18n_msg_with_dynamic_attributes(self): |
329 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
330 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
331 <p i18n:msg="" title="${_('A helpful paragraph')}"> | |
332 Please see <a href="help.html" title="${_('Click for help')}">Help</a> | |
333 </p> | |
334 </html>""") | |
335 translator = Translator() | |
336 translator.setup(tmpl) | |
337 messages = list(translator.extract(tmpl.stream)) | |
338 self.assertEqual(3, len(messages)) | |
339 self.assertEqual('A helpful paragraph', messages[0][2]) | |
340 self.assertEqual(3, messages[0][0]) | |
341 self.assertEqual('Click for help', messages[1][2]) | |
342 self.assertEqual(4, messages[1][0]) | |
343 self.assertEqual('Please see [1:Help]', messages[2][2]) | |
344 self.assertEqual(3, messages[2][0]) | |
345 | |
346 def test_translate_i18n_msg_with_dynamic_attributes(self): | |
347 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
348 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
349 <p i18n:msg="" title="${_('A helpful paragraph')}"> | |
350 Please see <a href="help.html" title="${_('Click for help')}">Help</a> | |
351 </p> | |
352 </html>""") | |
353 translator = Translator(lambda msgid: { | |
354 'A helpful paragraph': 'Ein hilfreicher Absatz', | |
355 'Click for help': u'Klicken für Hilfe', | |
356 'Please see [1:Help]': u'Siehe bitte [1:Hilfe]' | |
357 }[msgid]) | |
358 translator.setup(tmpl) | |
359 self.assertEqual(u"""<html> | |
360 <p title="Ein hilfreicher Absatz">Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a></p> | |
361 </html>""", tmpl.generate(_=translator.translate).render(encoding=None)) | |
362 | |
363 def test_extract_i18n_msg_as_element_with_attributes(self): | |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
364 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
365 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
366 <i18n:msg params=""> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
367 Please see <a href="help.html" title="Click for help">Help</a> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
368 </i18n:msg> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
369 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
370 translator = Translator() |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
371 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
372 messages = list(translator.extract(tmpl.stream)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
373 self.assertEqual(2, len(messages)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
374 self.assertEqual('Click for help', messages[0][2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
375 self.assertEqual(4, messages[0][0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
376 self.assertEqual('Please see [1:Help]', messages[1][2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
377 self.assertEqual(3, messages[1][0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
378 |
893 | 379 def test_translate_i18n_msg_as_element_with_attributes(self): |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
380 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
381 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
382 <i18n:msg params=""> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
383 Please see <a href="help.html" title="Click for help">Help</a> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
384 </i18n:msg> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
385 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
386 translator = Translator(lambda msgid: { |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
387 'Click for help': u'Klicken für Hilfe', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
388 'Please see [1:Help]': u'Siehe bitte [1:Hilfe]' |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
389 }[msgid]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
390 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
391 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
392 Siehe bitte <a href="help.html" title="Klicken für Hilfe">Hilfe</a> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
393 </html>""", tmpl.generate().render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
394 |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
395 def test_extract_i18n_msg_nested(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
396 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
397 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
398 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
399 Please see <a href="help.html"><em>Help</em> page</a> for details. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
400 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
401 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
402 translator = Translator() |
849 | 403 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
404 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
405 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
406 self.assertEqual('Please see [1:[2:Help] page] for details.', |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
407 messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
408 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
409 def test_translate_i18n_msg_nested(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
410 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
411 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
412 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
413 Please see <a href="help.html"><em>Help</em> page</a> for details. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
414 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
415 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
416 gettext = lambda s: u"Für Details siehe bitte [1:[2:Hilfeseite]]." |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
417 translator = Translator(gettext) |
849 | 418 translator.setup(tmpl) |
933 | 419 self.assertEqual(u"""<html> |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
420 <p>Für Details siehe bitte <a href="help.html"><em>Hilfeseite</em></a>.</p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
421 </html>""", tmpl.generate().render()) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
422 |
849 | 423 def test_extract_i18n_msg_label_with_nested_input(self): |
424 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
425 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
426 <div i18n:msg=""> | |
427 <label><input type="text" size="3" name="daysback" value="30" /> days back</label> | |
428 </div> | |
429 </html>""") | |
430 translator = Translator() | |
431 tmpl.add_directives(Translator.NAMESPACE, translator) | |
432 messages = list(translator.extract(tmpl.stream)) | |
433 self.assertEqual(1, len(messages)) | |
434 self.assertEqual('[1:[2:] days back]', | |
435 messages[0][2]) | |
436 | |
437 def test_translate_i18n_msg_label_with_nested_input(self): | |
438 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
439 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
440 <div i18n:msg=""> | |
441 <label><input type="text" size="3" name="daysback" value="30" /> foo bar</label> | |
442 </div> | |
443 </html>""") | |
444 gettext = lambda s: "[1:[2:] foo bar]" | |
445 translator = Translator(gettext) | |
446 translator.setup(tmpl) | |
447 self.assertEqual("""<html> | |
448 <div><label><input type="text" size="3" name="daysback" value="30"/> foo bar</label></div> | |
449 </html>""", tmpl.generate().render()) | |
450 | |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
451 def test_extract_i18n_msg_empty(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
452 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
453 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
454 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
455 Show me <input type="text" name="num" /> entries per page. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
456 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
457 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
458 translator = Translator() |
849 | 459 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
460 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
461 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
462 self.assertEqual('Show me [1:] entries per page.', messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
463 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
464 def test_translate_i18n_msg_empty(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
465 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
466 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
467 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
468 Show me <input type="text" name="num" /> entries per page. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
469 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
470 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
471 gettext = lambda s: u"[1:] Einträge pro Seite anzeigen." |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
472 translator = Translator(gettext) |
849 | 473 translator.setup(tmpl) |
933 | 474 self.assertEqual(u"""<html> |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
475 <p><input type="text" name="num"/> Einträge pro Seite anzeigen.</p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
476 </html>""", tmpl.generate().render()) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
477 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
478 def test_extract_i18n_msg_multiple(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
479 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
480 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
481 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
482 Please see <a href="help.html">Help</a> for <em>details</em>. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
483 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
484 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
485 translator = Translator() |
849 | 486 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
487 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
488 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
489 self.assertEqual('Please see [1:Help] for [2:details].', messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
490 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
491 def test_translate_i18n_msg_multiple(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
492 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
493 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
494 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
495 Please see <a href="help.html">Help</a> for <em>details</em>. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
496 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
497 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
498 gettext = lambda s: u"Für [2:Details] siehe bitte [1:Hilfe]." |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
499 translator = Translator(gettext) |
849 | 500 translator.setup(tmpl) |
933 | 501 self.assertEqual(u"""<html> |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
502 <p>Für <em>Details</em> siehe bitte <a href="help.html">Hilfe</a>.</p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
503 </html>""", tmpl.generate().render()) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
504 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
505 def test_extract_i18n_msg_multiple_empty(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
506 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
507 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
508 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
509 Show me <input type="text" name="num" /> entries per page, starting at page <input type="text" name="num" />. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
510 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
511 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
512 translator = Translator() |
849 | 513 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
514 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
515 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
516 self.assertEqual('Show me [1:] entries per page, starting at page [2:].', |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
517 messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
518 |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
519 def test_translate_i18n_msg_multiple_empty(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
520 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
521 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
522 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
523 Show me <input type="text" name="num" /> entries per page, starting at page <input type="text" name="num" />. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
524 </p> |
933 | 525 </html>""", encoding='utf-8') |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
526 gettext = lambda s: u"[1:] Einträge pro Seite, beginnend auf Seite [2:]." |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
527 translator = Translator(gettext) |
849 | 528 translator.setup(tmpl) |
933 | 529 self.assertEqual(u"""<html> |
530 <p><input type="text" name="num"/> Eintr\u00E4ge pro Seite, beginnend auf Seite <input type="text" name="num"/>.</p> | |
531 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) | |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
532 |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
533 def test_extract_i18n_msg_with_param(self): |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
534 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
535 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
536 <p i18n:msg="name"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
537 Hello, ${user.name}! |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
538 </p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
539 </html>""") |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
540 translator = Translator() |
849 | 541 tmpl.add_directives(Translator.NAMESPACE, translator) |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
542 messages = list(translator.extract(tmpl.stream)) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
543 self.assertEqual(1, len(messages)) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
544 self.assertEqual('Hello, %(name)s!', messages[0][2]) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
545 |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
546 def test_translate_i18n_msg_with_param(self): |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
547 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
548 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
549 <p i18n:msg="name"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
550 Hello, ${user.name}! |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
551 </p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
552 </html>""") |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
553 gettext = lambda s: u"Hallo, %(name)s!" |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
554 translator = Translator(gettext) |
849 | 555 translator.setup(tmpl) |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
556 self.assertEqual("""<html> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
557 <p>Hallo, Jim!</p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
558 </html>""", tmpl.generate(user=dict(name='Jim')).render()) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
559 |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
560 def test_translate_i18n_msg_with_param_reordered(self): |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
561 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
562 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
563 <p i18n:msg="name"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
564 Hello, ${user.name}! |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
565 </p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
566 </html>""") |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
567 gettext = lambda s: u"%(name)s, sei gegrüßt!" |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
568 translator = Translator(gettext) |
849 | 569 translator.setup(tmpl) |
933 | 570 self.assertEqual(u"""<html> |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
571 <p>Jim, sei gegrüßt!</p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
572 </html>""", tmpl.generate(user=dict(name='Jim')).render()) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
573 |
785
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
574 def test_translate_i18n_msg_with_attribute_param(self): |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
575 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
576 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
577 <p i18n:msg=""> |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
578 Hello, <a href="#${anchor}">dude</a>! |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
579 </p> |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
580 </html>""") |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
581 gettext = lambda s: u"Sei gegrüßt, [1:Alter]!" |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
582 translator = Translator(gettext) |
849 | 583 translator.setup(tmpl) |
933 | 584 self.assertEqual(u"""<html> |
785
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
585 <p>Sei gegrüßt, <a href="#42">Alter</a>!</p> |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
586 </html>""", tmpl.generate(anchor='42').render()) |
36fb0a57fe74
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
587 |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
588 def test_extract_i18n_msg_with_two_params(self): |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
589 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
590 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
591 <p i18n:msg="name, time"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
592 Posted by ${post.author} at ${entry.time.strftime('%H:%m')} |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
593 </p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
594 </html>""") |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
595 translator = Translator() |
849 | 596 tmpl.add_directives(Translator.NAMESPACE, translator) |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
597 messages = list(translator.extract(tmpl.stream)) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
598 self.assertEqual(1, len(messages)) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
599 self.assertEqual('Posted by %(name)s at %(time)s', messages[0][2]) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
600 |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
601 def test_translate_i18n_msg_with_two_params(self): |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
602 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
603 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
604 <p i18n:msg="name, time"> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
605 Written by ${entry.author} at ${entry.time.strftime('%H:%M')} |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
606 </p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
607 </html>""") |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
608 gettext = lambda s: u"%(name)s schrieb dies um %(time)s" |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
609 translator = Translator(gettext) |
849 | 610 translator.setup(tmpl) |
776
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
611 entry = { |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
612 'author': 'Jim', |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
613 'time': datetime(2008, 4, 1, 14, 30) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
614 } |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
615 self.assertEqual("""<html> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
616 <p>Jim schrieb dies um 14:30</p> |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
617 </html>""", tmpl.generate(entry=entry).render()) |
ddb58d74c8ee
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
618 |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
619 def test_extract_i18n_msg_with_directive(self): |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
620 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
621 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
622 <p i18n:msg=""> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
623 Show me <input type="text" name="num" py:attrs="{'value': x}" /> entries per page. |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
624 </p> |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
625 </html>""") |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
626 translator = Translator() |
849 | 627 tmpl.add_directives(Translator.NAMESPACE, translator) |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
628 messages = list(translator.extract(tmpl.stream)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
629 self.assertEqual(1, len(messages)) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
630 self.assertEqual('Show me [1:] entries per page.', messages[0][2]) |
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
631 |
849 | 632 def test_translate_i18n_msg_with_directive(self): |
633 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
634 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
635 <p i18n:msg=""> | |
636 Show me <input type="text" name="num" py:attrs="{'value': 'x'}" /> entries per page. | |
637 </p> | |
638 </html>""") | |
639 gettext = lambda s: u"[1:] Einträge pro Seite anzeigen." | |
640 translator = Translator(gettext) | |
641 translator.setup(tmpl) | |
933 | 642 self.assertEqual(u"""<html> |
849 | 643 <p><input type="text" name="num" value="x"/> Einträge pro Seite anzeigen.</p> |
644 </html>""", tmpl.generate().render()) | |
560
7e83be231f96
Start implementation of advanced I18n as dicussed in #129 and the MailingList. This is not complete yet, but many simple cases work okay.
cmlenz
parents:
549
diff
changeset
|
645 |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
646 def test_extract_i18n_msg_with_comment(self): |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
647 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
648 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
849 | 649 <p i18n:comment="As in foo bar" i18n:msg="">Foo</p> |
650 </html>""") | |
651 translator = Translator() | |
652 tmpl.add_directives(Translator.NAMESPACE, translator) | |
653 messages = list(translator.extract(tmpl.stream)) | |
654 self.assertEqual(1, len(messages)) | |
858 | 655 self.assertEqual((3, None, 'Foo', ['As in foo bar']), messages[0]) |
849 | 656 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
657 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
658 <p i18n:msg="" i18n:comment="As in foo bar">Foo</p> |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
659 </html>""") |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
660 translator = Translator() |
849 | 661 tmpl.add_directives(Translator.NAMESPACE, translator) |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
662 messages = list(translator.extract(tmpl.stream)) |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
663 self.assertEqual(1, len(messages)) |
858 | 664 self.assertEqual((3, None, 'Foo', ['As in foo bar']), messages[0]) |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
665 |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
666 def test_translate_i18n_msg_with_comment(self): |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
667 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
668 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
669 <p i18n:msg="" i18n:comment="As in foo bar">Foo</p> |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
670 </html>""") |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
671 gettext = lambda s: u"Voh" |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
672 translator = Translator(gettext) |
849 | 673 translator.setup(tmpl) |
787
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
674 self.assertEqual("""<html> |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
675 <p>Voh</p> |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
676 </html>""", tmpl.generate().render()) |
d7366797440f
Add support for supplying comments on localizable messages in the i18n filter. Based on patch by Pedro Algarvio on #129.
cmlenz
parents:
785
diff
changeset
|
677 |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
678 def test_extract_i18n_msg_with_attr(self): |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
679 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
680 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
681 <p i18n:msg="" title="Foo bar">Foo</p> |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
682 </html>""") |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
683 translator = Translator() |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
684 messages = list(translator.extract(tmpl.stream)) |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
685 self.assertEqual(2, len(messages)) |
858 | 686 self.assertEqual((3, None, 'Foo bar', []), messages[0]) |
687 self.assertEqual((3, None, 'Foo', []), messages[1]) | |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
688 |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
689 def test_translate_i18n_msg_with_attr(self): |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
690 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
691 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
692 <p i18n:msg="" title="Foo bar">Foo</p> |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
693 </html>""") |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
694 gettext = lambda s: u"Voh" |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
695 translator = Translator(DummyTranslations({ |
858 | 696 'Foo': 'Voh', |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
697 'Foo bar': u'Voh bär' |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
698 })) |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
699 tmpl.filters.insert(0, translator) |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
700 tmpl.add_directives(Translator.NAMESPACE, translator) |
933 | 701 self.assertEqual(u"""<html> |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
702 <p title="Voh bär">Voh</p> |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
703 </html>""", tmpl.generate().render()) |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
704 |
849 | 705 def test_translate_i18n_msg_and_py_strip_directives(self): |
706 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
707 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
708 <p i18n:msg="" py:strip="">Foo</p> | |
709 <p py:strip="" i18n:msg="">Foo</p> | |
710 </html>""") | |
711 translator = Translator(DummyTranslations({'Foo': 'Voh'})) | |
712 translator.setup(tmpl) | |
713 self.assertEqual("""<html> | |
714 Voh | |
715 Voh | |
716 </html>""", tmpl.generate().render()) | |
717 | |
718 def test_i18n_msg_ticket_300_extract(self): | |
719 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
720 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
721 <i18n:msg params="date, author"> | |
722 Changed ${ '10/12/2008' } ago by ${ 'me, the author' } | |
723 </i18n:msg> | |
724 </html>""") | |
725 translator = Translator() | |
726 tmpl.add_directives(Translator.NAMESPACE, translator) | |
727 messages = list(translator.extract(tmpl.stream)) | |
728 self.assertEqual(1, len(messages)) | |
729 self.assertEqual( | |
858 | 730 (3, None, 'Changed %(date)s ago by %(author)s', []), messages[0] |
849 | 731 ) |
732 | |
733 def test_i18n_msg_ticket_300_translate(self): | |
734 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
735 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
736 <i18n:msg params="date, author"> | |
737 Changed ${ date } ago by ${ author } | |
738 </i18n:msg> | |
739 </html>""") | |
740 translations = DummyTranslations({ | |
858 | 741 'Changed %(date)s ago by %(author)s': u'Modificado à %(date)s por %(author)s' |
849 | 742 }) |
743 translator = Translator(translations) | |
744 translator.setup(tmpl) | |
933 | 745 self.assertEqual(u"""<html> |
849 | 746 Modificado à um dia por Pedro |
933 | 747 </html>""".encode('utf-8'), tmpl.generate(date='um dia', author="Pedro").render(encoding='utf-8')) |
849 | 748 |
749 | |
750 def test_i18n_msg_ticket_251_extract(self): | |
751 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
752 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
753 <p i18n:msg=""><tt><b>Translation[ 0 ]</b>: <em>One coin</em></tt></p> | |
754 </html>""") | |
755 translator = Translator() | |
756 tmpl.add_directives(Translator.NAMESPACE, translator) | |
757 messages = list(translator.extract(tmpl.stream)) | |
758 self.assertEqual(1, len(messages)) | |
759 self.assertEqual( | |
760 (3, None, u'[1:[2:Translation\\[\xa00\xa0\\]]: [3:One coin]]', []), messages[0] | |
761 ) | |
762 | |
763 def test_i18n_msg_ticket_251_translate(self): | |
764 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
765 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
766 <p i18n:msg=""><tt><b>Translation[ 0 ]</b>: <em>One coin</em></tt></p> | |
767 </html>""") | |
768 translations = DummyTranslations({ | |
769 u'[1:[2:Translation\\[\xa00\xa0\\]]: [3:One coin]]': | |
770 u'[1:[2:Trandução\\[\xa00\xa0\\]]: [3:Uma moeda]]' | |
771 }) | |
772 translator = Translator(translations) | |
773 translator.setup(tmpl) | |
933 | 774 self.assertEqual(u"""<html> |
849 | 775 <p><tt><b>Trandução[ 0 ]</b>: <em>Uma moeda</em></tt></p> |
933 | 776 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) |
849 | 777 |
778 def test_extract_i18n_msg_with_other_directives_nested(self): | |
779 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
780 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
781 <p i18n:msg="" py:with="q = quote_plus(message[:80])">Before you do that, though, please first try | |
782 <strong><a href="${trac.homepage}search?ticket=yes&noquickjump=1&q=$q">searching</a> | |
783 for similar issues</strong>, as it is quite likely that this problem | |
784 has been reported before. For questions about installation | |
785 and configuration of Trac, please try the | |
786 <a href="${trac.homepage}wiki/MailingList">mailing list</a> | |
787 instead of filing a ticket. | |
788 </p> | |
789 </html>""") | |
790 translator = Translator() | |
791 translator.setup(tmpl) | |
792 messages = list(translator.extract(tmpl.stream)) | |
793 self.assertEqual(1, len(messages)) | |
794 self.assertEqual( | |
858 | 795 'Before you do that, though, please first try\n ' |
796 '[1:[2:searching]\n for similar issues], as it is ' | |
797 'quite likely that this problem\n has been reported ' | |
798 'before. For questions about installation\n and ' | |
799 'configuration of Trac, please try the\n ' | |
800 '[3:mailing list]\n instead of filing a ticket.', | |
849 | 801 messages[0][2] |
802 ) | |
803 | |
804 def test_translate_i18n_msg_with_other_directives_nested(self): | |
805 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
806 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
807 <p i18n:msg="">Before you do that, though, please first try | |
808 <strong><a href="${trac.homepage}search?ticket=yes&noquickjump=1&q=q">searching</a> | |
809 for similar issues</strong>, as it is quite likely that this problem | |
810 has been reported before. For questions about installation | |
811 and configuration of Trac, please try the | |
812 <a href="${trac.homepage}wiki/MailingList">mailing list</a> | |
813 instead of filing a ticket. | |
814 </p> | |
815 </html>""") | |
816 translations = DummyTranslations({ | |
858 | 817 'Before you do that, though, please first try\n ' |
818 '[1:[2:searching]\n for similar issues], as it is ' | |
819 'quite likely that this problem\n has been reported ' | |
820 'before. For questions about installation\n and ' | |
821 'configuration of Trac, please try the\n ' | |
822 '[3:mailing list]\n instead of filing a ticket.': | |
849 | 823 u'Antes de o fazer, porém,\n ' |
824 u'[1:por favor tente [2:procurar]\n por problemas semelhantes], uma vez que ' | |
825 u'é muito provável que este problema\n já tenha sido reportado ' | |
826 u'anteriormente. Para questões relativas à instalação\n e ' | |
827 u'configuração do Trac, por favor tente a\n ' | |
828 u'[3:mailing list]\n em vez de criar um assunto.' | |
829 }) | |
830 translator = Translator(translations) | |
831 translator.setup(tmpl) | |
832 messages = list(translator.extract(tmpl.stream)) | |
833 self.assertEqual(1, len(messages)) | |
834 ctx = Context() | |
835 ctx.push({'trac': {'homepage': 'http://trac.edgewall.org/'}}) | |
933 | 836 self.assertEqual(u"""<html> |
849 | 837 <p>Antes de o fazer, porém, |
838 <strong>por favor tente <a href="http://trac.edgewall.org/search?ticket=yes&noquickjump=1&q=q">procurar</a> | |
839 por problemas semelhantes</strong>, uma vez que é muito provável que este problema | |
840 já tenha sido reportado anteriormente. Para questões relativas à instalação | |
841 e configuração do Trac, por favor tente a | |
842 <a href="http://trac.edgewall.org/wiki/MailingList">mailing list</a> | |
843 em vez de criar um assunto.</p> | |
844 </html>""", tmpl.generate(ctx).render()) | |
845 | |
846 def test_i18n_msg_with_other_nested_directives_with_reordered_content(self): | |
847 # See: http://genshi.edgewall.org/ticket/300#comment:10 | |
848 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
849 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
850 <p py:if="not editable" class="hint" i18n:msg=""> | |
851 <strong>Note:</strong> This repository is defined in | |
852 <code><a href="${ 'href.wiki(TracIni)' }">trac.ini</a></code> | |
853 and cannot be edited on this page. | |
854 </p> | |
855 </html>""") | |
856 translations = DummyTranslations({ | |
858 | 857 '[1:Note:] This repository is defined in\n ' |
858 '[2:[3:trac.ini]]\n and cannot be edited on this page.': | |
849 | 859 u'[1:Nota:] Este repositório está definido em \n ' |
860 u'[2:[3:trac.ini]]\n e não pode ser editado nesta página.', | |
861 }) | |
862 translator = Translator(translations) | |
863 translator.setup(tmpl) | |
864 messages = list(translator.extract(tmpl.stream)) | |
865 self.assertEqual(1, len(messages)) | |
866 self.assertEqual( | |
858 | 867 '[1:Note:] This repository is defined in\n ' |
868 '[2:[3:trac.ini]]\n and cannot be edited on this page.', | |
849 | 869 messages[0][2] |
870 ) | |
933 | 871 self.assertEqual(u"""<html> |
849 | 872 <p class="hint"><strong>Nota:</strong> Este repositório está definido em |
873 <code><a href="href.wiki(TracIni)">trac.ini</a></code> | |
874 e não pode ser editado nesta página.</p> | |
933 | 875 </html>""".encode('utf-8'), tmpl.generate(editable=False).render(encoding='utf-8')) |
849 | 876 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
877 def test_extract_i18n_msg_with_py_strip(self): |
849 | 878 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
879 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
880 <p i18n:msg="" py:strip=""> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
881 Please see <a href="help.html">Help</a> for details. |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
882 </p> |
849 | 883 </html>""") |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
884 translator = Translator() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
885 tmpl.add_directives(Translator.NAMESPACE, translator) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
886 messages = list(translator.extract(tmpl.stream)) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
887 self.assertEqual(1, len(messages)) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
888 self.assertEqual((3, None, 'Please see [1:Help] for details.', []), |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
889 messages[0]) |
849 | 890 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
891 def test_extract_i18n_msg_with_py_strip_and_comment(self): |
849 | 892 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
893 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
894 <p i18n:msg="" py:strip="" i18n:comment="Foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
895 Please see <a href="help.html">Help</a> for details. |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
896 </p> |
849 | 897 </html>""") |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
898 translator = Translator() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
899 tmpl.add_directives(Translator.NAMESPACE, translator) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
900 messages = list(translator.extract(tmpl.stream)) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
901 self.assertEqual(1, len(messages)) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
902 self.assertEqual((3, None, 'Please see [1:Help] for details.', |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
903 ['Foo']), messages[0]) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
904 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
905 def test_translate_i18n_msg_and_comment_with_py_strip_directives(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
906 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
907 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
908 <p i18n:msg="" i18n:comment="As in foo bar" py:strip="">Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
909 <p py:strip="" i18n:msg="" i18n:comment="As in foo bar">Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
910 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
911 translator = Translator(DummyTranslations({'Foo': 'Voh'})) |
849 | 912 translator.setup(tmpl) |
913 self.assertEqual("""<html> | |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
914 Voh |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
915 Voh |
849 | 916 </html>""", tmpl.generate().render()) |
917 | |
952
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
918 def test_translate_i18n_msg_ticket_404(self): |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
919 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
920 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
921 <p i18n:msg="first,second"> |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
922 $first <span>$second</span> KEPT <span>Inside a tag</span> tail |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
923 </p></html>""") |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
924 translator = Translator(DummyTranslations()) |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
925 translator.setup(tmpl) |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
926 self.assertEqual("""<html> |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
927 <p>FIRST <span>SECOND</span> KEPT <span>Inside a tag</span> tail""" |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
928 """</p></html>""", |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
929 tmpl.generate(first="FIRST", second="SECOND").render()) |
7f8b4df4f862
Handle multiple events between or an either side of start and end tags in translated messages -- fixes #404 (bug no longer found).
hodgestar
parents:
933
diff
changeset
|
930 |
1017
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
931 def test_translate_i18n_msg_ticket_404_regression(self): |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
932 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
933 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
934 <h1 i18n:msg="name">text <a>$name</a></h1> |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
935 </html>""") |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
936 gettext = lambda s: u'head [1:%(name)s] tail' |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
937 translator = Translator(gettext) |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
938 translator.setup(tmpl) |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
939 self.assertEqual("""<html> |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
940 <h1>head <a>NAME</a> tail</h1> |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
941 </html>""", tmpl.generate(name='NAME').render()) |
9c4fafa85f4a
Merge r1242 from trunk (fix handling of case where a translation has text after a closing tag).
hodgestar
parents:
952
diff
changeset
|
942 |
849 | 943 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
944 class ChooseDirectiveTestCase(unittest.TestCase): |
849 | 945 |
946 def test_translate_i18n_choose_as_attribute(self): | |
947 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
948 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
949 <div i18n:choose="one"> | |
950 <p i18n:singular="">FooBar</p> | |
951 <p i18n:plural="">FooBars</p> | |
952 </div> | |
953 <div i18n:choose="two"> | |
954 <p i18n:singular="">FooBar</p> | |
955 <p i18n:plural="">FooBars</p> | |
956 </div> | |
957 </html>""") | |
958 translations = DummyTranslations() | |
959 translator = Translator(translations) | |
960 translator.setup(tmpl) | |
961 self.assertEqual("""<html> | |
962 <div> | |
963 <p>FooBar</p> | |
964 </div> | |
965 <div> | |
966 <p>FooBars</p> | |
967 </div> | |
968 </html>""", tmpl.generate(one=1, two=2).render()) | |
969 | |
970 def test_translate_i18n_choose_as_directive(self): | |
971 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
972 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
973 <i18n:choose numeral="two"> | |
974 <p i18n:singular="">FooBar</p> | |
975 <p i18n:plural="">FooBars</p> | |
976 </i18n:choose> | |
977 <i18n:choose numeral="one"> | |
978 <p i18n:singular="">FooBar</p> | |
979 <p i18n:plural="">FooBars</p> | |
980 </i18n:choose> | |
981 </html>""") | |
982 translations = DummyTranslations() | |
983 translator = Translator(translations) | |
984 translator.setup(tmpl) | |
985 self.assertEqual("""<html> | |
986 <p>FooBars</p> | |
987 <p>FooBar</p> | |
988 </html>""", tmpl.generate(one=1, two=2).render()) | |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
989 |
873
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
990 def test_translate_i18n_choose_as_directive_singular_and_plural_with_strip(self): |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
991 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
992 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
993 <i18n:choose numeral="two"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
994 <p i18n:singular="" py:strip="">FooBar Singular with Strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
995 <p i18n:plural="">FooBars Plural without Strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
996 </i18n:choose> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
997 <i18n:choose numeral="two"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
998 <p i18n:singular="">FooBar singular without strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
999 <p i18n:plural="" py:strip="">FooBars plural with strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1000 </i18n:choose> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1001 <i18n:choose numeral="one"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1002 <p i18n:singular="">FooBar singular without strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1003 <p i18n:plural="" py:strip="">FooBars plural with strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1004 </i18n:choose> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1005 <i18n:choose numeral="one"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1006 <p i18n:singular="" py:strip="">FooBar singular with strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1007 <p i18n:plural="">FooBars plural without strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1008 </i18n:choose> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1009 </html>""") |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1010 translations = DummyTranslations() |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1011 translator = Translator(translations) |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1012 translator.setup(tmpl) |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1013 self.assertEqual("""<html> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1014 <p>FooBars Plural without Strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1015 FooBars plural with strip |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1016 <p>FooBar singular without strip</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1017 FooBar singular with strip |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1018 </html>""", tmpl.generate(one=1, two=2).render()) |
849 | 1019 |
871
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1020 def test_translate_i18n_choose_plural_singular_as_directive(self): |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1021 # Ticket 371 |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1022 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1023 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1024 <i18n:choose numeral="two"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1025 <i18n:singular>FooBar</i18n:singular> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1026 <i18n:plural>FooBars</i18n:plural> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1027 </i18n:choose> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1028 <i18n:choose numeral="one"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1029 <i18n:singular>FooBar</i18n:singular> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1030 <i18n:plural>FooBars</i18n:plural> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1031 </i18n:choose> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1032 </html>""") |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1033 translations = DummyTranslations({ |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1034 ('FooBar', 0): 'FuBar', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1035 ('FooBars', 1): 'FuBars', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1036 'FooBar': 'FuBar', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1037 'FooBars': 'FuBars', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1038 }) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1039 translator = Translator(translations) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1040 translator.setup(tmpl) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1041 self.assertEqual("""<html> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1042 FuBars |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1043 FuBar |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1044 </html>""", tmpl.generate(one=1, two=2).render()) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1045 |
849 | 1046 def test_translate_i18n_choose_as_attribute_with_params(self): |
1047 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1048 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1049 <div i18n:choose="two; fname, lname"> | |
1050 <p i18n:singular="">Foo $fname $lname</p> | |
1051 <p i18n:plural="">Foos $fname $lname</p> | |
1052 </div> | |
1053 </html>""") | |
1054 translations = DummyTranslations({ | |
1055 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1056 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1057 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1058 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1059 }) | |
1060 translator = Translator(translations) | |
1061 translator.setup(tmpl) | |
1062 self.assertEqual("""<html> | |
1063 <div> | |
1064 <p>Vohs John Doe</p> | |
1065 </div> | |
1066 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1067 | |
1068 def test_translate_i18n_choose_as_attribute_with_params_and_domain_as_param(self): | |
1069 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1070 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1071 i18n:domain="foo"> | |
1072 <div i18n:choose="two; fname, lname"> | |
1073 <p i18n:singular="">Foo $fname $lname</p> | |
1074 <p i18n:plural="">Foos $fname $lname</p> | |
1075 </div> | |
1076 </html>""") | |
1077 translations = DummyTranslations() | |
1078 translations.add_domain('foo', { | |
1079 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1080 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1081 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1082 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1083 }) | |
1084 translator = Translator(translations) | |
1085 translator.setup(tmpl) | |
1086 self.assertEqual("""<html> | |
1087 <div> | |
1088 <p>Vohs John Doe</p> | |
1089 </div> | |
1090 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1091 | |
1092 def test_translate_i18n_choose_as_directive_with_params(self): | |
1093 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1094 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1095 <i18n:choose numeral="two" params="fname, lname"> | |
1096 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1097 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1098 </i18n:choose> | |
1099 <i18n:choose numeral="one" params="fname, lname"> | |
1100 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1101 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1102 </i18n:choose> | |
1103 </html>""") | |
1104 translations = DummyTranslations({ | |
1105 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1106 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1107 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1108 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1109 }) | |
1110 translator = Translator(translations) | |
1111 translator.setup(tmpl) | |
1112 self.assertEqual("""<html> | |
1113 <p>Vohs John Doe</p> | |
1114 <p>Voh John Doe</p> | |
1115 </html>""", tmpl.generate(one=1, two=2, | |
1116 fname='John', lname='Doe').render()) | |
1117 | |
1118 def test_translate_i18n_choose_as_directive_with_params_and_domain_as_directive(self): | |
1119 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1120 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1121 <i18n:domain name="foo"> | |
1122 <i18n:choose numeral="two" params="fname, lname"> | |
1123 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1124 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1125 </i18n:choose> | |
1126 </i18n:domain> | |
1127 <i18n:choose numeral="one" params="fname, lname"> | |
1128 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1129 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1130 </i18n:choose> | |
1131 </html>""") | |
1132 translations = DummyTranslations() | |
1133 translations.add_domain('foo', { | |
1134 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1135 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1136 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1137 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1138 }) | |
1139 translator = Translator(translations) | |
1140 translator.setup(tmpl) | |
1141 self.assertEqual("""<html> | |
1142 <p>Vohs John Doe</p> | |
1143 <p>Foo John Doe</p> | |
1144 </html>""", tmpl.generate(one=1, two=2, | |
1145 fname='John', lname='Doe').render()) | |
1146 | |
1147 def test_extract_i18n_choose_as_attribute(self): | |
1148 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1149 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1150 <div i18n:choose="one"> | |
1151 <p i18n:singular="">FooBar</p> | |
1152 <p i18n:plural="">FooBars</p> | |
1153 </div> | |
1154 <div i18n:choose="two"> | |
1155 <p i18n:singular="">FooBar</p> | |
1156 <p i18n:plural="">FooBars</p> | |
1157 </div> | |
1158 </html>""") | |
1159 translator = Translator() | |
1160 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1161 messages = list(translator.extract(tmpl.stream)) | |
1162 self.assertEqual(2, len(messages)) | |
858 | 1163 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
1164 self.assertEqual((7, 'ngettext', ('FooBar', 'FooBars'), []), messages[1]) | |
849 | 1165 |
1166 def test_extract_i18n_choose_as_directive(self): | |
1167 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1168 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1169 <i18n:choose numeral="two"> | |
1170 <p i18n:singular="">FooBar</p> | |
1171 <p i18n:plural="">FooBars</p> | |
1172 </i18n:choose> | |
1173 <i18n:choose numeral="one"> | |
1174 <p i18n:singular="">FooBar</p> | |
1175 <p i18n:plural="">FooBars</p> | |
1176 </i18n:choose> | |
1177 </html>""") | |
1178 translator = Translator() | |
1179 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1180 messages = list(translator.extract(tmpl.stream)) | |
1181 self.assertEqual(2, len(messages)) | |
858 | 1182 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
1183 self.assertEqual((7, 'ngettext', ('FooBar', 'FooBars'), []), messages[1]) | |
849 | 1184 |
1185 def test_extract_i18n_choose_as_attribute_with_params(self): | |
1186 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1187 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1188 <div i18n:choose="two; fname, lname"> | |
1189 <p i18n:singular="">Foo $fname $lname</p> | |
1190 <p i18n:plural="">Foos $fname $lname</p> | |
1191 </div> | |
1192 </html>""") | |
1193 translator = Translator() | |
1194 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1195 messages = list(translator.extract(tmpl.stream)) | |
1196 self.assertEqual(1, len(messages)) | |
858 | 1197 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1198 'Foos %(fname)s %(lname)s'), []), | |
849 | 1199 messages[0]) |
1200 | |
1201 def test_extract_i18n_choose_as_attribute_with_params_and_domain_as_param(self): | |
1202 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1203 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1204 i18n:domain="foo"> | |
1205 <div i18n:choose="two; fname, lname"> | |
1206 <p i18n:singular="">Foo $fname $lname</p> | |
1207 <p i18n:plural="">Foos $fname $lname</p> | |
1208 </div> | |
1209 </html>""") | |
1210 translator = Translator() | |
1211 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1212 messages = list(translator.extract(tmpl.stream)) | |
1213 self.assertEqual(1, len(messages)) | |
858 | 1214 self.assertEqual((4, 'ngettext', ('Foo %(fname)s %(lname)s', |
1215 'Foos %(fname)s %(lname)s'), []), | |
849 | 1216 messages[0]) |
1217 | |
1218 def test_extract_i18n_choose_as_directive_with_params(self): | |
1219 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1220 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1221 <i18n:choose numeral="two" params="fname, lname"> | |
1222 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1223 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1224 </i18n:choose> | |
1225 <i18n:choose numeral="one" params="fname, lname"> | |
1226 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1227 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1228 </i18n:choose> | |
1229 </html>""") | |
1230 translator = Translator() | |
1231 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1232 messages = list(translator.extract(tmpl.stream)) | |
1233 self.assertEqual(2, len(messages)) | |
858 | 1234 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1235 'Foos %(fname)s %(lname)s'), []), | |
849 | 1236 messages[0]) |
858 | 1237 self.assertEqual((7, 'ngettext', ('Foo %(fname)s %(lname)s', |
1238 'Foos %(fname)s %(lname)s'), []), | |
849 | 1239 messages[1]) |
1240 | |
1241 def test_extract_i18n_choose_as_directive_with_params_and_domain_as_directive(self): | |
1242 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1243 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1244 <i18n:domain name="foo"> | |
1245 <i18n:choose numeral="two" params="fname, lname"> | |
1246 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1247 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1248 </i18n:choose> | |
1249 </i18n:domain> | |
1250 <i18n:choose numeral="one" params="fname, lname"> | |
1251 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1252 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1253 </i18n:choose> | |
1254 </html>""") | |
1255 translator = Translator() | |
1256 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1257 messages = list(translator.extract(tmpl.stream)) | |
1258 self.assertEqual(2, len(messages)) | |
858 | 1259 self.assertEqual((4, 'ngettext', ('Foo %(fname)s %(lname)s', |
1260 'Foos %(fname)s %(lname)s'), []), | |
849 | 1261 messages[0]) |
858 | 1262 self.assertEqual((9, 'ngettext', ('Foo %(fname)s %(lname)s', |
1263 'Foos %(fname)s %(lname)s'), []), | |
849 | 1264 messages[1]) |
1265 | |
1266 def test_extract_i18n_choose_as_attribute_with_params_and_comment(self): | |
1267 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1268 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1269 <div i18n:choose="two; fname, lname" i18n:comment="As in Foo Bar"> | |
1270 <p i18n:singular="">Foo $fname $lname</p> | |
1271 <p i18n:plural="">Foos $fname $lname</p> | |
1272 </div> | |
1273 </html>""") | |
1274 translator = Translator() | |
1275 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1276 messages = list(translator.extract(tmpl.stream)) | |
1277 self.assertEqual(1, len(messages)) | |
858 | 1278 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1279 'Foos %(fname)s %(lname)s'), | |
1280 ['As in Foo Bar']), | |
849 | 1281 messages[0]) |
1282 | |
1283 def test_extract_i18n_choose_as_directive_with_params_and_comment(self): | |
1284 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1285 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1286 <i18n:choose numeral="two" params="fname, lname" i18n:comment="As in Foo Bar"> | |
1287 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1288 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1289 </i18n:choose> | |
1290 </html>""") | |
1291 translator = Translator() | |
1292 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1293 messages = list(translator.extract(tmpl.stream)) | |
1294 self.assertEqual(1, len(messages)) | |
858 | 1295 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1296 'Foos %(fname)s %(lname)s'), | |
1297 ['As in Foo Bar']), | |
849 | 1298 messages[0]) |
1299 | |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1300 def test_extract_i18n_choose_with_attributes(self): |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1301 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1302 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1303 <p i18n:choose="num; num" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1304 <i18n:singular> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1305 There is <a href="$link" title="View thing">${num} thing</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1306 </i18n:singular> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1307 <i18n:plural> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1308 There are <a href="$link" title="View things">${num} things</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1309 </i18n:plural> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1310 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1311 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1312 translator = Translator() |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1313 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1314 messages = list(translator.extract(tmpl.stream)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1315 self.assertEqual(4, len(messages)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1316 self.assertEqual((3, None, 'Things', []), messages[0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1317 self.assertEqual((5, None, 'View thing', []), messages[1]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1318 self.assertEqual((8, None, 'View things', []), messages[2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1319 self.assertEqual( |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1320 (3, 'ngettext', ('There is [1:%(num)s thing].', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1321 'There are [1:%(num)s things].'), []), |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1322 messages[3]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1323 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1324 def test_translate_i18n_choose_with_attributes(self): |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1325 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1326 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1327 <p i18n:choose="num; num" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1328 <i18n:singular> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1329 There is <a href="$link" title="View thing">${num} thing</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1330 </i18n:singular> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1331 <i18n:plural> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1332 There are <a href="$link" title="View things">${num} things</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1333 </i18n:plural> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1334 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1335 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1336 translations = DummyTranslations({ |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1337 'Things': 'Sachen', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1338 'View thing': 'Sache betrachten', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1339 'View things': 'Sachen betrachten', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1340 ('There is [1:%(num)s thing].', 0): 'Da ist [1:%(num)s Sache].', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1341 ('There is [1:%(num)s thing].', 1): 'Da sind [1:%(num)s Sachen].' |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1342 }) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1343 translator = Translator(translations) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1344 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1345 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1346 <p title="Sachen"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1347 Da ist <a href="/things" title="Sache betrachten">1 Sache</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1348 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1349 </html>""", tmpl.generate(link="/things", num=1).render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1350 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1351 <p title="Sachen"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1352 Da sind <a href="/things" title="Sachen betrachten">3 Sachen</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1353 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1354 </html>""", tmpl.generate(link="/things", num=3).render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1355 |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1356 def test_extract_i18n_choose_as_element_with_attributes(self): |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1357 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1358 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1359 <i18n:choose numeral="num" params="num"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1360 <p i18n:singular="" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1361 There is <a href="$link" title="View thing">${num} thing</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1362 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1363 <p i18n:plural="" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1364 There are <a href="$link" title="View things">${num} things</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1365 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1366 </i18n:choose> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1367 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1368 translator = Translator() |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1369 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1370 messages = list(translator.extract(tmpl.stream)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1371 self.assertEqual(5, len(messages)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1372 self.assertEqual((4, None, 'Things', []), messages[0]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1373 self.assertEqual((5, None, 'View thing', []), messages[1]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1374 self.assertEqual((7, None, 'Things', []), messages[2]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1375 self.assertEqual((8, None, 'View things', []), messages[3]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1376 self.assertEqual( |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1377 (3, 'ngettext', ('There is [1:%(num)s thing].', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1378 'There are [1:%(num)s things].'), []), |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1379 messages[4]) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1380 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1381 def test_translate_i18n_choose_as_element_with_attributes(self): |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1382 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1383 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1384 <i18n:choose numeral="num" params="num"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1385 <p i18n:singular="" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1386 There is <a href="$link" title="View thing">${num} thing</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1387 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1388 <p i18n:plural="" title="Things"> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1389 There are <a href="$link" title="View things">${num} things</a>. |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1390 </p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1391 </i18n:choose> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1392 </html>""") |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1393 translations = DummyTranslations({ |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1394 'Things': 'Sachen', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1395 'View thing': 'Sache betrachten', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1396 'View things': 'Sachen betrachten', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1397 ('There is [1:%(num)s thing].', 0): 'Da ist [1:%(num)s Sache].', |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1398 ('There is [1:%(num)s thing].', 1): 'Da sind [1:%(num)s Sachen].' |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1399 }) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1400 translator = Translator(translations) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1401 translator.setup(tmpl) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1402 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1403 <p title="Sachen">Da ist <a href="/things" title="Sache betrachten">1 Sache</a>.</p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1404 </html>""", tmpl.generate(link="/things", num=1).render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1405 self.assertEqual(u"""<html> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1406 <p title="Sachen">Da sind <a href="/things" title="Sachen betrachten">3 Sachen</a>.</p> |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1407 </html>""", tmpl.generate(link="/things", num=3).render(encoding=None)) |
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1408 |
849 | 1409 def test_translate_i18n_choose_and_py_strip(self): |
1410 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1411 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1412 <div i18n:choose="two; fname, lname"> | |
1413 <p i18n:singular="">Foo $fname $lname</p> | |
1414 <p i18n:plural="">Foos $fname $lname</p> | |
1415 </div> | |
1416 </html>""") | |
1417 translations = DummyTranslations({ | |
1418 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1419 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1420 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1421 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1422 }) | |
1423 translator = Translator(translations) | |
1424 translator.setup(tmpl) | |
1425 self.assertEqual("""<html> | |
1426 <div> | |
1427 <p>Vohs John Doe</p> | |
1428 </div> | |
1429 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1430 | |
1431 def test_translate_i18n_choose_and_domain_and_py_strip(self): | |
1432 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1433 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1434 i18n:domain="foo"> | |
1435 <div i18n:choose="two; fname, lname"> | |
1436 <p i18n:singular="">Foo $fname $lname</p> | |
1437 <p i18n:plural="">Foos $fname $lname</p> | |
1438 </div> | |
1439 </html>""") | |
1440 translations = DummyTranslations() | |
1441 translations.add_domain('foo', { | |
1442 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1443 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1444 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1445 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1446 }) | |
1447 translator = Translator(translations) | |
1448 translator.setup(tmpl) | |
1449 self.assertEqual("""<html> | |
1450 <div> | |
1451 <p>Vohs John Doe</p> | |
1452 </div> | |
1453 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
871
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1454 |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1455 def test_translate_i18n_choose_and_singular_with_py_strip(self): |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1456 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1457 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1458 <div i18n:choose="two; fname, lname"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1459 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1460 <p i18n:plural="">Foos $fname $lname</p> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1461 </div> |
873
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1462 <div i18n:choose="one; fname, lname"> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1463 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1464 <p i18n:plural="">Foos $fname $lname</p> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1465 </div> |
871
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1466 </html>""") |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1467 translations = DummyTranslations({ |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1468 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1469 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1470 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1471 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1472 }) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1473 translator = Translator(translations) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1474 translator.setup(tmpl) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1475 self.assertEqual("""<html> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1476 <div> |
873
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1477 <p>Vohs John Doe</p> |
871
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1478 </div> |
873
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1479 <div> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1480 Voh John Doe |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1481 </div> |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1482 </html>""", tmpl.generate( |
4e8100e83bdd
Any `py:strip` involved on `i18n:singular` or `i18n:plural` is now handled separately, ie, if one has `py:strip` on a `i18n:singular` element or directive and the plural form is the one chosen, no stripping will be performed. Refs #371.
palgarvio
parents:
871
diff
changeset
|
1483 one=1, two=2, fname='John',lname='Doe').render()) |
871
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1484 |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1485 def test_translate_i18n_choose_and_plural_with_py_strip(self): |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1486 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1487 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1488 <div i18n:choose="two; fname, lname"> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1489 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1490 <p i18n:plural="">Foos $fname $lname</p> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1491 </div> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1492 </html>""") |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1493 translations = DummyTranslations({ |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1494 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1495 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1496 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1497 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1498 }) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1499 translator = Translator(translations) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1500 translator.setup(tmpl) |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1501 self.assertEqual("""<html> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1502 <div> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1503 Voh John Doe |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1504 </div> |
b6deffd8ecce
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1505 </html>""", tmpl.generate(two=1, fname='John', lname='Doe').render()) |
849 | 1506 |
1507 def test_extract_i18n_choose_as_attribute_and_py_strip(self): | |
1508 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1509 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1510 <div i18n:choose="one" py:strip=""> | |
1511 <p i18n:singular="" py:strip="">FooBar</p> | |
1512 <p i18n:plural="" py:strip="">FooBars</p> | |
1513 </div> | |
1514 </html>""") | |
1515 translator = Translator() | |
1516 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1517 messages = list(translator.extract(tmpl.stream)) | |
1518 self.assertEqual(1, len(messages)) | |
858 | 1519 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
849 | 1520 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1521 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1522 class DomainDirectiveTestCase(unittest.TestCase): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1523 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1524 def test_translate_i18n_domain_with_msg_directives(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1525 #"""translate with i18n:domain and nested i18n:msg directives """ |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1526 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1527 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1528 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1529 <div i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1530 <p i18n:msg="">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1531 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1532 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1533 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1534 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1535 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1536 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1537 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1538 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1539 <div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1540 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1541 <p>PT_Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1542 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1543 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1544 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1545 def test_translate_i18n_domain_with_inline_directives(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1546 #"""translate with inlined i18n:domain and i18n:msg directives""" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1547 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1548 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1549 <p i18n:msg="" i18n:domain="foo">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1550 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1551 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1552 translations.add_domain('foo', {'FooBar': 'BarFoo'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1553 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1554 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1555 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1556 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1557 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1558 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1559 def test_translate_i18n_domain_without_msg_directives(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1560 #"""translate domain call without i18n:msg directives still uses current domain""" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1561 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1562 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1563 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1564 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1565 <div i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1566 <p i18n:msg="">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1567 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1568 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1569 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1570 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1571 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1572 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1573 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1574 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1575 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1576 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1577 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1578 <div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1579 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1580 <p>PT_Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1581 <p>PT_Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1582 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1583 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1584 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1585 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1586 def test_translate_i18n_domain_as_directive_not_attribute(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1587 #"""translate with domain as directive""" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1588 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1589 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1590 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1591 <i18n:domain name="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1592 <p i18n:msg="">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1593 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1594 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1595 </i18n:domain> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1596 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1597 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1598 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1599 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1600 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1601 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1602 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1603 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1604 <p>PT_Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1605 <p>PT_Foo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1606 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1607 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1608 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1609 def test_translate_i18n_domain_nested_directives(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1610 #"""translate with nested i18n:domain directives""" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1611 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1612 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1613 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1614 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1615 <div i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1616 <p i18n:msg="">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1617 <p i18n:domain="bar" i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1618 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1619 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1620 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1621 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1622 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1623 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'foo_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1624 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1625 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1626 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1627 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1628 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1629 <div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1630 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1631 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1632 <p>foo_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1633 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1634 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1635 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1636 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1637 def test_translate_i18n_domain_with_empty_nested_domain_directive(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1638 #"""translate with empty nested i18n:domain directive does not use dngettext""" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1639 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1640 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1641 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1642 <p i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1643 <div i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1644 <p i18n:msg="">FooBar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1645 <p i18n:domain="" i18n:msg="">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1646 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1647 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1648 <p>Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1649 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1650 translations = DummyTranslations({'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1651 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'foo_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1652 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1653 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1654 translator.setup(tmpl) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1655 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1656 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1657 <div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1658 <p>BarFoo</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1659 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1660 <p>foo_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1661 </div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1662 <p>Voh</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1663 </html>""", tmpl.generate().render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1664 |
849 | 1665 def test_translate_i18n_domain_with_inline_directive_on_START_NS(self): |
1666 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1667 xmlns:i18n="http://genshi.edgewall.org/i18n" i18n:domain="foo"> | |
1668 <p i18n:msg="">FooBar</p> | |
1669 </html>""") | |
1670 translations = DummyTranslations({'Bar': 'Voh'}) | |
1671 translations.add_domain('foo', {'FooBar': 'BarFoo'}) | |
1672 translator = Translator(translations) | |
1673 translator.setup(tmpl) | |
1674 self.assertEqual("""<html> | |
1675 <p>BarFoo</p> | |
1676 </html>""", tmpl.generate().render()) | |
1677 | |
1678 def test_translate_i18n_domain_with_inline_directive_on_START_NS_with_py_strip(self): | |
1679 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1680 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1681 i18n:domain="foo" py:strip=""> | |
1682 <p i18n:msg="">FooBar</p> | |
1683 </html>""") | |
1684 translations = DummyTranslations({'Bar': 'Voh'}) | |
1685 translations.add_domain('foo', {'FooBar': 'BarFoo'}) | |
1686 translator = Translator(translations) | |
1687 translator.setup(tmpl) | |
1688 self.assertEqual(""" | |
1689 <p>BarFoo</p> | |
1690 """, tmpl.generate().render()) | |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1691 |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1692 def test_translate_i18n_domain_with_nested_includes(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1693 import os, shutil, tempfile |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1694 from genshi.template.loader import TemplateLoader |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1695 dirname = tempfile.mkdtemp(suffix='genshi_test') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1696 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1697 for idx in range(7): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1698 file1 = open(os.path.join(dirname, 'tmpl%d.html' % idx), 'w') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1699 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1700 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1701 xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1702 xmlns:i18n="http://genshi.edgewall.org/i18n" py:strip=""> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1703 <div>Included tmpl$idx</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1704 <p i18n:msg="idx">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1705 <p i18n:domain="bar">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1706 <p i18n:msg="idx" i18n:domain="">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1707 <p i18n:domain="" i18n:msg="idx">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1708 <py:if test="idx < 6"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1709 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1710 </py:if> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1711 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1712 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1713 file1.close() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1714 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1715 file2 = open(os.path.join(dirname, 'tmpl10.html'), 'w') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1716 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1717 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1718 xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1719 xmlns:i18n="http://genshi.edgewall.org/i18n" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1720 i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1721 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1722 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1723 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1724 file2.close() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1725 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1726 def callback(template): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1727 translations = DummyTranslations({'Bar %(idx)s': 'Voh %(idx)s'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1728 translations.add_domain('foo', {'Bar %(idx)s': 'foo_Bar %(idx)s'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1729 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1730 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1731 translator.setup(template) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1732 loader = TemplateLoader([dirname], callback=callback) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1733 tmpl = loader.load('tmpl10.html') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1734 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1735 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1736 <div>Included tmpl0</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1737 <p>foo_Bar 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1738 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1739 <p>Voh 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1740 <p>Voh 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1741 <div>Included tmpl1</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1742 <p>foo_Bar 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1743 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1744 <p>Voh 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1745 <p>Voh 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1746 <div>Included tmpl2</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1747 <p>foo_Bar 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1748 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1749 <p>Voh 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1750 <p>Voh 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1751 <div>Included tmpl3</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1752 <p>foo_Bar 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1753 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1754 <p>Voh 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1755 <p>Voh 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1756 <div>Included tmpl4</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1757 <p>foo_Bar 4</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1758 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1759 <p>Voh 4</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1760 <p>Voh 4</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1761 <div>Included tmpl5</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1762 <p>foo_Bar 5</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1763 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1764 <p>Voh 5</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1765 <p>Voh 5</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1766 <div>Included tmpl6</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1767 <p>foo_Bar 6</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1768 <p>bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1769 <p>Voh 6</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1770 <p>Voh 6</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1771 </html>""", tmpl.generate(idx=-1).render()) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1772 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1773 shutil.rmtree(dirname) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1774 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1775 def test_translate_i18n_domain_with_nested_includes_with_translatable_attrs(self): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1776 import os, shutil, tempfile |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1777 from genshi.template.loader import TemplateLoader |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1778 dirname = tempfile.mkdtemp(suffix='genshi_test') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1779 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1780 for idx in range(4): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1781 file1 = open(os.path.join(dirname, 'tmpl%d.html' % idx), 'w') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1782 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1783 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1784 xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1785 xmlns:i18n="http://genshi.edgewall.org/i18n" py:strip=""> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1786 <div>Included tmpl$idx</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1787 <p title="${dg('foo', 'Bar %(idx)s') % dict(idx=idx)}" i18n:msg="idx">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1788 <p title="Bar" i18n:domain="bar">Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1789 <p title="Bar" i18n:msg="idx" i18n:domain="">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1790 <p i18n:msg="idx" i18n:domain="" title="Bar">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1791 <p i18n:domain="" i18n:msg="idx" title="Bar">Bar $idx</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1792 <py:if test="idx < 3"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1793 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1794 </py:if> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1795 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1796 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1797 file1.close() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1798 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1799 file2 = open(os.path.join(dirname, 'tmpl10.html'), 'w') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1800 try: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1801 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1802 xmlns:py="http://genshi.edgewall.org/" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1803 xmlns:i18n="http://genshi.edgewall.org/i18n" |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1804 i18n:domain="foo"> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1805 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1806 </html>""") |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1807 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1808 file2.close() |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1809 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1810 translations = DummyTranslations({'Bar %(idx)s': 'Voh %(idx)s', |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1811 'Bar': 'Voh'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1812 translations.add_domain('foo', {'Bar %(idx)s': 'foo_Bar %(idx)s'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1813 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1814 translator = Translator(translations) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1815 |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1816 def callback(template): |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1817 translator.setup(template) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1818 loader = TemplateLoader([dirname], callback=callback) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1819 tmpl = loader.load('tmpl10.html') |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1820 |
933 | 1821 if IS_PYTHON2: |
1822 dgettext = translations.dugettext | |
1823 else: | |
1824 dgettext = translations.dgettext | |
1825 | |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1826 self.assertEqual("""<html> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1827 <div>Included tmpl0</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1828 <p title="foo_Bar 0">foo_Bar 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1829 <p title="bar_Bar">bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1830 <p title="Voh">Voh 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1831 <p title="Voh">Voh 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1832 <p title="Voh">Voh 0</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1833 <div>Included tmpl1</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1834 <p title="foo_Bar 1">foo_Bar 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1835 <p title="bar_Bar">bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1836 <p title="Voh">Voh 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1837 <p title="Voh">Voh 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1838 <p title="Voh">Voh 1</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1839 <div>Included tmpl2</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1840 <p title="foo_Bar 2">foo_Bar 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1841 <p title="bar_Bar">bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1842 <p title="Voh">Voh 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1843 <p title="Voh">Voh 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1844 <p title="Voh">Voh 2</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1845 <div>Included tmpl3</div> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1846 <p title="foo_Bar 3">foo_Bar 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1847 <p title="bar_Bar">bar_Bar</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1848 <p title="Voh">Voh 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1849 <p title="Voh">Voh 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1850 <p title="Voh">Voh 3</p> |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1851 </html>""", tmpl.generate(idx=-1, |
933 | 1852 dg=dgettext).render()) |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1853 finally: |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1854 shutil.rmtree(dirname) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1855 |
892
a6a23b889708
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1856 |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1857 class ExtractTestCase(unittest.TestCase): |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1858 |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1859 def test_markup_template_extraction(self): |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1860 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1861 <head> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1862 <title>Example</title> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1863 </head> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1864 <body> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1865 <h1>Example</h1> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1866 <p>${_("Hello, %(name)s") % dict(name=username)}</p> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1867 <p>${ngettext("You have %d item", "You have %d items", num)}</p> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1868 </body> |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1869 </html>""") |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1870 results = list(extract(buf, ['_', 'ngettext'], [], {})) |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1871 self.assertEqual([ |
858 | 1872 (3, None, 'Example', []), |
1873 (6, None, 'Example', []), | |
1874 (7, '_', 'Hello, %(name)s', []), | |
1875 (8, 'ngettext', ('You have %d item', 'You have %d items', None), | |
565
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1876 []), |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1877 ], results) |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1878 |
596
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1879 def test_extraction_without_text(self): |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1880 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1881 <p title="Bar">Foo</p> |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1882 ${ngettext("Singular", "Plural", num)} |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1883 </html>""") |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1884 results = list(extract(buf, ['_', 'ngettext'], [], { |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1885 'extract_text': 'no' |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1886 })) |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1887 self.assertEqual([ |
858 | 1888 (3, 'ngettext', ('Singular', 'Plural', None), []), |
596
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1889 ], results) |
badb5e5b7bb9
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1890 |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1891 def test_text_template_extraction(self): |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1892 buf = StringIO("""${_("Dear %(name)s") % {'name': name}}, |
849 | 1893 |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1894 ${ngettext("Your item:", "Your items", len(items))} |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1895 #for item in items |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1896 * $item |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1897 #end |
849 | 1898 |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1899 All the best, |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1900 Foobar""") |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1901 results = list(extract(buf, ['_', 'ngettext'], [], { |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1902 'template_class': 'genshi.template:TextTemplate' |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1903 })) |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1904 self.assertEqual([ |
858 | 1905 (1, '_', 'Dear %(name)s', []), |
1906 (3, 'ngettext', ('Your item:', 'Your items', None), []), | |
1907 (7, None, 'All the best,\n Foobar', []) | |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1908 ], results) |
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1909 |
565
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1910 def test_extraction_with_keyword_arg(self): |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1911 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1912 ${gettext('Foobar', foo='bar')} |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1913 </html>""") |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1914 results = list(extract(buf, ['gettext'], [], {})) |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1915 self.assertEqual([ |
858 | 1916 (2, 'gettext', ('Foobar'), []), |
565
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1917 ], results) |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1918 |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1919 def test_extraction_with_nonstring_arg(self): |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1920 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1921 ${dgettext(curdomain, 'Foobar')} |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1922 </html>""") |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1923 results = list(extract(buf, ['dgettext'], [], {})) |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1924 self.assertEqual([ |
858 | 1925 (2, 'dgettext', (None, 'Foobar'), []), |
565
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1926 ], results) |
53b37e4f2921
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1927 |
549
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1928 def test_extraction_inside_ignored_tags(self): |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1929 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1930 <script type="text/javascript"> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1931 $('#llist').tabs({ |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1932 remote: true, |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1933 spinner: "${_('Please wait...')}" |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1934 }); |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1935 </script> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1936 </html>""") |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1937 results = list(extract(buf, ['_'], [], {})) |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1938 self.assertEqual([ |
858 | 1939 (5, '_', 'Please wait...', []), |
549
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1940 ], results) |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1941 |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1942 def test_extraction_inside_ignored_tags_with_directives(self): |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1943 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1944 <script type="text/javascript"> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1945 <py:if test="foobar"> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1946 alert("This shouldn't be extracted"); |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1947 </py:if> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1948 </script> |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1949 </html>""") |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1950 self.assertEqual([], list(extract(buf, ['_'], [], {}))) |
7214c1bdb383
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1951 |
849 | 1952 def test_extract_py_def_directive_with_py_strip(self): |
1953 # Failed extraction from Trac | |
1954 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" py:strip=""> | |
1955 <py:def function="diff_options_fields(diff)"> | |
1956 <label for="style">View differences</label> | |
1957 <select id="style" name="style"> | |
1958 <option selected="${diff.style == 'inline' or None}" | |
1959 value="inline">inline</option> | |
1960 <option selected="${diff.style == 'sidebyside' or None}" | |
1961 value="sidebyside">side by side</option> | |
1962 </select> | |
1963 <div class="field"> | |
1964 Show <input type="text" name="contextlines" id="contextlines" size="2" | |
1965 maxlength="3" value="${diff.options.contextlines < 0 and 'all' or diff.options.contextlines}" /> | |
1966 <label for="contextlines">lines around each change</label> | |
1967 </div> | |
1968 <fieldset id="ignore" py:with="options = diff.options"> | |
1969 <legend>Ignore:</legend> | |
1970 <div class="field"> | |
1971 <input type="checkbox" id="ignoreblanklines" name="ignoreblanklines" | |
1972 checked="${options.ignoreblanklines or None}" /> | |
1973 <label for="ignoreblanklines">Blank lines</label> | |
1974 </div> | |
1975 <div class="field"> | |
1976 <input type="checkbox" id="ignorecase" name="ignorecase" | |
1977 checked="${options.ignorecase or None}" /> | |
1978 <label for="ignorecase">Case changes</label> | |
1979 </div> | |
1980 <div class="field"> | |
1981 <input type="checkbox" id="ignorewhitespace" name="ignorewhitespace" | |
1982 checked="${options.ignorewhitespace or None}" /> | |
1983 <label for="ignorewhitespace">White space changes</label> | |
1984 </div> | |
1985 </fieldset> | |
1986 <div class="buttons"> | |
1987 <input type="submit" name="update" value="${_('Update')}" /> | |
1988 </div> | |
1989 </py:def></html>""") | |
1990 translator = Translator() | |
1991 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1992 messages = list(translator.extract(tmpl.stream)) | |
1993 self.assertEqual(10, len(messages)) | |
1994 self.assertEqual([ | |
858 | 1995 (3, None, 'View differences', []), |
1996 (6, None, 'inline', []), | |
1997 (8, None, 'side by side', []), | |
1998 (10, None, 'Show', []), | |
1999 (13, None, 'lines around each change', []), | |
2000 (16, None, 'Ignore:', []), | |
2001 (20, None, 'Blank lines', []), | |
2002 (25, None, 'Case changes',[]), | |
2003 (30, None, 'White space changes', []), | |
2004 (34, '_', 'Update', [])], messages) | |
849 | 2005 |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
2006 |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2007 def suite(): |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2008 suite = unittest.TestSuite() |
709
9dd5f370a70e
Python 2.3 compatibility fixes for transformer and (specifically for 2.3.1) i18n.
athomas
parents:
667
diff
changeset
|
2009 suite.addTest(doctest.DocTestSuite(Translator.__module__)) |
485
fb66fb3e4b49
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
2010 suite.addTest(unittest.makeSuite(TranslatorTestCase, 'test')) |
894
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
2011 suite.addTest(unittest.makeSuite(MsgDirectiveTestCase, 'test')) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
2012 suite.addTest(unittest.makeSuite(ChooseDirectiveTestCase, 'test')) |
9ee2565885dd
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
2013 suite.addTest(unittest.makeSuite(DomainDirectiveTestCase, 'test')) |
528
24df908da22d
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
2014 suite.addTest(unittest.makeSuite(ExtractTestCase, 'test')) |
446
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2015 return suite |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2016 |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2017 if __name__ == '__main__': |
fd9c4f7a249a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2018 unittest.main(defaultTest='suite') |