mirror of
https://github.com/imputnet/helium.git
synced 2026-08-20 00:57:32 +02:00
b0395c7ecd
rough sketch of the pipeline:
- generic + platform patches -> `devutils/i18n generate` ->
`i18n/source.gen.json` ("source of truth" for translations)
- `i18n/source.gen.json` -> `devutils/i18n translate` -> machine
translations generated into `i18n/translations/{lang}.json`
- those should be reviewed and fixed up by representative community
members that actually speak the corresponding language
- `i18n/source.gen.json` + `i18n/translations/*` -> `utils/i18n_apply`
-> fingerprints source strings and applies translations into XTB files
fixes #1109
71 lines
2.4 KiB
Python
Executable File
71 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright 2026 The Helium Authors
|
|
# You can use, redistribute, and/or modify this source code under
|
|
# the terms of the GPL-3.0 license that can be found in the LICENSE file.
|
|
"""
|
|
Utility file for generating files for translation and
|
|
importing them into the codebase.
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(REPO_ROOT))
|
|
|
|
PLATFORMS_DIR = Path(__file__).resolve().parent / "i18n-data"
|
|
OUT_PATH = REPO_ROOT / 'i18n' / 'source.gen.json'
|
|
|
|
|
|
def parse_args():
|
|
"""CLI arg parsing"""
|
|
parser = argparse.ArgumentParser(description='i18n tooling for Helium')
|
|
subparsers = parser.add_subparsers(dest='command', required=True)
|
|
base = subparsers.add_parser('generate', help='Extract translatable strings from patches')
|
|
base.add_argument('-p',
|
|
'--platforms-dir',
|
|
type=Path,
|
|
default=PLATFORMS_DIR,
|
|
help='Path where platform repos will be cloned')
|
|
base.add_argument('-o',
|
|
'--output',
|
|
type=Path,
|
|
default=OUT_PATH,
|
|
help='Output path where base JSON file will be saved')
|
|
|
|
translate = subparsers.add_parser('translate',
|
|
help='Translate source strings into target languages')
|
|
translate.add_argument('-l',
|
|
'--language',
|
|
type=str,
|
|
nargs='+',
|
|
help='Target language code(s) (e.g. "fr" "de"). '
|
|
'If omitted, translates all languages.')
|
|
translate.add_argument('-f',
|
|
'--from-file',
|
|
type=Path,
|
|
help='Import translations from a JSON file '
|
|
'instead of calling the LLM.')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
"""CLI entrypoint"""
|
|
args = parse_args()
|
|
|
|
if args.command == 'generate':
|
|
import i18n_generate # pylint: disable=import-outside-toplevel
|
|
return i18n_generate.run(args, REPO_ROOT)
|
|
|
|
if args.command == 'translate':
|
|
import i18n_translate # pylint: disable=import-outside-toplevel
|
|
return i18n_translate.run(args)
|
|
|
|
raise ValueError(f'unknown command: {args.command}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|