alphabetic order on localization files #1187

Open
opened 2026-05-27 07:39:24 +00:00 by c24danli · 1 comment
Collaborator

alphabetic order on localization files this involves both the English and Swedish json files

alphabetic order on localization files this involves both the English and Swedish json files
Collaborator

Cant upload py files but the following will change the order of one script based on a sorted one:

import json

english_file = "en.json"
swedish_file = "sv.json"
output_file = "merged_sv.json"

with open(english_file, "r", encoding="utf-8") as f:
    english = json.load(f)

with open(swedish_file, "r", encoding="utf-8") as f:
    swedish = json.load(f)

def replace_values(template, translations):
    
    if isinstance(template, dict):
        return {
            key: replace_values(template[key], translations[key])
            for key in template
        }

    elif isinstance(template, list):
        return [
            replace_values(t, s)
            for t, s in zip(template, translations)
        ]

    else:
        return translations

result = replace_values(english, swedish)

with open(output_file, "w", encoding="utf-8") as f:
    json.dump(result, f, ensure_ascii=False, indent=2)

print(f"Done")
Cant upload py files but the following will change the order of one script based on a sorted one: ``` import json english_file = "en.json" swedish_file = "sv.json" output_file = "merged_sv.json" with open(english_file, "r", encoding="utf-8") as f: english = json.load(f) with open(swedish_file, "r", encoding="utf-8") as f: swedish = json.load(f) def replace_values(template, translations): if isinstance(template, dict): return { key: replace_values(template[key], translations[key]) for key in template } elif isinstance(template, list): return [ replace_values(t, s) for t, s in zip(template, translations) ] else: return translations result = replace_values(english, swedish) with open(output_file, "w", encoding="utf-8") as f: json.dump(result, f, ensure_ascii=False, indent=2) print(f"Done") ```
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#1187
No description provided.