forked from Shinonome/dots-hyprland
i18n: Fix translatable string extraction tool bug.
This commit is contained in:
@@ -154,10 +154,9 @@ def sync_translations(translations_dir: str, source_lang: str = "en_US", target_
|
||||
del target_translations[key]
|
||||
print(f" Deleted {len(extra_keys)} extra keys")
|
||||
|
||||
# Save file
|
||||
with open(target_file, 'w', encoding='utf-8') as f:
|
||||
# Save file (ensure UTF-8, fix for special chars)
|
||||
with open(target_file, 'w', encoding='utf-8', newline='') as f:
|
||||
json.dump(target_translations, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f" Saved: {target_file}")
|
||||
|
||||
def main():
|
||||
|
||||
@@ -56,11 +56,22 @@ class TranslationManager:
|
||||
text = match[0] if match else ""
|
||||
else:
|
||||
text = match
|
||||
|
||||
# Decode escape characters
|
||||
|
||||
try:
|
||||
clean_text = text.encode().decode('unicode_escape')
|
||||
except:
|
||||
if '\\u' in text or '\\x' in text:
|
||||
clean_text = bytes(text, "utf-8").decode("unicode_escape")
|
||||
else:
|
||||
clean_text = (
|
||||
text.replace('\\n', '\n')
|
||||
.replace('\\t', '\t')
|
||||
.replace('\\r', '\r')
|
||||
.replace('\\"', '"')
|
||||
.replace('\\\'', "'")
|
||||
.replace('\\f', '\f')
|
||||
.replace('\\b', '\b')
|
||||
.replace('\\\\', '\\')
|
||||
)
|
||||
except Exception:
|
||||
clean_text = text
|
||||
|
||||
# Clean text (remove extra whitespace)
|
||||
|
||||
Reference in New Issue
Block a user