- translations_body.py: 26 languages × 74 keys (1,924 strings) - inject_translations.py: Script to merge body translations into i18n.py - Languages: en, es, fr, de, ja, pt, ru, ko, it, ar, hi, nl, pl, tr, vi, th, id, uk, sv, zh, zh-tw, bn, ur, sw, mr, te, ka
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Inject body translations into i18n.py"""
|
|
import re
|
|
from translations_body import BODY
|
|
|
|
def main():
|
|
with open('i18n.py', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
for lang, translations in BODY.items():
|
|
print(f"Processing {lang}...")
|
|
|
|
# Build the replacement text
|
|
lines = [' # About page body translations']
|
|
for key, value in translations.items():
|
|
escaped = value.replace('\\', '\\\\').replace('"', '\\"')
|
|
lines.append(f' "{key}": "{escaped}",')
|
|
new_block = '\n'.join(lines)
|
|
|
|
# Find the existing body translations for this language
|
|
# Pattern: from "# About page body translations" to "about_footer_remember": "...",
|
|
pattern = rf'( "{lang}": \{{[^}}]+?"about_footer_p5": "[^"]*",)\n # About page body translations\n.*?"about_footer_remember": "[^"]*",'
|
|
|
|
match = re.search(pattern, content, re.DOTALL)
|
|
if match:
|
|
old_block = match.group(0)
|
|
new_full = match.group(1) + '\n' + new_block
|
|
content = content.replace(old_block, new_full)
|
|
print(f" Updated {lang} with {len(translations)} translations")
|
|
else:
|
|
print(f" Could not find pattern for {lang}")
|
|
|
|
with open('i18n.py', 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
|
|
print("Done!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|