Skip to content

Commit 6b10012

Browse files
committed
Generate JavaScript translations directly from PO catalogs
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5
1 parent bd78daa commit 6b10012

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

‎babel_runner.py‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import tomllib
1010
from pathlib import Path
1111

12-
from babel.messages.mofile import read_mo
1312
from babel.messages.pofile import read_po
1413
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1514

@@ -121,25 +120,22 @@ def compile_catalogs(locale: str) -> None:
121120

122121

123122
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."""
126124
jsfile = pofile.with_suffix(".js")
127-
if not mofile.exists():
128-
jsfile.unlink(missing_ok=True)
129-
return
130125
with pofile.open("rb") as f:
131126
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
134130
messages = {}
135131
for message in source:
136132
if not isinstance(message.id, str):
137133
continue
138134
if not any(filename.endswith(".js") for filename, _ in message.locations):
139135
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
143139
jsfile.write_text(
144140
f"// {DOMAIN} translations for {pofile.parents[1].name}\n"
145141
"Object.assign(Documentation.TRANSLATIONS, "

0 commit comments

Comments
 (0)