Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
527 changes: 507 additions & 20 deletions repentogon/ImGuiFeatures/Localization/de.inl

Large diffs are not rendered by default.

163 changes: 29 additions & 134 deletions repentogon/ImGuiFeatures/Localization/en_us.inl

Large diffs are not rendered by default.

168 changes: 36 additions & 132 deletions repentogon/ImGuiFeatures/Localization/es.inl

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions repentogon/ImGuiFeatures/Localization/fr.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
#ifndef V
#define V(TYPE, VAR, VALUE)
#endif

/*
* note: Remove items inside "en_us.inl" may cause compile error, and you
* need also remove all of them in other language files.
*/
5 changes: 5 additions & 0 deletions repentogon/ImGuiFeatures/Localization/jp.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
#ifndef V
#define V(TYPE, VAR, VALUE)
#endif

/*
* note: Remove items inside "en_us.inl" may cause compile error, and you
* need also remove all of them in other language files.
*/
5 changes: 5 additions & 0 deletions repentogon/ImGuiFeatures/Localization/ru.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
#ifndef V
#define V(TYPE, VAR, VALUE)
#endif

/*
* note: Remove items inside "en_us.inl" may cause compile error, and you
* need also remove all of them in other language files.
*/
158 changes: 30 additions & 128 deletions repentogon/ImGuiFeatures/Localization/zh_cn.inl

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions tools/localizationToINL.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Converts JSON localization files to .INL files for use in the project.

import json
import os
import re
from glob import glob
SCRIPT_PATH = os.path.realpath(__file__)
SOURCE_DIRECTORY = os.path.dirname(os.path.dirname(SCRIPT_PATH))
LOCALIZATION_DIRECTORY = SOURCE_DIRECTORY +"/repentogon/ImGuiFeatures/Localization"

def json_to_inl(json_file, inl_file):
with open(json_file, encoding="utf-8") as f:
data = json.load(f)

lines = []
lines.append("/* This is saved as UTF-8 with BOM(code page 65001) */")
lines.append("#ifndef I")
lines.append("#define I(ITEM, TRANSLATE)")
lines.append("#endif\n")
lines.append("#ifndef V")
lines.append("#define V(TYPE, VAR, VALUE)")
lines.append("#endif\n")
lines.append("/*")
lines.append(" * note: Remove items inside \"en_us.inl\" may cause compile error, and you")
lines.append(" * need also remove all of them in other language files.")
lines.append(" */\n")

for category, items in data.items():
lines.append(f"// =========== {category} ===========")
for key, value in items.items():
# Move icon definition outside of the string definition if it exists
value = value.replace("\"", "\\\"")
value = value.replace("\n", "\\\n")
if "ICON_" in value:
icon_match = re.search(r'(ICON_[A-Z0-9_]+)', value)
if icon_match:
icon = icon_match.group(1)
value = value.replace(icon, "")
lines.append(f'I({key}, {icon} u8"{value}")')
else:
lines.append(f'I({key}, u8"{value}")')
# Handle cases without icon
else:
lines.append(f'I({key}, u8"{value}")')
lines.append("") # Blank line after each category

with open(inl_file, "w", encoding="utf-8-sig") as f:
f.write("\n".join(lines))
print(f"'{inl_file}' created.")

if __name__ == "__main__":
json_files = glob(os.path.join(LOCALIZATION_DIRECTORY, "*.json"))
for json_file in json_files:
inl_file = os.path.splitext(json_file)[0] + ".inl"
json_to_inl(json_file, inl_file)
54 changes: 54 additions & 0 deletions tools/localizationToJSON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Converts .INL localization files to .JSON files for use in external translation tools
import re
import json
import os
from glob import glob

SCRIPT_PATH = os.path.realpath(__file__)
SOURCE_DIRECTORY = os.path.dirname(os.path.dirname(SCRIPT_PATH))
LOCALIZATION_DIRECTORY = SOURCE_DIRECTORY +"/repentogon/ImGuiFeatures/Localization"

def parse_file(filename):
data = {}
current_category = None

with open(filename, encoding="utf-8") as f:
for line in f:
line = line.strip()
# Unterkategorie erkennen
cat_match = re.match(r"//\s*=*\s*(.+)", line)
if cat_match:
current_category = cat_match.group(1).replace("=","").strip()
if current_category not in data:
data[current_category] = {}
continue

# I() Funktion erkennen
i_match_withIcon = re.match(r'I\(\s*(.+?)\s*,\s(ICON_.*)*(?:u8)*["\'](.+?)["\']\s*\)', line)
i_match_noIcon = re.match(r'I\(\s*(.+?)\s*,[\s(u8)]*["\'](.+?)["\']\s*\)', line)
if current_category:
# Handle cases where icon is not present
if i_match_noIcon:
key, value = i_match_noIcon.groups()
translatedWord = re.sub(r'\"\s{2,}u8\"', '', value) # remove concatenation from string
data[current_category][key] = translatedWord.strip()
elif i_match_withIcon:
key, icon, value = i_match_withIcon.groups()
icon = icon.replace(" u8","").strip()
value = icon + value
translatedWord = re.sub(r'\"\s{2,}u8\"', '', value) # remove concatenation from string
data[current_category][key] = translatedWord.strip()

# Remove empty categories
data = {k: v for k, v in data.items() if v}
return data

if __name__ == "__main__":
inl_files = glob(os.path.join(LOCALIZATION_DIRECTORY, "*.inl"))

for inl_file in inl_files:
result = parse_file(inl_file)
output_file = os.path.splitext(inl_file)[0] + ".json"
with open(output_file, "w", encoding="utf-8") as f:
json.dump(result, f, ensure_ascii=False, indent=2)
print(f"'{output_file}' created.")
Loading