- Replace 5 hardcoded text strings with LUS_LOC() calls: * ResolutionEditor.cpp: 'Click to resolve' -> BUTTON_CLICK_TO_RESOLVE * ResolutionEditor.cpp: ' ' (space) -> TEXT_SPACE * SohMenuNetwork.cpp: ':' (colon) -> TEXT_COLON (2 instances) * UIWidgets.cpp: '+' (plus) -> TEXT_PLUS - Add new translation keys to both en_US.json and es_ES.json: * BUTTON_CLICK_TO_RESOLVE: 'Click to resolve' / 'Haz clic para resolver' * TEXT_SPACE: ' ' / ' ' * TEXT_COLON: ':' / ':' * TEXT_PLUS: '+' / '+' - All hardcoded UI text now uses localization system - Compilation successful with only minor format warnings This completes the immediate task of eliminating hardcoded text strings.
110 lines
3.9 KiB
Python
110 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
import re
|
|
import json
|
|
from pathlib import Path
|
|
from collections import defaultdict
|
|
|
|
PROJECT_ROOT = Path(__file__).parent.parent
|
|
LANGUAGES_DIR = PROJECT_ROOT / "languages"
|
|
SOH_DIR = PROJECT_ROOT / "soh" / "soh"
|
|
|
|
PATTERNS = [
|
|
(r'(\.Tooltip\s*\(\s*")([^"]+)(")', 'TOOLTIP'),
|
|
(r'(Tooltip\s*\(\s*")([^"]+)(")', 'TOOLTIP'),
|
|
(r'(ImGui::Text\s*\(\s*")([^"]+)(")', 'TEXT'),
|
|
(r'(ImGui::Button\s*\(\s*")([^"]+)(")', 'BUTTON'),
|
|
(r'(ImGui::SeparatorText\s*\(\s*")([^"]+)(")', 'SEPARATOR'),
|
|
(r'(ImGui::CollapsingHeader\s*\(\s*")([^"]+)(")', 'COLLAPSING'),
|
|
]
|
|
|
|
def load_json_keys():
|
|
with open(LANGUAGES_DIR / "en_US.json", 'r') as f:
|
|
return set(json.load(f).keys())
|
|
|
|
def generate_key(text, context=''):
|
|
text_clean = re.sub(r'[^a-zA-Z0-9\s]', '', text)
|
|
words = text_clean.upper().split()[:4]
|
|
key = '_'.join(words) if words else 'UNKNOWN'
|
|
if context:
|
|
key = f"{context}_{key}"
|
|
return key
|
|
|
|
def analyze_file(filepath, available_keys):
|
|
changes_needed = []
|
|
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
|
lines = f.readlines()
|
|
|
|
for line_num, line in enumerate(lines, 1):
|
|
for pattern, context in PATTERNS:
|
|
match = re.search(pattern, line)
|
|
if match:
|
|
text = match.group(2)
|
|
if len(text) > 2 and '%' not in text and '##' not in text:
|
|
key = generate_key(text, context)
|
|
if key not in available_keys:
|
|
alt_key = f"TOOLTIP_{key.split('_', 1)[-1]}" if key.split('_')[0] in ['TEXT', 'BUTTON', 'SEPARATOR', 'COLLAPSING'] else key
|
|
if alt_key not in available_keys:
|
|
changes_needed.append({
|
|
'line': line_num,
|
|
'text': text,
|
|
'suggested_key': key,
|
|
'line_content': line.strip()[:120]
|
|
})
|
|
return changes_needed
|
|
|
|
def main():
|
|
available_keys = load_json_keys()
|
|
print(f"Claves disponibles en JSONs: {len(available_keys)}")
|
|
|
|
all_changes = []
|
|
cpp_dirs = [SOH_DIR, PROJECT_ROOT / "libultraship" / "src"]
|
|
|
|
for cpp_dir in cpp_dirs:
|
|
if not cpp_dir.exists():
|
|
continue
|
|
for cpp_file in cpp_dir.rglob("*.cpp"):
|
|
changes = analyze_file(cpp_file, available_keys)
|
|
if changes:
|
|
all_changes.append({
|
|
'file': str(cpp_file.relative_to(PROJECT_ROOT)),
|
|
'file_name': cpp_file.name,
|
|
'changes': changes
|
|
})
|
|
|
|
grouped = defaultdict(list)
|
|
for fc in all_changes:
|
|
for change in fc['changes']:
|
|
grouped[fc['file']].append(change)
|
|
|
|
output = {
|
|
'summary': {
|
|
'total_files_need_changes': len(all_changes),
|
|
'total_lines_need_changes': sum(len(fc['changes']) for fc in all_changes)
|
|
},
|
|
'files': []
|
|
}
|
|
|
|
for fc in sorted(all_changes, key=lambda x: x['file']):
|
|
output['files'].append({
|
|
'file': fc['file'],
|
|
'changes_needed': len(fc['changes']),
|
|
'details': fc['changes'][:20]
|
|
})
|
|
|
|
output_file = PROJECT_ROOT / "translations_pending.json"
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(output, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"\nArchivos que necesitan cambios: {len(all_changes)}")
|
|
print(f"Líneas que necesitan cambios: {sum(len(fc['changes']) for fc in all_changes)}")
|
|
print(f"\nOutput guardado en: {output_file}")
|
|
|
|
print("\n=== Primeros 10 archivos ===")
|
|
for fc in all_changes[:10]:
|
|
print(f"\n{fc['file']} ({len(fc['changes'])} cambios)")
|
|
for c in fc['changes'][:3]:
|
|
print(f" Línea {c['line']}: {c['text'][:50]}...")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|