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