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