refactoring
This commit is contained in:
parent
564c63f0c1
commit
7fc6ba99de
|
@ -61,9 +61,17 @@ class GrammalecteChecker(Checker):
|
||||||
result = self.run_grammalecte(filename)
|
result = self.run_grammalecte(filename)
|
||||||
if result.stdout:
|
if result.stdout:
|
||||||
warnings = json.loads(result.stdout)
|
warnings = json.loads(result.stdout)
|
||||||
|
self.manage_grammar_errors(warnings, pofile)
|
||||||
|
Path(filename).unlink()
|
||||||
|
|
||||||
|
def check_item(self, item: PoItem):
|
||||||
|
"""Check an item in a `*.po` file (does nothing)."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def manage_grammar_errors(self, warnings, pofile: PoFile):
|
||||||
for warning in warnings["data"]:
|
for warning in warnings["data"]:
|
||||||
for error in warning["lGrammarErrors"]:
|
for error in warning["lGrammarErrors"]:
|
||||||
if self.filter_out(error):
|
if self.filter_out_grammar_error(error):
|
||||||
continue
|
continue
|
||||||
item_index = int(warning["iParagraph"]) // 2
|
item_index = int(warning["iParagraph"]) // 2
|
||||||
item = pofile.content[item_index]
|
item = pofile.content[item_index]
|
||||||
|
@ -71,19 +79,13 @@ class GrammalecteChecker(Checker):
|
||||||
end = max(0, int(error["nEnd"]) + 10)
|
end = max(0, int(error["nEnd"]) + 10)
|
||||||
item.add_warning(
|
item.add_warning(
|
||||||
self.name,
|
self.name,
|
||||||
# self.name + " " + error["sRuleId"], # TODO
|
|
||||||
error["sMessage"]
|
error["sMessage"]
|
||||||
+ " => ###"
|
+ " => ###"
|
||||||
+ item.msgstr_rst2txt[start:end]
|
+ item.msgstr_rst2txt[start:end]
|
||||||
+ "###",
|
+ "###",
|
||||||
)
|
)
|
||||||
Path(filename).unlink()
|
|
||||||
|
|
||||||
def check_item(self, item: PoItem):
|
def filter_out_grammar_error(self, error):
|
||||||
"""Check an item in a `*.po` file (does nothing)."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def filter_out(self, error):
|
|
||||||
"""Return True when grammalecte error should be ignored."""
|
"""Return True when grammalecte error should be ignored."""
|
||||||
msg = error["sRuleId"]
|
msg = error["sRuleId"]
|
||||||
if msg in (
|
if msg in (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user