本文整理汇总了Python中translate.storage.test_base.first_translatable函数的典型用法代码示例。如果您正苦于以下问题:Python first_translatable函数的具体用法?Python first_translatable怎么用?Python first_translatable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了first_translatable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_romanian_nicio
def test_romanian_nicio(self):
"""Test the Romanian nicio check"""
posource = '''
msgid "cow"
msgstr "bla nici o bla"
'''
pofile = self.parse_text(posource)
filter_result = self.filter(pofile,
cmdlineoptions=["--language=ro",
"--test=niciun_nicio"])
errors = first_translatable(filter_result).geterrors()
assert len(errors) == 1
assert 'niciun_nicio' in errors
posource = '''
msgid "cow"
msgstr "bla nicio bla"
'''
pofile = self.parse_text(posource)
filter_result = self.filter(pofile,
cmdlineoptions=["--language=ro",
"--test=niciun_nicio"])
errors = first_translatable(filter_result).geterrors()
assert len(errors) == 0
assert 'niciun_nicio' not in errors
示例2: test_msgid_comments
def test_msgid_comments(self):
"""Tests that msgid comments don't feature anywhere."""
posource = 'msgid "_: Capital. ACRONYMN. (msgid) comment 3. %d Extra sentence.\\n"\n"cow"\nmsgstr "koei"\n'
pofile = self.parse_text(posource)
filter_result = self.filter(pofile)
if headerless_len(filter_result.units):
print first_translatable(filter_result)
assert headerless_len(filter_result.units) == 0
示例3: test_simplegrep
def test_simplegrep(self):
"""grep for a simple string."""
xliff_text = self.xliff_text
xliff_file = self.xliff_parse(xliff_text)
xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "rêd"))
assert first_translatable(xliff_result).getsource() == "rêd"
assert first_translatable(xliff_result).gettarget() == "rooi"
xliff_result = self.xliff_parse(self.xliff_grep(xliff_text, "unavailable string"))
assert xliff_result.isempty()
示例4: test_ignore_if_already_marked
def test_ignore_if_already_marked(self):
"""check that we don't add another failing marker if the message is already marked as failed"""
self.unit.target = ''
filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=untranslated"])
errors = first_translatable(filter_result).geterrors()
assert len(errors) == 1
assert errors.has_key('untranslated')
# Run a filter test on the result, to check that it doesn't mark the same error twice.
filter_result2 = self.filter(filter_result, cmdlineoptions=["--test=untranslated"])
errors = first_translatable(filter_result2).geterrors()
assert len(errors) == 1
assert errors.has_key('untranslated')
示例5: test_simplefail
def test_simplefail(self):
"""checks that an obviously wrong string fails"""
self.unit.target = "REST"
filter_result = self.filter(self.translationstore)
print filter_result
print filter_result.units
assert first_translatable(filter_result).geterrors().has_key('startcaps')
示例6: test_notes
def test_notes(self):
"""tests the optional adding of notes"""
# let's make sure we trigger the 'long' and/or 'doubleword' test
self.unit.target = u"asdf asdf asdf asdf asdf asdf asdf"
filter_result = self.filter(self.translationstore)
assert headerless_len(filter_result.units) == 1
assert first_translatable(filter_result).geterrors()
# now we remove the existing error. self.unit is changed since we copy
# units - very naughty
if isinstance(self.unit, xliff.xliffunit):
self.unit.removenotes(origin='pofilter')
else:
self.unit.removenotes()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--nonotes"])
assert headerless_len(filter_result.units) == 1
assert len(first_translatable(filter_result).geterrors()) == 0
示例7: test_isreview
def test_isreview(self):
"""tests the extraction of items marked review"""
filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isreview"])
assert headerless_len(filter_result.units) == 0
self.unit.markreviewneeded()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isreview"])
assert first_translatable(filter_result).isreview()
示例8: test_preconditions
def test_preconditions(self):
"""tests that the preconditions work correctly"""
self.unit.source = "File"
self.unit.target = ""
filter_result= self.filter(self.translationstore)
# We should only get one error (untranslated), and nothing else
assert headerless_len(filter_result.units) == 1
unit = first_translatable(filter_result)
assert len(unit.geterrors()) == 1
示例9: test_isfuzzy
def test_isfuzzy(self):
"""tests the extraction of items marked fuzzy"""
self.unit.markfuzzy()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isfuzzy"])
assert first_translatable(filter_result).geterrors().has_key('isfuzzy')
self.unit.markfuzzy(False)
filter_result = self.filter(self.translationstore, cmdlineoptions=["--test=isfuzzy"])
assert headerless_len(filter_result.units) == 0
示例10: test_translatorcomments
def test_translatorcomments(self):
"""Tests translator comments"""
minixlf = self.xliffskeleton % '''<trans-unit>
<source>nonsense</source>
<target>matlhapolosa</target>
<context-group name="po-entry" purpose="information">
<context context-type="x-po-trancomment">Couldn't do
it</context>
</context-group>
<note from="po-translator">Couldn't do
it</note>
</trans-unit>'''
pofile = self.xliff2po(minixlf)
assert pofile.translate("nonsense") == "matlhapolosa"
assert pofile.translate("bla") is None
unit = first_translatable(pofile)
assert unit.getnotes("translator") == "Couldn't do it"
potext = bytes(pofile).decode('utf-8')
assert potext.index("# Couldn't do it\n") >= 0
minixlf = self.xliffskeleton % '''<trans-unit xml:space="preserve">
<source>nonsense</source>
<target>matlhapolosa</target>
<context-group name="po-entry" purpose="information">
<context context-type="x-po-trancomment">Couldn't do
it</context>
</context-group>
<note from="po-translator">Couldn't do
it</note>
</trans-unit>'''
pofile = self.xliff2po(minixlf)
assert pofile.translate("nonsense") == "matlhapolosa"
assert pofile.translate("bla") is None
unit = first_translatable(pofile)
assert unit.getnotes("translator") == "Couldn't do\nit"
potext = bytes(pofile).decode('utf-8')
assert potext.index("# Couldn't do\n# it\n") >= 0
示例11: test_autocomment
def test_autocomment(self):
"""Tests automatic comments"""
minixlf = self.xliffskeleton % '''<trans-unit>
<source>nonsense</source>
<target>matlhapolosa</target>
<context-group name="po-entry" purpose="information">
<context context-type="x-po-autocomment">Note that this is
garbage</context>
</context-group>
<note from="developer">Note that this is
garbage</note>
</trans-unit>'''
pofile = self.xliff2po(minixlf)
assert pofile.translate("nonsense") == "matlhapolosa"
assert pofile.translate("bla") is None
unit = first_translatable(pofile)
assert unit.getnotes("developer") == "Note that this is garbage"
potext = bytes(pofile).decode('utf-8')
assert potext.index("#. Note that this is garbage\n") >= 0
minixlf = self.xliffskeleton % '''<trans-unit xml:space="preserve">
<source>nonsense</source>
<target>matlhapolosa</target>
<context-group name="po-entry" purpose="information">
<context context-type="x-po-autocomment">Note that this is
garbage</context>
</context-group>
<note from="developer">Note that this is
garbage</note>
</trans-unit>'''
pofile = self.xliff2po(minixlf)
assert pofile.translate("nonsense") == "matlhapolosa"
assert pofile.translate("bla") is None
unit = first_translatable(pofile)
assert unit.getnotes("developer") == "Note that this is\ngarbage"
potext = bytes(pofile).decode('utf-8')
assert potext.index("#. Note that this is\n#. garbage\n") >= 0
示例12: set_store_review
def set_store_review(self, review=True):
self.filetext = '''<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file datatype="po" original="example.po" source-language="en-US">
<body>
<trans-unit approved="yes">
<source>test</source>
<target>rest</target>
</trans-unit>
</body>
</file>
</xliff>'''
self.translationstore = self.parse_text(self.filetext)
self.unit = first_translatable(self.translationstore)
示例13: test_quotes
def test_quotes(self):
"""Test the escaping of quotes (and slash)"""
minicsv = r''',"Hello ""Everyone""","Good day ""All"""
,"Use \"".","Gebruik \""."'''
print(minicsv)
csvfile = csvl10n.csvfile(wStringIO.StringIO(minicsv))
print(bytes(csvfile))
pofile = self.csv2po(minicsv)
unit = first_translatable(pofile)
assert unit.source == 'Hello "Everyone"'
assert pofile.findunit('Hello "Everyone"').target == 'Good day "All"'
print(bytes(pofile))
for unit in pofile.units:
print(unit.source)
print(unit.target)
print()
示例14: test_test_against_review
def test_test_against_review(self):
"""test whether to run tests against translations marked for review"""
self.unit.markreviewneeded()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
assert first_translatable(filter_result).isreview()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--noreview"])
assert headerless_len(filter_result.units) == 0
# Re-initialize the translation store object.
self.setup_method(self)
filter_result = self.filter(self.translationstore, cmdlineoptions=["--review"])
assert headerless_len(filter_result.units) == 0
filter_result = self.filter(self.translationstore, cmdlineoptions=["--noreview"])
assert headerless_len(filter_result.units) == 0
示例15: test_test_against_fuzzy
def test_test_against_fuzzy(self):
"""test whether to run tests against fuzzy translations"""
self.unit.markfuzzy()
filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
assert first_translatable(filter_result).geterrors().has_key('isfuzzy')
filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
assert headerless_len(filter_result.units) == 0
# Re-initialize the translation store object in order to get an unfuzzy unit
# with no filter notes.
self.setup_method(self)
filter_result = self.filter(self.translationstore, cmdlineoptions=["--fuzzy"])
assert headerless_len(filter_result.units) == 0
filter_result = self.filter(self.translationstore, cmdlineoptions=["--nofuzzy"])
assert headerless_len(filter_result.units) == 0