#!/usr/bin/env python # -*- coding: utf-8 -*- # # .poファイルを.moファイルにコンパイルする # Compile .po files to .mo files import os import subprocess from pathlib import Path import logging from .i18n_utils import setup_i18n # Initialize translation _ = setup_i18n('compile_translations') # Set up logging logging.basicConfig( level=logging.INFO, format='%(levelname)s: %(message)s' ) def compile_po_files(start_dir='.'): """ Find and compile all .po files in subdirectories to .mo files """ success_count = 0 error_count = 0 # Convert to Path object start_path = Path(start_dir) # Find all .po files po_files = list(start_path.rglob('*.po')) if not po_files: logging.warning(_("No .po files found")) return logging.info(_("Found {} .po files").format(len(po_files))) for po_file in po_files: mo_file = po_file.with_suffix('.mo') try: # Run msgfmt subprocess.run(['msgfmt', str(po_file), '-o', str(mo_file)], check=True, capture_output=True, text=True) logging.info(_("✓ Compiled {}").format(po_file)) success_count += 1 except subprocess.CalledProcessError as e: logging.error(_("✗ Failed to compile {}").format(po_file)) logging.error(_("Error: {}").format(e.stderr)) error_count += 1 except FileNotFoundError: logging.error(_("msgfmt command not found. Please install gettext.")) return # Print summary logging.info(_("\nSummary:")) logging.info(_("Total files processed: {}").format(len(po_files))) logging.info(_("Successfully compiled: {}").format(success_count)) if error_count > 0: logging.error(_("Failed compilations: {}").format(error_count)) if __name__ == '__main__': compile_po_files()