mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-03 20:32:07 -04:00
i18n: Add japanese + i18n service
This commit is contained in:
1372
translations/en.json
1372
translations/en.json
File diff suppressed because it is too large
Load Diff
@@ -8,19 +8,28 @@ from collections import defaultdict
|
||||
def extract_qstr_strings(root_dir):
|
||||
translations = defaultdict(list)
|
||||
qstr_pattern = re.compile(r'qsTr\(["\']([^"\']+)["\']\)')
|
||||
i18n_pattern = re.compile(r'I18n\.tr\(["\']([^"\']+)["\'],\s*["\']([^"\']+)["\']\)')
|
||||
|
||||
for qml_file in Path(root_dir).rglob('*.qml'):
|
||||
relative_path = qml_file.relative_to(root_dir)
|
||||
|
||||
with open(qml_file, 'r', encoding='utf-8') as f:
|
||||
for line_num, line in enumerate(f, 1):
|
||||
matches = qstr_pattern.findall(line)
|
||||
for match in matches:
|
||||
qstr_matches = qstr_pattern.findall(line)
|
||||
for match in qstr_matches:
|
||||
translations[match].append({
|
||||
'file': str(relative_path),
|
||||
'line': line_num
|
||||
})
|
||||
|
||||
i18n_matches = i18n_pattern.findall(line)
|
||||
for match in i18n_matches:
|
||||
term = match[0]
|
||||
translations[term].append({
|
||||
'file': str(relative_path),
|
||||
'line': line_num
|
||||
})
|
||||
|
||||
return translations
|
||||
|
||||
def create_poeditor_json(translations):
|
||||
@@ -28,16 +37,14 @@ def create_poeditor_json(translations):
|
||||
|
||||
for term, occurrences in sorted(translations.items()):
|
||||
references = []
|
||||
contexts = []
|
||||
|
||||
for occ in occurrences:
|
||||
ref = f"{occ['file']}:{occ['line']}"
|
||||
references.append(ref)
|
||||
contexts.append(f"{occ['file']}:{occ['line']}")
|
||||
|
||||
entry = {
|
||||
"term": term,
|
||||
"context": contexts[0] if contexts else "",
|
||||
"context": term,
|
||||
"reference": ", ".join(references),
|
||||
"comment": ""
|
||||
}
|
||||
|
||||
1391
translations/ja.json
Normal file
1391
translations/ja.json
Normal file
File diff suppressed because it is too large
Load Diff
48
translations/replace_qstr.py
Executable file
48
translations/replace_qstr.py
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
def replace_qstr_in_file(file_path, root_dir):
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
original_content = content
|
||||
relative_path = file_path.relative_to(root_dir)
|
||||
|
||||
qstr_pattern = re.compile(r'qsTr\("([^"]+)"\)')
|
||||
|
||||
def replacement(match):
|
||||
term = match.group(1)
|
||||
context = term
|
||||
return f'I18n.tr("{term}", "{context}")'
|
||||
|
||||
content = qstr_pattern.sub(replacement, content)
|
||||
|
||||
if content != original_content:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
return True
|
||||
return False
|
||||
|
||||
def main():
|
||||
script_dir = Path(__file__).parent
|
||||
root_dir = script_dir.parent
|
||||
|
||||
modified_count = 0
|
||||
|
||||
for qml_file in root_dir.rglob('*.qml'):
|
||||
if 'translations' in str(qml_file):
|
||||
continue
|
||||
|
||||
try:
|
||||
if replace_qstr_in_file(qml_file, root_dir):
|
||||
modified_count += 1
|
||||
print(f"Modified: {qml_file.relative_to(root_dir)}")
|
||||
except Exception as e:
|
||||
print(f"Error processing {qml_file}: {e}")
|
||||
|
||||
print(f"\nTotal files modified: {modified_count}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user