annotate genshi/filters/tests/i18n.py @ 1018:fa0e84724fee stable-0.6.x

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