예제 #1
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_ignore_attribute_with_expression(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="Reply" title="Reply to comment $num" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
예제 #2
0
파일: i18n.py 프로젝트: alon/polinax
 def test_ignore_attribute_with_expression(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="Reply" title="Reply to comment $num" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
예제 #3
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_ignore_tag_with_fixed_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="en">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
예제 #4
0
파일: i18n.py 프로젝트: alon/polinax
 def test_ignore_tag_with_fixed_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="en">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
예제 #5
0
def extract_genshi_strings(filename, options=None):
    """Extract translatable strings from a Genshi template.

    The extractor will get all the text inside all elements which are
    not in the ignore list (see options) and the values of all
    attributes named in the include list.

    Options:

    `ignore_tags` -- `'script style'`
        List of element names. Content inside elements named in
        this list is not extracted as translatable text. Can be a
        space-separated string or a list of string.
    `include_attrs` -- `'abbr alt label prompt standby summary title'`
        List of attribute names. Only values of the attributes named in this
        list are extracted as translatable text. Can be a space-separated
        string or a list of string.

    See http://genshi.edgewall.org/wiki/Documentation/0.5.x/i18n.html for
    more information.

    """

    if not GenshiMarkupTemplate:
        raise ImportError("Genshi templating is not installed.")

    if options is None:
        options = {}

    tmpl = open(filename)
    stream = GenshiMarkupTemplate(tmpl, filename=filename).stream
    translator = GenshiTranslator(**options)
    return translator.extract(stream)
예제 #6
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_text_from_sub(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <py:if test="foo">Foo</py:if>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo', []), messages[0])
예제 #7
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_non_included_attribute_interpolated(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <a href="#anchor_${num}">Foo</a>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo', []), messages[0])
예제 #8
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_text_from_sub(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <py:if test="foo">Foo</py:if>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
예제 #9
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_tag_with_variable_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="${lang}">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'(c) 2007 Edgewall Software'), messages[0])
예제 #10
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_gettext_with_unicode_string(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${gettext("Grüße")}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'gettext', u'Gr\xfc\xdfe'), messages[0])
예제 #11
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_included_attribute_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <span title="Foo"></span>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
예제 #12
0
파일: i18n.py 프로젝트: tsondt/Canvas
 def test_extract_tag_with_variable_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="${lang}">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'(c) 2007 Edgewall Software'), messages[0])
예제 #13
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_funky_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext(len(items), *widget.display_names)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (None, None)), messages[0])
예제 #14
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_attribute_expr(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="${_('Save')}" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, '_', u'Save'), messages[0])
예제 #15
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_attribute_expr(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="${_('Save')}" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, '_', u'Save', []), messages[0])
예제 #16
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_non_included_attribute_interpolated(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <a href="#anchor_${num}">Foo</a>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
예제 #17
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_included_attribute_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <span title="Foo"></span>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo', []), messages[0])
예제 #18
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_gettext_with_unicode_string(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${gettext("Grüße")}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'gettext', u'Gr\xfc\xdfe', []), messages[0])
예제 #19
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_funky_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext(len(items), *widget.display_names)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (None, None), []), messages[0])
예제 #20
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (u'Singular', u'Plural', None)),
                      messages[0])
예제 #21
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_with_comment(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="" i18n:comment="As in foo bar">Foo</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((3, None, u'Foo', ['As in foo bar']), messages[0])
예제 #22
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (u'Singular', u'Plural', None), []),
                      messages[0])
예제 #23
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_without_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p title="Bar">Foo</p>
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator(extract_text=False)
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((3, 'ngettext', (u'Singular', u'Plural', None)),
                      messages[0])
예제 #24
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_without_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p title="Bar">Foo</p>
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator(extract_text=False)
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((3, 'ngettext', (u'Singular', u'Plural', None), []),
                      messages[0])
예제 #25
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_i18n_msg_with_directive(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Show me <input type="text" name="num" py:attrs="{'value': x}" /> entries per page.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Show me [1:] entries per page.', messages[0][2])
예제 #26
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_i18n_msg_with_two_params(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="name, time">
         Posted by ${post.author} at ${entry.time.strftime('%H:%m')}
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Posted by %(name)s at %(time)s', messages[0][2])
예제 #27
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_i18n_msg_with_param(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="name">
         Hello, ${user.name}!
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Hello, %(name)s!', messages[0][2])
예제 #28
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_with_two_params(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="name, time">
         Posted by ${post.author} at ${entry.time.strftime('%H:%m')}
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Posted by %(name)s at %(time)s', messages[0][2])
예제 #29
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_multiple(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Please see <a href="help.html">Help</a> for <em>details</em>.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Please see [1:Help] for [2:details].', messages[0][2])
예제 #30
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_with_directive(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Show me <input type="text" name="num" py:attrs="{'value': x}" /> entries per page.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Show me [1:] entries per page.', messages[0][2])
예제 #31
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_i18n_msg_multiple(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Please see <a href="help.html">Help</a> for <em>details</em>.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Please see [1:Help] for [2:details].', messages[0][2])
예제 #32
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_with_param(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="name">
         Hello, ${user.name}!
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Hello, %(name)s!', messages[0][2])
예제 #33
0
파일: i18n.py 프로젝트: e2pluginss/plexnet
 def test_extract_i18n_msg_multiple_empty(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Show me <input type="text" name="num" /> entries per page, starting at page <input type="text" name="num" />.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Show me [1:] entries per page, starting at page [2:].',
                      messages[0][2])
예제 #34
0
파일: i18n.py 프로젝트: alon/polinax
 def test_extract_i18n_msg_multiple_empty(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Show me <input type="text" name="num" /> entries per page, starting at page <input type="text" name="num" />.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Show me [1:] entries per page, starting at page [2:].',
                      messages[0][2])