Пример #1
0
def test_extract_from_method_calls(tmpdir):
    tmpdir.join('foo.py').write("""
print tr._('hello')
print tr.gettext('world')
print tr.ngettext('orange', 'oranges', 1)
""")
    tr = Translator(tmpdir, ['it_IT'], autocompile=False)
    tr.extract()
    pot = tmpdir.join('languages', 'template.pot').read()
    assert 'hello' in pot
    assert 'world' in pot
    assert 'orange' in pot
Пример #2
0
def test_translate_string(tmpdir):
    languages = ['it_IT']
    tmpdir.join('foo.py').write("print _('hello')")
    tr = Translator(tmpdir, languages, autocompile=False)
    tr.extract()
    it_IT = tr.get_po('it_IT')
    it_IT_text = it_IT.read()
    assert 'hello' in it_IT_text
    #
    add_translation(it_IT, 'hello', 'ciao')
    tr.compile()
    tr.reload()
    assert tr._('hello') == 'ciao'
Пример #3
0
def main(argv):
    from i18n.translator import Translator
    parser = get_parser()
    args = parser.parse_args(argv[1:])
    if args.root.check(dir=False):
        parser.error('Not a directory: %s' % args.root)
    languages = map(str.strip, args.languages.split(','))
    tr = Translator(args.root, languages, autocompile=False)
    if args.command == 'extract':
        tr.extract()
    elif args.command == 'compile':
        tr.compile()
    else:
        parser.error('Invalid command: %s' % args.command)
Пример #4
0
def test_extract_and_update(tmpdir):
    languages = ['it_IT']
    tmpdir.join('foo.py').write("print _('hello')")
    tr = Translator(tmpdir, languages, autocompile=False)
    tr.extract()
    # check that the template was extracted
    pot = tmpdir.join('languages', 'template.pot')
    assert 'hello' in pot.read()
    # check that the various translations has been initialized from the template
    it_IT = tmpdir.join('languages', 'it_IT', 'LC_MESSAGES', 'messages.po')
    it_IT_text = it_IT.read()
    assert 'hello' in it_IT_text
    #
    add_translation(it_IT, 'hello', 'ciao')
    #
    # add another string to translate in the source and extract again
    tmpdir.join('foo.py').write("print _('hello'), _('world')")
    tr.extract()
    assert 'world' in pot.read()
    #
    # check that it_IT has been merged correctly
    it_IT_text = it_IT.read()
    assert 'world' in it_IT_text
    assert 'ciao' in it_IT_text