annotate genshi/filters/tests/i18n.py @ 916:872726bac135 experimental-py3k

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