|
9 | 9 | import tomllib |
10 | 10 | from pathlib import Path |
11 | 11 |
|
12 | | -from babel.messages.mofile import read_mo |
13 | 12 | from babel.messages.pofile import read_po |
14 | 13 | from hatchling.builders.hooks.plugin.interface import BuildHookInterface |
15 | 14 |
|
@@ -121,25 +120,22 @@ def compile_catalogs(locale: str) -> None: |
121 | 120 |
|
122 | 121 |
|
123 | 122 | def compile_js_catalog(pofile: Path) -> None: |
124 | | - """Export translated singular JavaScript messages from the compiled catalog.""" |
125 | | - mofile = pofile.with_suffix(".mo") |
| 123 | + """Export translated singular JavaScript messages from the PO catalog.""" |
126 | 124 | jsfile = pofile.with_suffix(".js") |
127 | | - if not mofile.exists(): |
128 | | - jsfile.unlink(missing_ok=True) |
129 | | - return |
130 | 125 | with pofile.open("rb") as f: |
131 | 126 | source = read_po(f) |
132 | | - with mofile.open("rb") as f: |
133 | | - compiled = read_mo(f) |
| 127 | + if source.fuzzy: |
| 128 | + jsfile.unlink(missing_ok=True) |
| 129 | + return |
134 | 130 | messages = {} |
135 | 131 | for message in source: |
136 | 132 | if not isinstance(message.id, str): |
137 | 133 | continue |
138 | 134 | if not any(filename.endswith(".js") for filename, _ in message.locations): |
139 | 135 | continue |
140 | | - translation = compiled.get(message.id) |
141 | | - if translation is not None and translation.string: |
142 | | - messages[message.id] = translation.string |
| 136 | + if message.context is not None or message.fuzzy or not message.string: |
| 137 | + continue |
| 138 | + messages[message.id] = message.string |
143 | 139 | jsfile.write_text( |
144 | 140 | f"// {DOMAIN} translations for {pofile.parents[1].name}\n" |
145 | 141 | "Object.assign(Documentation.TRANSLATIONS, " |
|
0 commit comments