aboutsummaryrefslogtreecommitdiffstats
path: root/manage_translations.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-03-22 14:17:23 -0500
committerAstounds <kirito@disroot.org>2026-03-22 14:17:23 -0500
commit84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759 (patch)
treea4021823e3e29d1efb57271dda5024825983bacf /manage_translations.py
parented4b05d9b616c688afc6ef03dc404009c4abfc0f (diff)
downloadyt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.lz
yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.xz
yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.zip
yt-dlp
Diffstat (limited to 'manage_translations.py')
-rw-r--r--manage_translations.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/manage_translations.py b/manage_translations.py
new file mode 100644
index 0000000..ce1e160
--- /dev/null
+++ b/manage_translations.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+"""
+Translation management script for yt-local
+
+Usage:
+ python manage_translations.py extract # Extract strings to messages.pot
+ python manage_translations.py init es # Initialize Spanish translation
+ python manage_translations.py update # Update all translations
+ python manage_translations.py compile # Compile translations to .mo files
+"""
+import sys
+import os
+import subprocess
+
+
+def run_command(cmd):
+ """Run a shell command and print output"""
+ print(f"Running: {' '.join(cmd)}")
+ result = subprocess.run(cmd, capture_output=True, text=True)
+ if result.stdout:
+ print(result.stdout)
+ if result.stderr:
+ print(result.stderr, file=sys.stderr)
+ return result.returncode
+
+
+def extract():
+ """Extract translatable strings from source code"""
+ print("Extracting translatable strings...")
+ return run_command([
+ 'pybabel', 'extract',
+ '-F', 'babel.cfg',
+ '-k', 'lazy_gettext',
+ '-k', '_l',
+ '-o', 'translations/messages.pot',
+ '.'
+ ])
+
+
+def init(language):
+ """Initialize a new language translation"""
+ print(f"Initializing {language} translation...")
+ return run_command([
+ 'pybabel', 'init',
+ '-i', 'translations/messages.pot',
+ '-d', 'translations',
+ '-l', language
+ ])
+
+
+def update():
+ """Update existing translations with new strings"""
+ print("Updating translations...")
+ return run_command([
+ 'pybabel', 'update',
+ '-i', 'translations/messages.pot',
+ '-d', 'translations'
+ ])
+
+
+def compile_translations():
+ """Compile .po files to .mo files"""
+ print("Compiling translations...")
+ return run_command([
+ 'pybabel', 'compile',
+ '-d', 'translations'
+ ])
+
+
+def main():
+ if len(sys.argv) < 2:
+ print(__doc__)
+ sys.exit(1)
+
+ command = sys.argv[1]
+
+ if command == 'extract':
+ sys.exit(extract())
+ elif command == 'init':
+ if len(sys.argv) < 3:
+ print("Error: Please specify a language code (e.g., es, fr, de)")
+ sys.exit(1)
+ sys.exit(init(sys.argv[2]))
+ elif command == 'update':
+ sys.exit(update())
+ elif command == 'compile':
+ sys.exit(compile_translations())
+ else:
+ print(f"Unknown command: {command}")
+ print(__doc__)
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()