25 lines
770 B
Python
25 lines
770 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Compile .po files to .mo files for Flask-Babel
|
||
|
|
"""
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
def compile_translations():
|
||
|
|
translations_dir = Path('translations')
|
||
|
|
|
||
|
|
for lang_dir in translations_dir.iterdir():
|
||
|
|
if lang_dir.is_dir():
|
||
|
|
lc_messages_dir = lang_dir / 'LC_MESSAGES'
|
||
|
|
if lc_messages_dir.exists():
|
||
|
|
for po_file in lc_messages_dir.glob('*.po'):
|
||
|
|
mo_file = lc_messages_dir / f"{po_file.stem}.mo"
|
||
|
|
print(f"Compiling {po_file} -> {mo_file}")
|
||
|
|
# Use msgfmt to compile
|
||
|
|
os.system(f"msgfmt -o {mo_file} {po_file}")
|
||
|
|
|
||
|
|
print("✅ All translations compiled!")
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
compile_translations()
|