Some comments
This commit is contained in:
+33
-30
@@ -289,7 +289,7 @@ def find_used_string_keys(
|
||||
escaped = False
|
||||
continue
|
||||
if quote_char is None:
|
||||
if ch == '"' or ch == "'":
|
||||
if ch in ['"', "'"]:
|
||||
quote_char = ch
|
||||
continue
|
||||
if ch == "/" and idx + 1 < len(line) and line[idx + 1] == "/":
|
||||
@@ -413,11 +413,7 @@ def format_cpp_string_literal(segments: List[str], indent: str = " ") -> List
|
||||
last_space = idx
|
||||
|
||||
# Handle escapes to step correctly
|
||||
if current[idx] == "\\":
|
||||
idx += 2
|
||||
else:
|
||||
idx += 1
|
||||
|
||||
idx += 2 if current[idx] == "\\" else 1
|
||||
# If we found a space, split after it
|
||||
if last_space != -1:
|
||||
# Include the space in the first line
|
||||
@@ -479,17 +475,19 @@ def generate_keys_header(
|
||||
]
|
||||
|
||||
for code in languages:
|
||||
lines.append(f"extern const char STRINGS_{code}_DATA[];")
|
||||
lines.append(f"extern const uint16_t OFFSETS_{code}[];")
|
||||
|
||||
lines.extend(
|
||||
(
|
||||
f"extern const char STRINGS_{code}_DATA[];",
|
||||
f"extern const uint16_t OFFSETS_{code}[];",
|
||||
)
|
||||
)
|
||||
lines.append("} // namespace i18n_strings")
|
||||
lines.append("")
|
||||
|
||||
# Language enum
|
||||
lines.append("// Language enum")
|
||||
lines.append("enum class Language : uint8_t {")
|
||||
for i, lang in enumerate(languages):
|
||||
lines.append(f" {lang} = {i},")
|
||||
lines.extend(f" {lang} = {i}," for i, lang in enumerate(languages))
|
||||
lines.append(" _COUNT")
|
||||
lines.append("};")
|
||||
lines.append("")
|
||||
@@ -529,9 +527,11 @@ def generate_keys_header(
|
||||
lines.append("inline LangStrings getLanguageStrings(Language lang) {")
|
||||
lines.append(" switch (lang) {")
|
||||
for code in languages:
|
||||
lines.append(f" case Language::{code}:")
|
||||
lines.append(
|
||||
f" return {{i18n_strings::STRINGS_{code}_DATA, i18n_strings::OFFSETS_{code}}};"
|
||||
lines.extend(
|
||||
(
|
||||
f" case Language::{code}:",
|
||||
f" return {{i18n_strings::STRINGS_{code}_DATA, i18n_strings::OFFSETS_{code}}};",
|
||||
)
|
||||
)
|
||||
first_code = languages[0]
|
||||
lines.append(" default:")
|
||||
@@ -559,8 +559,10 @@ def generate_keys_header(
|
||||
)
|
||||
sorted_indices = [english_idx] + rest
|
||||
lines.append("// Sorted language indices by code (auto-generated by gen_i18n.py)")
|
||||
for rank, idx in enumerate(sorted_indices):
|
||||
lines.append(f"// {rank:>2}: {languages[idx]:<4} {language_names[idx]}")
|
||||
lines.extend(
|
||||
f"// {rank:>2}: {languages[idx]:<4} {language_names[idx]}"
|
||||
for rank, idx in enumerate(sorted_indices)
|
||||
)
|
||||
lines.append(
|
||||
"constexpr uint8_t SORTED_LANGUAGE_INDICES[] = {"
|
||||
f"{', '.join(str(i) for i in sorted_indices)}"
|
||||
@@ -594,11 +596,13 @@ def generate_strings_header(
|
||||
]
|
||||
|
||||
for code in languages:
|
||||
lines.append(f"extern const char STRINGS_{code}_DATA[];")
|
||||
lines.append(f"extern const uint16_t OFFSETS_{code}[];")
|
||||
|
||||
lines.append("")
|
||||
lines.append("} // namespace i18n_strings")
|
||||
lines.extend(
|
||||
(
|
||||
f"extern const char STRINGS_{code}_DATA[];",
|
||||
f"extern const uint16_t OFFSETS_{code}[];",
|
||||
)
|
||||
)
|
||||
lines.extend(("", "} // namespace i18n_strings"))
|
||||
_write_file(output_path, lines, verbose)
|
||||
|
||||
|
||||
@@ -618,11 +622,10 @@ def generate_strings_cpp(
|
||||
"",
|
||||
"#include <cstddef>",
|
||||
"",
|
||||
"// Language codes",
|
||||
"const char* const LANGUAGE_CODES[] = {",
|
||||
]
|
||||
|
||||
# LANGUAGE_NAMES array
|
||||
lines.append("// Language codes")
|
||||
lines.append("const char* const LANGUAGE_CODES[] = {")
|
||||
for code in languages:
|
||||
_append_string_entry(lines, code)
|
||||
lines.append("};")
|
||||
@@ -686,13 +689,13 @@ def generate_strings_cpp(
|
||||
# Compile-time size checks
|
||||
lines.append("// Compile-time validation of array sizes")
|
||||
for code in languages:
|
||||
lines.append(
|
||||
f"static_assert(sizeof(i18n_strings::OFFSETS_{code}) "
|
||||
f"/ sizeof(i18n_strings::OFFSETS_{code}[0]) =="
|
||||
lines.extend(
|
||||
(
|
||||
f"static_assert(sizeof(i18n_strings::OFFSETS_{code}) / sizeof(i18n_strings::OFFSETS_{code}[0]) ==",
|
||||
" static_cast<size_t>(StrId::_COUNT),",
|
||||
f' "OFFSETS_{code} size mismatch");',
|
||||
)
|
||||
)
|
||||
lines.append(" static_cast<size_t>(StrId::_COUNT),")
|
||||
lines.append(f' "OFFSETS_{code} size mismatch");')
|
||||
|
||||
_write_file(output_path, lines, verbose)
|
||||
|
||||
|
||||
|
||||
@@ -27,17 +27,17 @@ def get_font(size=20):
|
||||
import sys
|
||||
|
||||
candidates = []
|
||||
if sys.platform == "win32":
|
||||
if sys.platform == "darwin":
|
||||
candidates = [
|
||||
"/System/Library/Fonts/Helvetica.ttc",
|
||||
"/Library/Fonts/Arial.ttf",
|
||||
]
|
||||
elif sys.platform == "win32":
|
||||
windir = os.environ.get("WINDIR", "C:\\Windows")
|
||||
candidates = [
|
||||
os.path.join(windir, "Fonts", "arial.ttf"),
|
||||
os.path.join(windir, "Fonts", "calibri.ttf"),
|
||||
]
|
||||
elif sys.platform == "darwin":
|
||||
candidates = [
|
||||
"/System/Library/Fonts/Helvetica.ttc",
|
||||
"/Library/Fonts/Arial.ttf",
|
||||
]
|
||||
else:
|
||||
candidates = [
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
|
||||
Reference in New Issue
Block a user