Mercurial > genshi > genshi-test
annotate genshi/filters/tests/i18n.py @ 916:872726bac135 experimental-py3k
add support for python 3 to genshi.filters:
* minor changes to track encoding=None API change in core genshi modules.
* renamed genshi/filters/tests/html.py to test_html.py to avoid clashes with Python 3 top-level html module when running tests subset.
* did not rename genshi/filters/html.py.
* i18n filters:
* ugettext and friends are gone in Python 3 (and only gettext and friends exist and they now handle unicode)
* Some \ line continuations inside doctests confused 2to3 and so were removed them.
* Testing picked up a problem (already present in trunk) where Translator.__call__ could end up defining gettext as an endlessly recursive function. Noted with a TODO.
author | hodgestar |
---|---|
date | Sun, 24 Oct 2010 22:21:28 +0000 |
parents | 85e4678337cf |
children |
rev | line source |
---|---|
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2 # |
897 | 3 # Copyright (C) 2007-2010 Edgewall Software |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
5 # |
90f5908cd10a
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 |
90f5908cd10a
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 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
9 # |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
13 |
776
9e0ba5b9693c
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
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
15 import doctest |
788
09531799bac2
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
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
17 import unittest |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
18 |
667
077c9142dca0
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
f38ce008ab0a
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
077c9142dca0
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 |
916 | 23 from genshi.compat import IS_PYTHON2, StringIO |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
24 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
25 |
788
09531799bac2
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
09531799bac2
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
09531799bac2
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
09531799bac2
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 |
916 | 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
09531799bac2
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 |
916 | 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 | |
916 | 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
09531799bac2
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
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
91 class TranslatorTestCase(unittest.TestCase): |
485
770ba8556940
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
077c9142dca0
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): |
077c9142dca0
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 """ |
077c9142dca0
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. |
077c9142dca0
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 """ |
916 | 97 html = HTML(u"""<html> |
667
077c9142dca0
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> |
077c9142dca0
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>""") |
077c9142dca0
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") |
077c9142dca0
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)) |
077c9142dca0
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] |
077c9142dca0
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) |
077c9142dca0
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
0fb43dc2e165
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): |
0fb43dc2e165
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/"> |
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
107 <p title="Bar">Foo</p> |
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
108 ${ngettext("Singular", "Plural", num)} |
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
109 </html>""") |
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
110 translator = Translator(extract_text=False) |
0fb43dc2e165
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)) |
0fb43dc2e165
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
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
114 messages[0]) |
0fb43dc2e165
Add option to I18n filter to only extract strings in gettext function calls.
cmlenz
parents:
565
diff
changeset
|
115 |
485
770ba8556940
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): |
770ba8556940
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/"> |
770ba8556940
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)} |
770ba8556940
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>""") |
770ba8556940
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() |
770ba8556940
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)) |
770ba8556940
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
aa8e85a4085e
* 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
770ba8556940
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
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
126 def test_extract_funky_plural_form(self): |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
127 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
128 ${ngettext(len(items), *widget.display_names)} |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
129 </html>""") |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
130 translator = Translator() |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
131 messages = list(translator.extract(tmpl.stream)) |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
132 self.assertEqual(1, len(messages)) |
787
422a9dd01e9f
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
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
134 |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
135 def test_extract_gettext_with_unicode_string(self): |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
136 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
137 ${gettext("Grüße")} |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
138 </html>""") |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
139 translator = Translator() |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
140 messages = list(translator.extract(tmpl.stream)) |
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
141 self.assertEqual(1, len(messages)) |
787
422a9dd01e9f
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
0d802a7e3630
Handle starargs and dstarargs in the I18n extraction code.
cmlenz
parents:
596
diff
changeset
|
143 |
485
770ba8556940
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): |
770ba8556940
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/"> |
770ba8556940
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> |
770ba8556940
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>""") |
770ba8556940
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() |
770ba8556940
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)) |
770ba8556940
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
770ba8556940
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 |
770ba8556940
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): |
770ba8556940
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/"> |
770ba8556940
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')}" /> |
770ba8556940
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>""") |
770ba8556940
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() |
770ba8556940
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)) |
770ba8556940
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
770ba8556940
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 |
770ba8556940
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): |
770ba8556940
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/"> |
770ba8556940
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> |
770ba8556940
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>""") |
770ba8556940
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() |
770ba8556940
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)) |
770ba8556940
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
770ba8556940
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 |
770ba8556940
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): |
770ba8556940
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/"> |
770ba8556940
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> |
770ba8556940
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>""") |
770ba8556940
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() |
770ba8556940
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)) |
770ba8556940
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
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
179 |
522
c1738dec04d9
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): |
c1738dec04d9
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/"> |
c1738dec04d9
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> |
c1738dec04d9
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>""") |
c1738dec04d9
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() |
c1738dec04d9
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)) |
c1738dec04d9
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)) |
c1738dec04d9
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 |
c1738dec04d9
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): |
c1738dec04d9
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/"> |
c1738dec04d9
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> |
c1738dec04d9
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>""") |
c1738dec04d9
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() |
c1738dec04d9
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)) |
c1738dec04d9
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
422a9dd01e9f
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
c1738dec04d9
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
c8806216aec4
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): |
c8806216aec4
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/"> |
c8806216aec4
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" /> |
c8806216aec4
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
201 </html>""") |
c8806216aec4
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() |
c8806216aec4
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)) |
c8806216aec4
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)) |
c8806216aec4
The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions.
cmlenz
parents:
528
diff
changeset
|
205 |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
206 def test_translate_with_translations_object(self): |
6fe4feb2635b
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/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
208 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
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> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
210 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
211 translator = Translator(DummyTranslations({'Foo': 'Voh'})) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
212 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
213 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
214 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
215 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
216 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
217 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
218 class MsgDirectiveTestCase(unittest.TestCase): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
219 |
560
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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]) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
241 translator = Translator(gettext) |
849 | 242 translator.setup(tmpl) |
916 | 243 self.assertEqual(u"""<html> |
560
f227a2f12e5f
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> |
916 | 245 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) |
560
f227a2f12e5f
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
38c44e2f4232
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): |
38c44e2f4232
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/" |
38c44e2f4232
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"> |
38c44e2f4232
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> |
38c44e2f4232
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>""") |
38c44e2f4232
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() |
38c44e2f4232
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) |
38c44e2f4232
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)) |
38c44e2f4232
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)) |
38c44e2f4232
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]) |
38c44e2f4232
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
257 |
38c44e2f4232
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): |
38c44e2f4232
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/" |
38c44e2f4232
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"> |
38c44e2f4232
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> |
38c44e2f4232
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>""") |
38c44e2f4232
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]" |
38c44e2f4232
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) |
38c44e2f4232
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) |
916 | 266 self.assertEqual(u"""<html> |
869
38c44e2f4232
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> |
38c44e2f4232
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()) |
38c44e2f4232
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
269 |
38c44e2f4232
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): |
38c44e2f4232
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/" |
38c44e2f4232
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"> |
38c44e2f4232
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> |
38c44e2f4232
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>""") |
38c44e2f4232
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() |
38c44e2f4232
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) |
38c44e2f4232
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)) |
38c44e2f4232
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)) |
38c44e2f4232
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]) |
38c44e2f4232
Apply patch for I18n message extraction bug as reported in #358. Thanks to cboos for the patch, again.
cmlenz
parents:
858
diff
changeset
|
280 |
38c44e2f4232
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): |
38c44e2f4232
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/" |
38c44e2f4232
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"> |
38c44e2f4232
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> |
38c44e2f4232
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>""") |
38c44e2f4232
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]" |
38c44e2f4232
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) |
38c44e2f4232
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) |
916 | 289 self.assertEqual(u"""<html> |
869
38c44e2f4232
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> |
916 | 291 </html>""".encode('utf-8'), tmpl.generate().render(encoding='utf-8')) |
869
38c44e2f4232
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
1de952fd479e
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): |
1de952fd479e
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/" |
1de952fd479e
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"> |
1de952fd479e
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"> |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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>""") |
1de952fd479e
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() |
1de952fd479e
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) |
1de952fd479e
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)) |
1de952fd479e
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)) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
310 |
1de952fd479e
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): |
1de952fd479e
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/" |
1de952fd479e
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"> |
1de952fd479e
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"> |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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>""") |
1de952fd479e
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: { |
1de952fd479e
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', |
1de952fd479e
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', |
1de952fd479e
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]' |
1de952fd479e
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]) |
1de952fd479e
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) |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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)) |
1de952fd479e
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
1de952fd479e
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/" |
1de952fd479e
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"> |
1de952fd479e
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=""> |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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>""") |
1de952fd479e
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() |
1de952fd479e
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) |
1de952fd479e
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)) |
1de952fd479e
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)) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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]) |
1de952fd479e
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
1de952fd479e
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/" |
1de952fd479e
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"> |
1de952fd479e
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=""> |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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>""") |
1de952fd479e
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: { |
1de952fd479e
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', |
1de952fd479e
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]' |
1de952fd479e
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]) |
1de952fd479e
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) |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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)) |
1de952fd479e
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
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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.', |
f227a2f12e5f
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]) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
417 translator = Translator(gettext) |
849 | 418 translator.setup(tmpl) |
916 | 419 self.assertEqual(u"""<html> |
560
f227a2f12e5f
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> |
f227a2f12e5f
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()) |
f227a2f12e5f
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
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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]) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
472 translator = Translator(gettext) |
849 | 473 translator.setup(tmpl) |
916 | 474 self.assertEqual(u"""<html> |
560
f227a2f12e5f
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> |
f227a2f12e5f
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()) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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>. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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]) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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>. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
499 translator = Translator(gettext) |
849 | 500 translator.setup(tmpl) |
916 | 501 self.assertEqual(u"""<html> |
560
f227a2f12e5f
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> |
f227a2f12e5f
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()) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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" />. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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:].', |
f227a2f12e5f
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]) |
f227a2f12e5f
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 |
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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" />. |
f227a2f12e5f
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> |
916 | 525 </html>""", encoding='utf-8') |
560
f227a2f12e5f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
527 translator = Translator(gettext) |
849 | 528 translator.setup(tmpl) |
916 | 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
f227a2f12e5f
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
9e0ba5b9693c
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): |
9e0ba5b9693c
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/" |
9e0ba5b9693c
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"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
536 <p i18n:msg="name"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
537 Hello, ${user.name}! |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
538 </p> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
539 </html>""") |
9e0ba5b9693c
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
9e0ba5b9693c
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)) |
9e0ba5b9693c
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)) |
9e0ba5b9693c
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]) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
545 |
9e0ba5b9693c
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): |
9e0ba5b9693c
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/" |
9e0ba5b9693c
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"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
549 <p i18n:msg="name"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
550 Hello, ${user.name}! |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
551 </p> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
552 </html>""") |
9e0ba5b9693c
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
554 translator = Translator(gettext) |
849 | 555 translator.setup(tmpl) |
776
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
556 self.assertEqual("""<html> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
557 <p>Hallo, Jim!</p> |
9e0ba5b9693c
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()) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
559 |
9e0ba5b9693c
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): |
9e0ba5b9693c
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/" |
9e0ba5b9693c
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"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
563 <p i18n:msg="name"> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
564 Hello, ${user.name}! |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
565 </p> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
566 </html>""") |
9e0ba5b9693c
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
568 translator = Translator(gettext) |
849 | 569 translator.setup(tmpl) |
916 | 570 self.assertEqual(u"""<html> |
776
9e0ba5b9693c
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> |
9e0ba5b9693c
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()) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
573 |
785
64bf70856f02
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): |
64bf70856f02
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/" |
64bf70856f02
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"> |
64bf70856f02
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
577 <p i18n:msg=""> |
64bf70856f02
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>! |
64bf70856f02
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
579 </p> |
64bf70856f02
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
580 </html>""") |
64bf70856f02
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
582 translator = Translator(gettext) |
849 | 583 translator.setup(tmpl) |
916 | 584 self.assertEqual(u"""<html> |
785
64bf70856f02
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> |
64bf70856f02
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()) |
64bf70856f02
Fix for #250: ignore expressions in attribute values when inside `i18n:msg` elements.
cmlenz
parents:
776
diff
changeset
|
587 |
776
9e0ba5b9693c
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): |
9e0ba5b9693c
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/" |
9e0ba5b9693c
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"> |
9e0ba5b9693c
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"> |
9e0ba5b9693c
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')} |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
593 </p> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
594 </html>""") |
9e0ba5b9693c
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
9e0ba5b9693c
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)) |
9e0ba5b9693c
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)) |
9e0ba5b9693c
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]) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
600 |
9e0ba5b9693c
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): |
9e0ba5b9693c
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/" |
9e0ba5b9693c
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"> |
9e0ba5b9693c
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"> |
9e0ba5b9693c
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')} |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
606 </p> |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
607 </html>""") |
9e0ba5b9693c
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
609 translator = Translator(gettext) |
849 | 610 translator.setup(tmpl) |
776
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
611 entry = { |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
612 'author': 'Jim', |
9e0ba5b9693c
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) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
614 } |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
615 self.assertEqual("""<html> |
9e0ba5b9693c
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> |
9e0ba5b9693c
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()) |
9e0ba5b9693c
Added tests for the parameter support added to advanced internationalization in [901]. See #129.
cmlenz
parents:
719
diff
changeset
|
618 |
560
f227a2f12e5f
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): |
f227a2f12e5f
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/" |
f227a2f12e5f
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"> |
f227a2f12e5f
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=""> |
f227a2f12e5f
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. |
f227a2f12e5f
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> |
f227a2f12e5f
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>""") |
f227a2f12e5f
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
f227a2f12e5f
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)) |
f227a2f12e5f
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)) |
f227a2f12e5f
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]) |
f227a2f12e5f
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) | |
916 | 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
f227a2f12e5f
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
422a9dd01e9f
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): |
422a9dd01e9f
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/" |
422a9dd01e9f
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
422a9dd01e9f
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> |
422a9dd01e9f
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>""") |
422a9dd01e9f
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
422a9dd01e9f
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)) |
422a9dd01e9f
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
422a9dd01e9f
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 |
422a9dd01e9f
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): |
422a9dd01e9f
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/" |
422a9dd01e9f
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"> |
422a9dd01e9f
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> |
422a9dd01e9f
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>""") |
422a9dd01e9f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
672 translator = Translator(gettext) |
849 | 673 translator.setup(tmpl) |
787
422a9dd01e9f
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> |
422a9dd01e9f
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> |
422a9dd01e9f
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()) |
422a9dd01e9f
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
678 def test_extract_i18n_msg_with_attr(self): |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
679 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
680 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
681 <p i18n:msg="" title="Foo bar">Foo</p> |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
682 </html>""") |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
683 translator = Translator() |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
684 messages = list(translator.extract(tmpl.stream)) |
1b6968d31089
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
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
688 |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
689 def test_translate_i18n_msg_with_attr(self): |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
690 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
691 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
692 <p i18n:msg="" title="Foo bar">Foo</p> |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
693 </html>""") |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
694 gettext = lambda s: u"Voh" |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
695 translator = Translator(DummyTranslations({ |
858 | 696 'Foo': 'Voh', |
790
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
697 'Foo bar': u'Voh bär' |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
698 })) |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
699 tmpl.filters.insert(0, translator) |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
700 tmpl.add_directives(Translator.NAMESPACE, translator) |
916 | 701 self.assertEqual(u"""<html> |
790
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
702 <p title="Voh bär">Voh</p> |
1b6968d31089
Merged the custom-directives branch back into trunk.
cmlenz
parents:
788
diff
changeset
|
703 </html>""", tmpl.generate().render()) |
1b6968d31089
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) | |
916 | 745 self.assertEqual(u"""<html> |
849 | 746 Modificado à um dia por Pedro |
916 | 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) | |
916 | 774 self.assertEqual(u"""<html> |
849 | 775 <p><tt><b>Trandução[ 0 ]</b>: <em>Uma moeda</em></tt></p> |
916 | 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/'}}) | |
916 | 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 ) | |
916 | 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> | |
916 | 875 </html>""".encode('utf-8'), tmpl.generate(editable=False).render(encoding='utf-8')) |
849 | 876 |
894
6fe4feb2635b
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
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
880 <p i18n:msg="" py:strip=""> |
6fe4feb2635b
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. |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
882 </p> |
849 | 883 </html>""") |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
884 translator = Translator() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
885 tmpl.add_directives(Translator.NAMESPACE, translator) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
886 messages = list(translator.extract(tmpl.stream)) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
887 self.assertEqual(1, len(messages)) |
6fe4feb2635b
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.', []), |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
889 messages[0]) |
849 | 890 |
894
6fe4feb2635b
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
6fe4feb2635b
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"> |
6fe4feb2635b
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. |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
896 </p> |
849 | 897 </html>""") |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
898 translator = Translator() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
899 tmpl.add_directives(Translator.NAMESPACE, translator) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
900 messages = list(translator.extract(tmpl.stream)) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
901 self.assertEqual(1, len(messages)) |
6fe4feb2635b
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.', |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
903 ['Foo']), messages[0]) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
904 |
6fe4feb2635b
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): |
6fe4feb2635b
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/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
907 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
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> |
6fe4feb2635b
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> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
910 </html>""") |
6fe4feb2635b
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
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
914 Voh |
6fe4feb2635b
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 | |
918 | |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
919 class ChooseDirectiveTestCase(unittest.TestCase): |
849 | 920 |
921 def test_translate_i18n_choose_as_attribute(self): | |
922 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
923 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
924 <div i18n:choose="one"> | |
925 <p i18n:singular="">FooBar</p> | |
926 <p i18n:plural="">FooBars</p> | |
927 </div> | |
928 <div i18n:choose="two"> | |
929 <p i18n:singular="">FooBar</p> | |
930 <p i18n:plural="">FooBars</p> | |
931 </div> | |
932 </html>""") | |
933 translations = DummyTranslations() | |
934 translator = Translator(translations) | |
935 translator.setup(tmpl) | |
936 self.assertEqual("""<html> | |
937 <div> | |
938 <p>FooBar</p> | |
939 </div> | |
940 <div> | |
941 <p>FooBars</p> | |
942 </div> | |
943 </html>""", tmpl.generate(one=1, two=2).render()) | |
944 | |
945 def test_translate_i18n_choose_as_directive(self): | |
946 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
947 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
948 <i18n:choose numeral="two"> | |
949 <p i18n:singular="">FooBar</p> | |
950 <p i18n:plural="">FooBars</p> | |
951 </i18n:choose> | |
952 <i18n:choose numeral="one"> | |
953 <p i18n:singular="">FooBar</p> | |
954 <p i18n:plural="">FooBars</p> | |
955 </i18n:choose> | |
956 </html>""") | |
957 translations = DummyTranslations() | |
958 translator = Translator(translations) | |
959 translator.setup(tmpl) | |
960 self.assertEqual("""<html> | |
961 <p>FooBars</p> | |
962 <p>FooBar</p> | |
963 </html>""", tmpl.generate(one=1, two=2).render()) | |
892
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
964 |
873
9786aa263217
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
|
965 def test_translate_i18n_choose_as_directive_singular_and_plural_with_strip(self): |
9786aa263217
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
|
966 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
9786aa263217
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
|
967 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
9786aa263217
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
|
968 <i18n:choose numeral="two"> |
9786aa263217
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
|
969 <p i18n:singular="" py:strip="">FooBar Singular with Strip</p> |
9786aa263217
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
|
970 <p i18n:plural="">FooBars Plural without Strip</p> |
9786aa263217
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
|
971 </i18n:choose> |
9786aa263217
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
|
972 <i18n:choose numeral="two"> |
9786aa263217
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
|
973 <p i18n:singular="">FooBar singular without strip</p> |
9786aa263217
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
|
974 <p i18n:plural="" py:strip="">FooBars plural with strip</p> |
9786aa263217
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
|
975 </i18n:choose> |
9786aa263217
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
|
976 <i18n:choose numeral="one"> |
9786aa263217
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
|
977 <p i18n:singular="">FooBar singular without strip</p> |
9786aa263217
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
|
978 <p i18n:plural="" py:strip="">FooBars plural with strip</p> |
9786aa263217
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
|
979 </i18n:choose> |
9786aa263217
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
|
980 <i18n:choose numeral="one"> |
9786aa263217
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
|
981 <p i18n:singular="" py:strip="">FooBar singular with strip</p> |
9786aa263217
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
|
982 <p i18n:plural="">FooBars plural without strip</p> |
9786aa263217
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
|
983 </i18n:choose> |
9786aa263217
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
|
984 </html>""") |
9786aa263217
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
|
985 translations = DummyTranslations() |
9786aa263217
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
|
986 translator = Translator(translations) |
9786aa263217
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
|
987 translator.setup(tmpl) |
9786aa263217
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
|
988 self.assertEqual("""<html> |
9786aa263217
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
|
989 <p>FooBars Plural without Strip</p> |
9786aa263217
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 FooBars plural with strip |
9786aa263217
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 <p>FooBar singular without strip</p> |
9786aa263217
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 FooBar singular with strip |
9786aa263217
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 </html>""", tmpl.generate(one=1, two=2).render()) |
849 | 994 |
871
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
995 def test_translate_i18n_choose_plural_singular_as_directive(self): |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
996 # Ticket 371 |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
997 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
998 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
999 <i18n:choose numeral="two"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1000 <i18n:singular>FooBar</i18n:singular> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1001 <i18n:plural>FooBars</i18n:plural> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1002 </i18n:choose> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1003 <i18n:choose numeral="one"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1004 <i18n:singular>FooBar</i18n:singular> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1005 <i18n:plural>FooBars</i18n:plural> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1006 </i18n:choose> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1007 </html>""") |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1008 translations = DummyTranslations({ |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1009 ('FooBar', 0): 'FuBar', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1010 ('FooBars', 1): 'FuBars', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1011 'FooBar': 'FuBar', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1012 'FooBars': 'FuBars', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1013 }) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1014 translator = Translator(translations) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1015 translator.setup(tmpl) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1016 self.assertEqual("""<html> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1017 FuBars |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1018 FuBar |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1019 </html>""", tmpl.generate(one=1, two=2).render()) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1020 |
849 | 1021 def test_translate_i18n_choose_as_attribute_with_params(self): |
1022 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1023 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1024 <div i18n:choose="two; fname, lname"> | |
1025 <p i18n:singular="">Foo $fname $lname</p> | |
1026 <p i18n:plural="">Foos $fname $lname</p> | |
1027 </div> | |
1028 </html>""") | |
1029 translations = DummyTranslations({ | |
1030 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1031 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1032 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1033 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1034 }) | |
1035 translator = Translator(translations) | |
1036 translator.setup(tmpl) | |
1037 self.assertEqual("""<html> | |
1038 <div> | |
1039 <p>Vohs John Doe</p> | |
1040 </div> | |
1041 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1042 | |
1043 def test_translate_i18n_choose_as_attribute_with_params_and_domain_as_param(self): | |
1044 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1045 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1046 i18n:domain="foo"> | |
1047 <div i18n:choose="two; fname, lname"> | |
1048 <p i18n:singular="">Foo $fname $lname</p> | |
1049 <p i18n:plural="">Foos $fname $lname</p> | |
1050 </div> | |
1051 </html>""") | |
1052 translations = DummyTranslations() | |
1053 translations.add_domain('foo', { | |
1054 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1055 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1056 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1057 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1058 }) | |
1059 translator = Translator(translations) | |
1060 translator.setup(tmpl) | |
1061 self.assertEqual("""<html> | |
1062 <div> | |
1063 <p>Vohs John Doe</p> | |
1064 </div> | |
1065 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1066 | |
1067 def test_translate_i18n_choose_as_directive_with_params(self): | |
1068 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1069 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1070 <i18n:choose numeral="two" params="fname, lname"> | |
1071 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1072 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1073 </i18n:choose> | |
1074 <i18n:choose numeral="one" params="fname, lname"> | |
1075 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1076 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1077 </i18n:choose> | |
1078 </html>""") | |
1079 translations = DummyTranslations({ | |
1080 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1081 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1082 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1083 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1084 }) | |
1085 translator = Translator(translations) | |
1086 translator.setup(tmpl) | |
1087 self.assertEqual("""<html> | |
1088 <p>Vohs John Doe</p> | |
1089 <p>Voh John Doe</p> | |
1090 </html>""", tmpl.generate(one=1, two=2, | |
1091 fname='John', lname='Doe').render()) | |
1092 | |
1093 def test_translate_i18n_choose_as_directive_with_params_and_domain_as_directive(self): | |
1094 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1095 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1096 <i18n:domain name="foo"> | |
1097 <i18n:choose numeral="two" params="fname, lname"> | |
1098 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1099 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1100 </i18n:choose> | |
1101 </i18n:domain> | |
1102 <i18n:choose numeral="one" params="fname, lname"> | |
1103 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1104 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1105 </i18n:choose> | |
1106 </html>""") | |
1107 translations = DummyTranslations() | |
1108 translations.add_domain('foo', { | |
1109 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1110 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1111 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1112 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1113 }) | |
1114 translator = Translator(translations) | |
1115 translator.setup(tmpl) | |
1116 self.assertEqual("""<html> | |
1117 <p>Vohs John Doe</p> | |
1118 <p>Foo John Doe</p> | |
1119 </html>""", tmpl.generate(one=1, two=2, | |
1120 fname='John', lname='Doe').render()) | |
1121 | |
1122 def test_extract_i18n_choose_as_attribute(self): | |
1123 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1124 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1125 <div i18n:choose="one"> | |
1126 <p i18n:singular="">FooBar</p> | |
1127 <p i18n:plural="">FooBars</p> | |
1128 </div> | |
1129 <div i18n:choose="two"> | |
1130 <p i18n:singular="">FooBar</p> | |
1131 <p i18n:plural="">FooBars</p> | |
1132 </div> | |
1133 </html>""") | |
1134 translator = Translator() | |
1135 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1136 messages = list(translator.extract(tmpl.stream)) | |
1137 self.assertEqual(2, len(messages)) | |
858 | 1138 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
1139 self.assertEqual((7, 'ngettext', ('FooBar', 'FooBars'), []), messages[1]) | |
849 | 1140 |
1141 def test_extract_i18n_choose_as_directive(self): | |
1142 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1143 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1144 <i18n:choose numeral="two"> | |
1145 <p i18n:singular="">FooBar</p> | |
1146 <p i18n:plural="">FooBars</p> | |
1147 </i18n:choose> | |
1148 <i18n:choose numeral="one"> | |
1149 <p i18n:singular="">FooBar</p> | |
1150 <p i18n:plural="">FooBars</p> | |
1151 </i18n:choose> | |
1152 </html>""") | |
1153 translator = Translator() | |
1154 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1155 messages = list(translator.extract(tmpl.stream)) | |
1156 self.assertEqual(2, len(messages)) | |
858 | 1157 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
1158 self.assertEqual((7, 'ngettext', ('FooBar', 'FooBars'), []), messages[1]) | |
849 | 1159 |
1160 def test_extract_i18n_choose_as_attribute_with_params(self): | |
1161 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1162 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1163 <div i18n:choose="two; fname, lname"> | |
1164 <p i18n:singular="">Foo $fname $lname</p> | |
1165 <p i18n:plural="">Foos $fname $lname</p> | |
1166 </div> | |
1167 </html>""") | |
1168 translator = Translator() | |
1169 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1170 messages = list(translator.extract(tmpl.stream)) | |
1171 self.assertEqual(1, len(messages)) | |
858 | 1172 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1173 'Foos %(fname)s %(lname)s'), []), | |
849 | 1174 messages[0]) |
1175 | |
1176 def test_extract_i18n_choose_as_attribute_with_params_and_domain_as_param(self): | |
1177 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1178 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1179 i18n:domain="foo"> | |
1180 <div i18n:choose="two; fname, lname"> | |
1181 <p i18n:singular="">Foo $fname $lname</p> | |
1182 <p i18n:plural="">Foos $fname $lname</p> | |
1183 </div> | |
1184 </html>""") | |
1185 translator = Translator() | |
1186 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1187 messages = list(translator.extract(tmpl.stream)) | |
1188 self.assertEqual(1, len(messages)) | |
858 | 1189 self.assertEqual((4, 'ngettext', ('Foo %(fname)s %(lname)s', |
1190 'Foos %(fname)s %(lname)s'), []), | |
849 | 1191 messages[0]) |
1192 | |
1193 def test_extract_i18n_choose_as_directive_with_params(self): | |
1194 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1195 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1196 <i18n:choose numeral="two" params="fname, lname"> | |
1197 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1198 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1199 </i18n:choose> | |
1200 <i18n:choose numeral="one" params="fname, lname"> | |
1201 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1202 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1203 </i18n:choose> | |
1204 </html>""") | |
1205 translator = Translator() | |
1206 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1207 messages = list(translator.extract(tmpl.stream)) | |
1208 self.assertEqual(2, len(messages)) | |
858 | 1209 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1210 'Foos %(fname)s %(lname)s'), []), | |
849 | 1211 messages[0]) |
858 | 1212 self.assertEqual((7, 'ngettext', ('Foo %(fname)s %(lname)s', |
1213 'Foos %(fname)s %(lname)s'), []), | |
849 | 1214 messages[1]) |
1215 | |
1216 def test_extract_i18n_choose_as_directive_with_params_and_domain_as_directive(self): | |
1217 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1218 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1219 <i18n:domain name="foo"> | |
1220 <i18n:choose numeral="two" params="fname, lname"> | |
1221 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1222 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1223 </i18n:choose> | |
1224 </i18n:domain> | |
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((4, 'ngettext', ('Foo %(fname)s %(lname)s', |
1235 'Foos %(fname)s %(lname)s'), []), | |
849 | 1236 messages[0]) |
858 | 1237 self.assertEqual((9, 'ngettext', ('Foo %(fname)s %(lname)s', |
1238 'Foos %(fname)s %(lname)s'), []), | |
849 | 1239 messages[1]) |
1240 | |
1241 def test_extract_i18n_choose_as_attribute_with_params_and_comment(self): | |
1242 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1243 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1244 <div i18n:choose="two; fname, lname" i18n:comment="As in Foo Bar"> | |
1245 <p i18n:singular="">Foo $fname $lname</p> | |
1246 <p i18n:plural="">Foos $fname $lname</p> | |
1247 </div> | |
1248 </html>""") | |
1249 translator = Translator() | |
1250 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1251 messages = list(translator.extract(tmpl.stream)) | |
1252 self.assertEqual(1, len(messages)) | |
858 | 1253 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1254 'Foos %(fname)s %(lname)s'), | |
1255 ['As in Foo Bar']), | |
849 | 1256 messages[0]) |
1257 | |
1258 def test_extract_i18n_choose_as_directive_with_params_and_comment(self): | |
1259 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1260 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1261 <i18n:choose numeral="two" params="fname, lname" i18n:comment="As in Foo Bar"> | |
1262 <p i18n:singular="">Foo ${fname} ${lname}</p> | |
1263 <p i18n:plural="">Foos ${fname} ${lname}</p> | |
1264 </i18n:choose> | |
1265 </html>""") | |
1266 translator = Translator() | |
1267 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1268 messages = list(translator.extract(tmpl.stream)) | |
1269 self.assertEqual(1, len(messages)) | |
858 | 1270 self.assertEqual((3, 'ngettext', ('Foo %(fname)s %(lname)s', |
1271 'Foos %(fname)s %(lname)s'), | |
1272 ['As in Foo Bar']), | |
849 | 1273 messages[0]) |
1274 | |
892
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1275 def test_extract_i18n_choose_with_attributes(self): |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1276 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1277 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1278 <p i18n:choose="num; num" title="Things"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1279 <i18n:singular> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1280 There is <a href="$link" title="View thing">${num} thing</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1281 </i18n:singular> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1282 <i18n:plural> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1283 There are <a href="$link" title="View things">${num} things</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1284 </i18n:plural> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1285 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1286 </html>""") |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1287 translator = Translator() |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1288 translator.setup(tmpl) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1289 messages = list(translator.extract(tmpl.stream)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1290 self.assertEqual(4, len(messages)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1291 self.assertEqual((3, None, 'Things', []), messages[0]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1292 self.assertEqual((5, None, 'View thing', []), messages[1]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1293 self.assertEqual((8, None, 'View things', []), messages[2]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1294 self.assertEqual( |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1295 (3, 'ngettext', ('There is [1:%(num)s thing].', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1296 'There are [1:%(num)s things].'), []), |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1297 messages[3]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1298 |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1299 def test_translate_i18n_choose_with_attributes(self): |
892
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1300 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1301 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1302 <p i18n:choose="num; num" title="Things"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1303 <i18n:singular> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1304 There is <a href="$link" title="View thing">${num} thing</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1305 </i18n:singular> |
1de952fd479e
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:plural> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1307 There are <a href="$link" title="View things">${num} things</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1308 </i18n:plural> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1309 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1310 </html>""") |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1311 translations = DummyTranslations({ |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1312 'Things': 'Sachen', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1313 'View thing': 'Sache betrachten', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1314 'View things': 'Sachen betrachten', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1315 ('There is [1:%(num)s thing].', 0): 'Da ist [1:%(num)s Sache].', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1316 ('There is [1:%(num)s thing].', 1): 'Da sind [1:%(num)s Sachen].' |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1317 }) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1318 translator = Translator(translations) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1319 translator.setup(tmpl) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1320 self.assertEqual(u"""<html> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1321 <p title="Sachen"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1322 Da ist <a href="/things" title="Sache betrachten">1 Sache</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1323 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1324 </html>""", tmpl.generate(link="/things", num=1).render(encoding=None)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1325 self.assertEqual(u"""<html> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1326 <p title="Sachen"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1327 Da sind <a href="/things" title="Sachen betrachten">3 Sachen</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1328 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1329 </html>""", tmpl.generate(link="/things", num=3).render(encoding=None)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1330 |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1331 def test_extract_i18n_choose_as_element_with_attributes(self): |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1332 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1333 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1334 <i18n:choose numeral="num" params="num"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1335 <p i18n:singular="" title="Things"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1336 There is <a href="$link" title="View thing">${num} thing</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1337 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1338 <p i18n:plural="" title="Things"> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1339 There are <a href="$link" title="View things">${num} things</a>. |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1340 </p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1341 </i18n:choose> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1342 </html>""") |
1de952fd479e
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() |
1de952fd479e
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) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1345 messages = list(translator.extract(tmpl.stream)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1346 self.assertEqual(5, len(messages)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1347 self.assertEqual((4, None, 'Things', []), messages[0]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1348 self.assertEqual((5, None, 'View thing', []), messages[1]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1349 self.assertEqual((7, None, 'Things', []), messages[2]) |
1de952fd479e
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((8, None, 'View things', []), messages[3]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1351 self.assertEqual( |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1352 (3, 'ngettext', ('There is [1:%(num)s thing].', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1353 'There are [1:%(num)s things].'), []), |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1354 messages[4]) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1355 |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1356 def test_translate_i18n_choose_as_element_with_attributes(self): |
892
1de952fd479e
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/" |
1de952fd479e
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"> |
1de952fd479e
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"> |
1de952fd479e
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"> |
1de952fd479e
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>. |
1de952fd479e
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> |
1de952fd479e
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"> |
1de952fd479e
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>. |
1de952fd479e
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> |
1de952fd479e
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> |
1de952fd479e
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>""") |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1368 translations = DummyTranslations({ |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1369 'Things': 'Sachen', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1370 'View thing': 'Sache betrachten', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1371 'View things': 'Sachen betrachten', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1372 ('There is [1:%(num)s thing].', 0): 'Da ist [1:%(num)s Sache].', |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1373 ('There is [1:%(num)s thing].', 1): 'Da sind [1:%(num)s Sachen].' |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1374 }) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1375 translator = Translator(translations) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1376 translator.setup(tmpl) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1377 self.assertEqual(u"""<html> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1378 <p title="Sachen">Da ist <a href="/things" title="Sache betrachten">1 Sache</a>.</p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1379 </html>""", tmpl.generate(link="/things", num=1).render(encoding=None)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1380 self.assertEqual(u"""<html> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1381 <p title="Sachen">Da sind <a href="/things" title="Sachen betrachten">3 Sachen</a>.</p> |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1382 </html>""", tmpl.generate(link="/things", num=3).render(encoding=None)) |
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1383 |
849 | 1384 def test_translate_i18n_choose_and_py_strip(self): |
1385 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1386 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1387 <div i18n:choose="two; fname, lname"> | |
1388 <p i18n:singular="">Foo $fname $lname</p> | |
1389 <p i18n:plural="">Foos $fname $lname</p> | |
1390 </div> | |
1391 </html>""") | |
1392 translations = DummyTranslations({ | |
1393 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1394 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1395 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1396 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1397 }) | |
1398 translator = Translator(translations) | |
1399 translator.setup(tmpl) | |
1400 self.assertEqual("""<html> | |
1401 <div> | |
1402 <p>Vohs John Doe</p> | |
1403 </div> | |
1404 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
1405 | |
1406 def test_translate_i18n_choose_and_domain_and_py_strip(self): | |
1407 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1408 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1409 i18n:domain="foo"> | |
1410 <div i18n:choose="two; fname, lname"> | |
1411 <p i18n:singular="">Foo $fname $lname</p> | |
1412 <p i18n:plural="">Foos $fname $lname</p> | |
1413 </div> | |
1414 </html>""") | |
1415 translations = DummyTranslations() | |
1416 translations.add_domain('foo', { | |
1417 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', | |
1418 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', | |
1419 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', | |
1420 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', | |
1421 }) | |
1422 translator = Translator(translations) | |
1423 translator.setup(tmpl) | |
1424 self.assertEqual("""<html> | |
1425 <div> | |
1426 <p>Vohs John Doe</p> | |
1427 </div> | |
1428 </html>""", tmpl.generate(two=2, fname='John', lname='Doe').render()) | |
871
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1429 |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1430 def test_translate_i18n_choose_and_singular_with_py_strip(self): |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1431 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1432 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1433 <div i18n:choose="two; fname, lname"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1434 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1435 <p i18n:plural="">Foos $fname $lname</p> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1436 </div> |
873
9786aa263217
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
|
1437 <div i18n:choose="one; fname, lname"> |
9786aa263217
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
|
1438 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
9786aa263217
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
|
1439 <p i18n:plural="">Foos $fname $lname</p> |
9786aa263217
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
|
1440 </div> |
871
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1441 </html>""") |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1442 translations = DummyTranslations({ |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1443 ('Foo %(fname)s %(lname)s', 0): 'Voh %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1444 ('Foo %(fname)s %(lname)s', 1): 'Vohs %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1445 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1446 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1447 }) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1448 translator = Translator(translations) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1449 translator.setup(tmpl) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1450 self.assertEqual("""<html> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1451 <div> |
873
9786aa263217
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
|
1452 <p>Vohs John Doe</p> |
871
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1453 </div> |
873
9786aa263217
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
|
1454 <div> |
9786aa263217
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
|
1455 Voh John Doe |
9786aa263217
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
|
1456 </div> |
9786aa263217
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
|
1457 </html>""", tmpl.generate( |
9786aa263217
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
|
1458 one=1, two=2, fname='John',lname='Doe').render()) |
871
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1459 |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1460 def test_translate_i18n_choose_and_plural_with_py_strip(self): |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1461 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1462 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1463 <div i18n:choose="two; fname, lname"> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1464 <p i18n:singular="" py:strip="">Foo $fname $lname</p> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1465 <p i18n:plural="">Foos $fname $lname</p> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1466 </div> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1467 </html>""") |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1468 translations = DummyTranslations({ |
7eb6f506bb54
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', 0): 'Voh %(fname)s %(lname)s', |
7eb6f506bb54
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', 1): 'Vohs %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1471 'Foo %(fname)s %(lname)s': 'Voh %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1472 'Foos %(fname)s %(lname)s': 'Vohs %(fname)s %(lname)s', |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1473 }) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1474 translator = Translator(translations) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1475 translator.setup(tmpl) |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1476 self.assertEqual("""<html> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1477 <div> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1478 Voh John Doe |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1479 </div> |
7eb6f506bb54
Allow the use of `i18n:singular` and `i18n:plural` as directives and not just as attributes.
palgarvio
parents:
869
diff
changeset
|
1480 </html>""", tmpl.generate(two=1, fname='John', lname='Doe').render()) |
849 | 1481 |
1482 def test_extract_i18n_choose_as_attribute_and_py_strip(self): | |
1483 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1484 xmlns:i18n="http://genshi.edgewall.org/i18n"> | |
1485 <div i18n:choose="one" py:strip=""> | |
1486 <p i18n:singular="" py:strip="">FooBar</p> | |
1487 <p i18n:plural="" py:strip="">FooBars</p> | |
1488 </div> | |
1489 </html>""") | |
1490 translator = Translator() | |
1491 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1492 messages = list(translator.extract(tmpl.stream)) | |
1493 self.assertEqual(1, len(messages)) | |
858 | 1494 self.assertEqual((3, 'ngettext', ('FooBar', 'FooBars'), []), messages[0]) |
849 | 1495 |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1496 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1497 class DomainDirectiveTestCase(unittest.TestCase): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1498 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1499 def test_translate_i18n_domain_with_msg_directives(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1500 #"""translate with i18n:domain and nested i18n:msg directives """ |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1501 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1502 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1503 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1504 <div i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1505 <p i18n:msg="">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1506 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1507 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1508 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1509 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1510 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1511 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1512 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1513 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1514 <div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1515 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1516 <p>PT_Foo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1517 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1518 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1519 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1520 def test_translate_i18n_domain_with_inline_directives(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1521 #"""translate with inlined i18n:domain and i18n:msg directives""" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1522 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1523 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1524 <p i18n:msg="" i18n:domain="foo">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1525 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1526 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1527 translations.add_domain('foo', {'FooBar': 'BarFoo'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1528 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1529 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1530 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1531 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1532 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1533 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1534 def test_translate_i18n_domain_without_msg_directives(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1535 #"""translate domain call without i18n:msg directives still uses current domain""" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1536 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1537 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1538 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1539 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1540 <div i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1541 <p i18n:msg="">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1542 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1543 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1544 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1545 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1546 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1547 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1548 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1549 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1550 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1551 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1552 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1553 <div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1554 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1555 <p>PT_Foo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1556 <p>PT_Foo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1557 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1558 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1559 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1560 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1561 def test_translate_i18n_domain_as_directive_not_attribute(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1562 #"""translate with domain as directive""" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1563 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1564 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1565 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1566 <i18n:domain name="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1567 <p i18n:msg="">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1568 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1569 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1570 </i18n:domain> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1571 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1572 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1573 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1574 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'PT_Foo'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1575 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1576 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1577 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1578 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1579 <p>PT_Foo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1580 <p>PT_Foo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1581 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1582 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1583 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1584 def test_translate_i18n_domain_nested_directives(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1585 #"""translate with nested i18n:domain directives""" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1586 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1587 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1588 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1589 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1590 <div i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1591 <p i18n:msg="">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1592 <p i18n:domain="bar" i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1593 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1594 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1595 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1596 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1597 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1598 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'foo_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1599 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1600 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1601 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1602 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1603 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1604 <div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1605 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1606 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1607 <p>foo_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1608 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1609 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1610 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1611 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1612 def test_translate_i18n_domain_with_empty_nested_domain_directive(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1613 #"""translate with empty nested i18n:domain directive does not use dngettext""" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1614 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1615 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1616 xmlns:i18n="http://genshi.edgewall.org/i18n"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1617 <p i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1618 <div i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1619 <p i18n:msg="">FooBar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1620 <p i18n:domain="" i18n:msg="">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1621 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1622 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1623 <p>Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1624 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1625 translations = DummyTranslations({'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1626 translations.add_domain('foo', {'FooBar': 'BarFoo', 'Bar': 'foo_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1627 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1628 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1629 translator.setup(tmpl) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1630 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1631 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1632 <div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1633 <p>BarFoo</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1634 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1635 <p>foo_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1636 </div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1637 <p>Voh</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1638 </html>""", tmpl.generate().render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1639 |
849 | 1640 def test_translate_i18n_domain_with_inline_directive_on_START_NS(self): |
1641 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1642 xmlns:i18n="http://genshi.edgewall.org/i18n" i18n:domain="foo"> | |
1643 <p i18n:msg="">FooBar</p> | |
1644 </html>""") | |
1645 translations = DummyTranslations({'Bar': 'Voh'}) | |
1646 translations.add_domain('foo', {'FooBar': 'BarFoo'}) | |
1647 translator = Translator(translations) | |
1648 translator.setup(tmpl) | |
1649 self.assertEqual("""<html> | |
1650 <p>BarFoo</p> | |
1651 </html>""", tmpl.generate().render()) | |
1652 | |
1653 def test_translate_i18n_domain_with_inline_directive_on_START_NS_with_py_strip(self): | |
1654 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" | |
1655 xmlns:i18n="http://genshi.edgewall.org/i18n" | |
1656 i18n:domain="foo" py:strip=""> | |
1657 <p i18n:msg="">FooBar</p> | |
1658 </html>""") | |
1659 translations = DummyTranslations({'Bar': 'Voh'}) | |
1660 translations.add_domain('foo', {'FooBar': 'BarFoo'}) | |
1661 translator = Translator(translations) | |
1662 translator.setup(tmpl) | |
1663 self.assertEqual(""" | |
1664 <p>BarFoo</p> | |
1665 """, tmpl.generate().render()) | |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1666 |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1667 def test_translate_i18n_domain_with_nested_includes(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1668 import os, shutil, tempfile |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1669 from genshi.template.loader import TemplateLoader |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1670 dirname = tempfile.mkdtemp(suffix='genshi_test') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1671 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1672 for idx in range(7): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1673 file1 = open(os.path.join(dirname, 'tmpl%d.html' % idx), 'w') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1674 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1675 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1676 xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1677 xmlns:i18n="http://genshi.edgewall.org/i18n" py:strip=""> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1678 <div>Included tmpl$idx</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1679 <p i18n:msg="idx">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1680 <p i18n:domain="bar">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1681 <p i18n:msg="idx" i18n:domain="">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1682 <p i18n:domain="" i18n:msg="idx">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1683 <py:if test="idx < 6"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1684 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1685 </py:if> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1686 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1687 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1688 file1.close() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1689 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1690 file2 = open(os.path.join(dirname, 'tmpl10.html'), 'w') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1691 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1692 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1693 xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1694 xmlns:i18n="http://genshi.edgewall.org/i18n" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1695 i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1696 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1697 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1698 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1699 file2.close() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1700 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1701 def callback(template): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1702 translations = DummyTranslations({'Bar %(idx)s': 'Voh %(idx)s'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1703 translations.add_domain('foo', {'Bar %(idx)s': 'foo_Bar %(idx)s'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1704 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1705 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1706 translator.setup(template) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1707 loader = TemplateLoader([dirname], callback=callback) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1708 tmpl = loader.load('tmpl10.html') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1709 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1710 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1711 <div>Included tmpl0</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1712 <p>foo_Bar 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1713 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1714 <p>Voh 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1715 <p>Voh 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1716 <div>Included tmpl1</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1717 <p>foo_Bar 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1718 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1719 <p>Voh 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1720 <p>Voh 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1721 <div>Included tmpl2</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1722 <p>foo_Bar 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1723 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1724 <p>Voh 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1725 <p>Voh 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1726 <div>Included tmpl3</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1727 <p>foo_Bar 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1728 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1729 <p>Voh 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1730 <p>Voh 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1731 <div>Included tmpl4</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1732 <p>foo_Bar 4</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1733 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1734 <p>Voh 4</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1735 <p>Voh 4</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1736 <div>Included tmpl5</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1737 <p>foo_Bar 5</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1738 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1739 <p>Voh 5</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1740 <p>Voh 5</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1741 <div>Included tmpl6</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1742 <p>foo_Bar 6</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1743 <p>bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1744 <p>Voh 6</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1745 <p>Voh 6</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1746 </html>""", tmpl.generate(idx=-1).render()) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1747 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1748 shutil.rmtree(dirname) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1749 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1750 def test_translate_i18n_domain_with_nested_includes_with_translatable_attrs(self): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1751 import os, shutil, tempfile |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1752 from genshi.template.loader import TemplateLoader |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1753 dirname = tempfile.mkdtemp(suffix='genshi_test') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1754 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1755 for idx in range(4): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1756 file1 = open(os.path.join(dirname, 'tmpl%d.html' % idx), 'w') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1757 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1758 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1759 xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1760 xmlns:i18n="http://genshi.edgewall.org/i18n" py:strip=""> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1761 <div>Included tmpl$idx</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1762 <p title="${dg('foo', 'Bar %(idx)s') % dict(idx=idx)}" i18n:msg="idx">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1763 <p title="Bar" i18n:domain="bar">Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1764 <p title="Bar" i18n:msg="idx" i18n:domain="">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1765 <p i18n:msg="idx" i18n:domain="" title="Bar">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1766 <p i18n:domain="" i18n:msg="idx" title="Bar">Bar $idx</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1767 <py:if test="idx < 3"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1768 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1769 </py:if> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1770 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1771 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1772 file1.close() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1773 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1774 file2 = open(os.path.join(dirname, 'tmpl10.html'), 'w') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1775 try: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1776 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1777 xmlns:py="http://genshi.edgewall.org/" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1778 xmlns:i18n="http://genshi.edgewall.org/i18n" |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1779 i18n:domain="foo"> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1780 <xi:include href="tmpl${idx}.html" py:with="idx = idx+1"/> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1781 </html>""") |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1782 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1783 file2.close() |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1784 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1785 translations = DummyTranslations({'Bar %(idx)s': 'Voh %(idx)s', |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1786 'Bar': 'Voh'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1787 translations.add_domain('foo', {'Bar %(idx)s': 'foo_Bar %(idx)s'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1788 translations.add_domain('bar', {'Bar': 'bar_Bar'}) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1789 translator = Translator(translations) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1790 |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1791 def callback(template): |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1792 translator.setup(template) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1793 loader = TemplateLoader([dirname], callback=callback) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1794 tmpl = loader.load('tmpl10.html') |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1795 |
916 | 1796 if IS_PYTHON2: |
1797 dgettext = translations.dugettext | |
1798 else: | |
1799 dgettext = translations.dgettext | |
1800 | |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1801 self.assertEqual("""<html> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1802 <div>Included tmpl0</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1803 <p title="foo_Bar 0">foo_Bar 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1804 <p title="bar_Bar">bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1805 <p title="Voh">Voh 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1806 <p title="Voh">Voh 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1807 <p title="Voh">Voh 0</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1808 <div>Included tmpl1</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1809 <p title="foo_Bar 1">foo_Bar 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1810 <p title="bar_Bar">bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1811 <p title="Voh">Voh 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1812 <p title="Voh">Voh 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1813 <p title="Voh">Voh 1</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1814 <div>Included tmpl2</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1815 <p title="foo_Bar 2">foo_Bar 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1816 <p title="bar_Bar">bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1817 <p title="Voh">Voh 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1818 <p title="Voh">Voh 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1819 <p title="Voh">Voh 2</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1820 <div>Included tmpl3</div> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1821 <p title="foo_Bar 3">foo_Bar 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1822 <p title="bar_Bar">bar_Bar</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1823 <p title="Voh">Voh 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1824 <p title="Voh">Voh 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1825 <p title="Voh">Voh 3</p> |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1826 </html>""", tmpl.generate(idx=-1, |
916 | 1827 dg=dgettext).render()) |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1828 finally: |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1829 shutil.rmtree(dirname) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1830 |
892
1de952fd479e
i18n: Support extraction of attributes in markup embedded in ``i18n:msg`` and ``i18n:choose`` directives. See also #380.
cmlenz
parents:
873
diff
changeset
|
1831 |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1832 class ExtractTestCase(unittest.TestCase): |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1833 |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1834 def test_markup_template_extraction(self): |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1835 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1836 <head> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1837 <title>Example</title> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1838 </head> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1839 <body> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1840 <h1>Example</h1> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1841 <p>${_("Hello, %(name)s") % dict(name=username)}</p> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1842 <p>${ngettext("You have %d item", "You have %d items", num)}</p> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1843 </body> |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1844 </html>""") |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1845 results = list(extract(buf, ['_', 'ngettext'], [], {})) |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1846 self.assertEqual([ |
858 | 1847 (3, None, 'Example', []), |
1848 (6, None, 'Example', []), | |
1849 (7, '_', 'Hello, %(name)s', []), | |
1850 (8, 'ngettext', ('You have %d item', 'You have %d items', None), | |
565
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1851 []), |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1852 ], results) |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1853 |
596
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1854 def test_extraction_without_text(self): |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1855 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1856 <p title="Bar">Foo</p> |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1857 ${ngettext("Singular", "Plural", num)} |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1858 </html>""") |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1859 results = list(extract(buf, ['_', 'ngettext'], [], { |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1860 'extract_text': 'no' |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1861 })) |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1862 self.assertEqual([ |
858 | 1863 (3, 'ngettext', ('Singular', 'Plural', None), []), |
596
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1864 ], results) |
f436c7db99f5
Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
cmlenz
parents:
594
diff
changeset
|
1865 |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1866 def test_text_template_extraction(self): |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1867 buf = StringIO("""${_("Dear %(name)s") % {'name': name}}, |
849 | 1868 |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1869 ${ngettext("Your item:", "Your items", len(items))} |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1870 #for item in items |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1871 * $item |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1872 #end |
849 | 1873 |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1874 All the best, |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1875 Foobar""") |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1876 results = list(extract(buf, ['_', 'ngettext'], [], { |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1877 'template_class': 'genshi.template:TextTemplate' |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1878 })) |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1879 self.assertEqual([ |
858 | 1880 (1, '_', 'Dear %(name)s', []), |
1881 (3, 'ngettext', ('Your item:', 'Your items', None), []), | |
1882 (7, None, 'All the best,\n Foobar', []) | |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1883 ], results) |
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1884 |
565
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1885 def test_extraction_with_keyword_arg(self): |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1886 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1887 ${gettext('Foobar', foo='bar')} |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1888 </html>""") |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1889 results = list(extract(buf, ['gettext'], [], {})) |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1890 self.assertEqual([ |
858 | 1891 (2, 'gettext', ('Foobar'), []), |
565
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1892 ], results) |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1893 |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1894 def test_extraction_with_nonstring_arg(self): |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1895 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1896 ${dgettext(curdomain, 'Foobar')} |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1897 </html>""") |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1898 results = list(extract(buf, ['dgettext'], [], {})) |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1899 self.assertEqual([ |
858 | 1900 (2, 'dgettext', (None, 'Foobar'), []), |
565
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1901 ], results) |
aa8e85a4085e
* The I18n extractor now handles gettext function calls that use non-string parameters as well as keyword arguments.
cmlenz
parents:
560
diff
changeset
|
1902 |
549
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1903 def test_extraction_inside_ignored_tags(self): |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1904 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1905 <script type="text/javascript"> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1906 $('#llist').tabs({ |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1907 remote: true, |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1908 spinner: "${_('Please wait...')}" |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1909 }); |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1910 </script> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1911 </html>""") |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1912 results = list(extract(buf, ['_'], [], {})) |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1913 self.assertEqual([ |
858 | 1914 (5, '_', 'Please wait...', []), |
549
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1915 ], results) |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1916 |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1917 def test_extraction_inside_ignored_tags_with_directives(self): |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1918 buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1919 <script type="text/javascript"> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1920 <py:if test="foobar"> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1921 alert("This shouldn't be extracted"); |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1922 </py:if> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1923 </script> |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1924 </html>""") |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1925 self.assertEqual([], list(extract(buf, ['_'], [], {}))) |
da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
cmlenz
parents:
535
diff
changeset
|
1926 |
849 | 1927 def test_extract_py_def_directive_with_py_strip(self): |
1928 # Failed extraction from Trac | |
1929 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/" py:strip=""> | |
1930 <py:def function="diff_options_fields(diff)"> | |
1931 <label for="style">View differences</label> | |
1932 <select id="style" name="style"> | |
1933 <option selected="${diff.style == 'inline' or None}" | |
1934 value="inline">inline</option> | |
1935 <option selected="${diff.style == 'sidebyside' or None}" | |
1936 value="sidebyside">side by side</option> | |
1937 </select> | |
1938 <div class="field"> | |
1939 Show <input type="text" name="contextlines" id="contextlines" size="2" | |
1940 maxlength="3" value="${diff.options.contextlines < 0 and 'all' or diff.options.contextlines}" /> | |
1941 <label for="contextlines">lines around each change</label> | |
1942 </div> | |
1943 <fieldset id="ignore" py:with="options = diff.options"> | |
1944 <legend>Ignore:</legend> | |
1945 <div class="field"> | |
1946 <input type="checkbox" id="ignoreblanklines" name="ignoreblanklines" | |
1947 checked="${options.ignoreblanklines or None}" /> | |
1948 <label for="ignoreblanklines">Blank lines</label> | |
1949 </div> | |
1950 <div class="field"> | |
1951 <input type="checkbox" id="ignorecase" name="ignorecase" | |
1952 checked="${options.ignorecase or None}" /> | |
1953 <label for="ignorecase">Case changes</label> | |
1954 </div> | |
1955 <div class="field"> | |
1956 <input type="checkbox" id="ignorewhitespace" name="ignorewhitespace" | |
1957 checked="${options.ignorewhitespace or None}" /> | |
1958 <label for="ignorewhitespace">White space changes</label> | |
1959 </div> | |
1960 </fieldset> | |
1961 <div class="buttons"> | |
1962 <input type="submit" name="update" value="${_('Update')}" /> | |
1963 </div> | |
1964 </py:def></html>""") | |
1965 translator = Translator() | |
1966 tmpl.add_directives(Translator.NAMESPACE, translator) | |
1967 messages = list(translator.extract(tmpl.stream)) | |
1968 self.assertEqual(10, len(messages)) | |
1969 self.assertEqual([ | |
858 | 1970 (3, None, 'View differences', []), |
1971 (6, None, 'inline', []), | |
1972 (8, None, 'side by side', []), | |
1973 (10, None, 'Show', []), | |
1974 (13, None, 'lines around each change', []), | |
1975 (16, None, 'Ignore:', []), | |
1976 (20, None, 'Blank lines', []), | |
1977 (25, None, 'Case changes',[]), | |
1978 (30, None, 'White space changes', []), | |
1979 (34, '_', 'Update', [])], messages) | |
849 | 1980 |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1981 |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1982 def suite(): |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1983 suite = unittest.TestSuite() |
709
a7b0d320aea4
Python 2.3 compatibility fixes for transformer and (specifically for 2.3.1) i18n.
athomas
parents:
667
diff
changeset
|
1984 suite.addTest(doctest.DocTestSuite(Translator.__module__)) |
485
770ba8556940
Follow-up to [583]: Don't extract strings from interpolated attribute values for attributes that shouldn't be included.
cmlenz
parents:
446
diff
changeset
|
1985 suite.addTest(unittest.makeSuite(TranslatorTestCase, 'test')) |
894
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1986 suite.addTest(unittest.makeSuite(MsgDirectiveTestCase, 'test')) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1987 suite.addTest(unittest.makeSuite(ChooseDirectiveTestCase, 'test')) |
6fe4feb2635b
Split up the i18n unit tests into per-directive test cases.
cmlenz
parents:
893
diff
changeset
|
1988 suite.addTest(unittest.makeSuite(DomainDirectiveTestCase, 'test')) |
528
f38ce008ab0a
Integrated [http://babel.edgewall.org/ Babel] message extraction plugin, and added I18n doc page.
cmlenz
parents:
522
diff
changeset
|
1989 suite.addTest(unittest.makeSuite(ExtractTestCase, 'test')) |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1990 return suite |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1991 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1992 if __name__ == '__main__': |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1993 unittest.main(defaultTest='suite') |