Repository navigation
Conversation
Documentation build overview
151 files changed ·
|
…rtifact paths alphabetically in pyproject.toml
| """Export translated singular JavaScript messages from the compiled catalog.""" | ||
| mofile = pofile.with_suffix(".mo") | ||
| jsfile = pofile.with_suffix(".js") | ||
| if not mofile.exists(): | ||
| jsfile.unlink(missing_ok=True) | ||
| return |
There was a problem hiding this comment.
We could simplify this function to only read the .po file, and skip the fuzzy/untranslated messages, rather than also reading the compiled .mo file?
| """Export translated singular JavaScript messages from the compiled catalog.""" | |
| mofile = pofile.with_suffix(".mo") | |
| jsfile = pofile.with_suffix(".js") | |
| if not mofile.exists(): | |
| jsfile.unlink(missing_ok=True) | |
| return | |
| """Export translated singular JavaScript messages from the catalog.""" | |
| jsfile = pofile.with_suffix(".js") |
There was a problem hiding this comment.
Thanks for suggestion, applied. On the other hand using .mo makes us reusing the same configuration of catalog compilation, but it's not worth the complication probably.
| with mofile.open("rb") as f: | ||
| compiled = read_mo(f) |
There was a problem hiding this comment.
| with mofile.open("rb") as f: | |
| compiled = read_mo(f) |
| compiled = read_mo(f) | ||
| messages = {} | ||
| for message in source: | ||
| if not isinstance(message.id, str): |
There was a problem hiding this comment.
| if not isinstance(message.id, str): | |
| if not isinstance(message.id, str) or message.fuzzy or not message.string: |
| translation = compiled.get(message.id) | ||
| if translation is not None and translation.string: | ||
| messages[message.id] = translation.string |
There was a problem hiding this comment.
| translation = compiled.get(message.id) | |
| if translation is not None and translation.string: | |
| messages[message.id] = translation.string | |
| messages[message.id] = message.string |
| import tomllib | ||
| from pathlib import Path | ||
|
|
||
| from babel.messages.mofile import read_mo |
There was a problem hiding this comment.
| from babel.messages.mofile import read_mo |
|
Thanks for doing the work @m-aciek! I should have time tomorrow for a review :) |
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5
tomasr8
left a comment
There was a problem hiding this comment.
Looks good, but I'll let Hugo have another look :)
| ) | ||
| jsfile.write_text( | ||
| f"// {DOMAIN} translations for {pofile.parents[1].name}\n" | ||
| f"Documentation.addTranslations({serialized});\n", |
There was a problem hiding this comment.
🤖 says this, does it matter here?
Documentation.addTranslations also replaces the global PLURAL_EXPR, and our file loads after Sphinx's translations.js, so our plural rule overrides Sphinx's. They don't always match: for German we emit a three-form rule but Sphinx's German catalog has two forms, so ngettext in searchtools.js would return undefined for most counts.
None of our three JS strings are plural, so let's merge into TRANSLATIONS and leave the plural rule to Sphinx:
# The plural rule is global and set by Sphinx's own catalog
if message.pluralizable:
continue
if message.fuzzy or not message.string:
continue
messages[message.id] = message.string
serialized = json.dumps(messages, ensure_ascii=True, sort_keys=True)
jsfile.write_text(
f"// {DOMAIN} translations for {pofile.parents[1].name}\n"
f"Object.assign(Documentation.TRANSLATIONS, {serialized});\n",
encoding="utf-8",
)
Alternative to #337.
Add and mount missing JS translations catalog. Extraction was/is working correctly.