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