36 lines
969 B
Python
Executable File
36 lines
969 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Validate every Gettext catalog changed or maintained in this repository."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import polib
|
|
|
|
|
|
def main() -> int:
|
|
failures: list[str] = []
|
|
catalogs = sorted(Path('.').glob('**/*.po'))
|
|
if not catalogs:
|
|
failures.append('no PO catalogs were found')
|
|
|
|
for path in catalogs:
|
|
try:
|
|
catalog = polib.pofile(path, check_for_duplicates=True)
|
|
except (OSError, UnicodeError, ValueError) as exc:
|
|
failures.append(f'{path}: {exc}')
|
|
continue
|
|
if not catalog.metadata.get('Content-Type', '').startswith('text/plain'):
|
|
failures.append(f'{path}: missing or invalid Content-Type metadata')
|
|
|
|
if failures:
|
|
print('\n'.join(failures), file=sys.stderr)
|
|
return 1
|
|
print(f'Validated {len(catalogs)} PO catalogs')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|