MCPcopy Create free account
hub / github.com/comaps/comaps / _parse_one_file

Method _parse_one_file

tools/python/po_parser.py:60–89  ·  view source on GitHub ↗
(self, filepath, lang)

Source from the content-addressed store, hash-verified

58
59
60 def _parse_one_file(self, filepath, lang):
61 self.translations = defaultdict(str)
62 current_key = None
63 string_started = False
64 with open(filepath) as infile:
65 for line in infile:
66 if line.startswith("msgid"):
67 current_key = self.clean_line(line,"msgid")
68 elif line.startswith("msgstr"):
69 if not current_key:
70 continue
71 translation = self.clean_line(line, "msgstr")
72 if not translation:
73 print("No translation for key {} in file {}".format(current_key, filepath))
74 continue
75 self.dest_file.add_translation(
76 translation,
77 key="[{}]".format(current_key),
78 lang=lang
79 )
80 string_started = True
81
82 elif not line or line.startswith("#"):
83 string_started = False
84 current_key = None
85
86 else:
87 if not string_started:
88 continue
89 self.dest_file.append_to_translation(current_key, lang, self.clean_line(line))
90
91
92 def clean_line(self, line, prefix=""):

Callers 1

parse_filesMethod · 0.95

Calls 4

clean_lineMethod · 0.95
formatMethod · 0.80
add_translationMethod · 0.80
append_to_translationMethod · 0.80

Tested by

no test coverage detected