Mercurial > genshi > genshi-test
annotate genshi/filters/tests/i18n.py @ 523:5b59e911e6c3 stable-0.4.x
Ported [626] to 0.4.x branch.
author | cmlenz |
---|---|
date | Fri, 15 Jun 2007 20:19:29 +0000 |
parents | 6a48853a2e36 |
children | f38ce008ab0a |
rev | line source |
---|---|
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
2 # |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
5 # |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
9 # |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
13 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
14 import doctest |
486 | 15 from StringIO import StringIO |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
16 import unittest |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
17 |
486 | 18 from genshi.template import MarkupTemplate |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
19 from genshi.filters.i18n import Translator |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
20 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
21 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
22 class TranslatorTestCase(unittest.TestCase): |
486 | 23 |
24 def test_extract_plural_form(self): | |
25 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
26 ${ngettext("Singular", "Plural", num)} | |
27 </html>""") | |
28 translator = Translator() | |
29 messages = list(translator.extract(tmpl.stream)) | |
30 self.assertEqual(1, len(messages)) | |
31 self.assertEqual((2, 'ngettext', (u'Singular', u'Plural')), messages[0]) | |
32 | |
33 def test_extract_included_attribute_text(self): | |
34 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
35 <span title="Foo"></span> | |
36 </html>""") | |
37 translator = Translator() | |
38 messages = list(translator.extract(tmpl.stream)) | |
39 self.assertEqual(1, len(messages)) | |
40 self.assertEqual((2, None, u'Foo'), messages[0]) | |
41 | |
42 def test_extract_attribute_expr(self): | |
43 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
44 <input type="submit" value="${_('Save')}" /> | |
45 </html>""") | |
46 translator = Translator() | |
47 messages = list(translator.extract(tmpl.stream)) | |
48 self.assertEqual(1, len(messages)) | |
49 self.assertEqual((2, '_', u'Save'), messages[0]) | |
50 | |
51 def test_extract_non_included_attribute_interpolated(self): | |
52 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
53 <a href="#anchor_${num}">Foo</a> | |
54 </html>""") | |
55 translator = Translator() | |
56 messages = list(translator.extract(tmpl.stream)) | |
57 self.assertEqual(1, len(messages)) | |
58 self.assertEqual((2, None, u'Foo'), messages[0]) | |
59 | |
60 def test_extract_text_from_sub(self): | |
61 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
62 <py:if test="foo">Foo</py:if> | |
63 </html>""") | |
64 translator = Translator() | |
65 messages = list(translator.extract(tmpl.stream)) | |
66 self.assertEqual(1, len(messages)) | |
67 self.assertEqual((2, None, u'Foo'), messages[0]) | |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
68 |
523 | 69 def test_ignore_tag_with_fixed_xml_lang(self): |
70 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
71 <p xml:lang="en">(c) 2007 Edgewall Software</p> | |
72 </html>""") | |
73 translator = Translator() | |
74 messages = list(translator.extract(tmpl.stream)) | |
75 self.assertEqual(0, len(messages)) | |
76 | |
77 def test_extract_tag_with_variable_xml_lang(self): | |
78 tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> | |
79 <p xml:lang="${lang}">(c) 2007 Edgewall Software</p> | |
80 </html>""") | |
81 translator = Translator() | |
82 messages = list(translator.extract(tmpl.stream)) | |
83 self.assertEqual(1, len(messages)) | |
84 self.assertEqual((2, None, u'(c) 2007 Edgewall Software'), messages[0]) | |
85 | |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
86 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
87 def suite(): |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
88 suite = unittest.TestSuite() |
486 | 89 suite.addTest(unittest.makeSuite(TranslatorTestCase, 'test')) |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
90 suite.addTests(doctest.DocTestSuite(Translator.__module__)) |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
91 return suite |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
92 |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
93 if __name__ == '__main__': |
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
diff
changeset
|
94 unittest.main(defaultTest='suite') |