mirror of
https://codeberg.org/readeck/readeck.git
synced 2025-12-22 13:17:10 +00:00
Fixed messages python scripts
- Changed separator for language code parsing - Only check non fuzzy strings
This commit is contained in:
@@ -15,7 +15,7 @@ from argparse import ArgumentParser
|
||||
from operator import itemgetter
|
||||
from pathlib import Path
|
||||
|
||||
from babel.messages.catalog import Catalog
|
||||
from babel.messages.catalog import Catalog, Locale
|
||||
from babel.messages.extract import extract_from_file
|
||||
from babel.messages.pofile import read_po, write_po
|
||||
|
||||
@@ -130,14 +130,15 @@ def update(_):
|
||||
|
||||
dirs = [x for x in translations.iterdir() if x.is_dir()]
|
||||
for p in dirs:
|
||||
locale = Locale.parse(p.name, sep="-")
|
||||
po_file = p / "messages.po"
|
||||
if po_file.exists():
|
||||
with po_file.open("rb") as fp:
|
||||
catalog = read_po(fp, locale=p.name, domain=po_file.name)
|
||||
catalog = read_po(fp, locale=locale, domain=po_file.name)
|
||||
else:
|
||||
catalog = Catalog(
|
||||
**CATALOG_OPTIONS,
|
||||
locale=p.name,
|
||||
locale=locale,
|
||||
domain=po_file.name,
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import sys
|
||||
from argparse import ArgumentParser
|
||||
from pathlib import Path
|
||||
|
||||
from babel.messages.catalog import Catalog
|
||||
from babel.messages.catalog import Catalog, Locale
|
||||
from babel.messages.extract import extract_from_file
|
||||
from babel.messages.mofile import write_mo
|
||||
from babel.messages.pofile import read_po, write_po
|
||||
@@ -350,14 +350,15 @@ def update(_):
|
||||
|
||||
dirs = [x for x in translations.iterdir() if x.is_dir()]
|
||||
for p in sorted(dirs):
|
||||
locale = Locale.parse(p.name, sep="-")
|
||||
po_file = p / "messages.po"
|
||||
if po_file.exists():
|
||||
with po_file.open("rb") as fp:
|
||||
catalog = read_po(fp, locale=p.name, domain=po_file.name)
|
||||
catalog = read_po(fp, locale=locale, domain=po_file.name)
|
||||
else:
|
||||
catalog = Catalog(
|
||||
**CATALOG_OPTIONS,
|
||||
locale=p.name,
|
||||
locale=locale,
|
||||
domain=po_file.name,
|
||||
)
|
||||
|
||||
@@ -436,6 +437,14 @@ def check(_):
|
||||
translations = HERE / "translations"
|
||||
po_files = translations.glob("*/messages.po")
|
||||
|
||||
def check(catalog: Catalog):
|
||||
for message in catalog._messages.values():
|
||||
if message.fuzzy:
|
||||
continue
|
||||
errors = message.check(catalog=catalog)
|
||||
if errors:
|
||||
yield message, errors
|
||||
|
||||
has_errors = False
|
||||
for filename in po_files:
|
||||
code = filename.parent.name
|
||||
@@ -445,7 +454,7 @@ def check(_):
|
||||
with filename.open("rb") as fp:
|
||||
catalog = read_po(fp)
|
||||
|
||||
errors = list(catalog.check())
|
||||
errors = list(check(catalog))
|
||||
if len(errors) == 0:
|
||||
print(f"[OK] {code}")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user