Repository navigation
Replies: 2 comments 1 reply
|
You can calculate it by iterating over the from babel.messages.pofile import read_po
with open("messages.po", "rb") as f:
catalog = read_po(f)
messages = [message for message in catalog if message.id != ""]
def is_complete(message):
if message.fuzzy:
return False
if message.pluralizable:
forms = message.string
return len(forms) == catalog.num_plurals and all(forms)
return bool(message.string)
translated = sum(is_complete(message) for message in messages)
print(f"{translated}/{len(messages)} translated")
if messages:
print(f"{100 * translated / len(messages):.1f}%")The empty This measures coverage of the active entries in that PO file; it doesn't validate the translations or check for messages missing from an outdated catalog. Merge against the current POT first if you want project-wide coverage. I checked the example with Babel 2.18.0, including fuzzy, untranslated, plural, obsolete, and empty-catalog cases. References: PO file loading, Catalog and Message API. |
|
Why not using PoFile.percent_translated() ?
|
Uh oh!
There was an error while loading. Please reload this page.
I was looking in to 'Catalogs' class but couldn't find the right method or attribute.
Can I calculate how complete a translation is when loading a specific po file?
All reactions