(self, filepath, lang)
| 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=""): |
no test coverage detected