mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 06:25:37 -05:00
i18n: Add japanese + i18n service
This commit is contained in:
@@ -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": ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user