From 4691de7a669ef14366103822db57d54fe090ea18 Mon Sep 17 00:00:00 2001 From: Dobri Dabar Date: Mon, 15 Dec 2025 19:36:29 +0100 Subject: [PATCH] [desktop] Display type names Signed-off-by: Dobri Dabar Co-authored-by: Dobri Dabar Co-committed-by: Dobri Dabar --- .gitignore | 2 + configure.sh | 3 + libs/indexer/CMakeLists.txt | 3 + libs/platform/localization_dummy.cpp | 8 ++- tools/python/generate_desktop_ui_strings.py | 74 +++++++++++++++++++++ tools/unix/generate_desktop_ui_strings.sh | 2 + 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100755 tools/python/generate_desktop_ui_strings.py create mode 100755 tools/unix/generate_desktop_ui_strings.sh diff --git a/.gitignore b/.gitignore index 0af099653..61c829872 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,8 @@ android/huawei-appgallery.json android/res/xml/network_security_config.xml ./server/ iphone/Maps/app.omaps/ +# Generated file +libs/indexer/localized_types_map.cpp *.li diff --git a/configure.sh b/configure.sh index 57f3b18d1..540c70378 100755 --- a/configure.sh +++ b/configure.sh @@ -116,6 +116,9 @@ fi echo "Generating search categories / synonyms..." ./tools/unix/generate_categories.sh +echo "Generating Desktop UI strings..." +./tools/unix/generate_desktop_ui_strings.sh + if [ -z "$SKIP_GENERATE_SYMBOLS" ]; then if Diff data/symbols_hash data/styles/*/*/symbols/* || [ ! -z "$SYMBOLS_NOT_GENERATED" ]; then echo "Generating symbols..." diff --git a/libs/indexer/CMakeLists.txt b/libs/indexer/CMakeLists.txt index ae872b59d..b5e53f119 100644 --- a/libs/indexer/CMakeLists.txt +++ b/libs/indexer/CMakeLists.txt @@ -95,6 +95,9 @@ set(SRC interval_index_builder.hpp isolines_info.cpp isolines_info.hpp + + + localized_types_map.cpp map_object.cpp map_object.hpp map_style.cpp diff --git a/libs/platform/localization_dummy.cpp b/libs/platform/localization_dummy.cpp index f4e5211e3..31e7bed73 100644 --- a/libs/platform/localization_dummy.cpp +++ b/libs/platform/localization_dummy.cpp @@ -1,11 +1,17 @@ #include #include "platform/localization.hpp" +#include "indexer/localized_types_map.cpp" namespace platform { std::string GetLocalizedTypeName(std::string const & type) { - return type; + auto key = "type." + type; + std::replace(key.begin(), key.end(), '-', '.'); + std::replace(key.begin(), key.end(), ':', '_'); + auto const it = g_type2localizedType.find(key); + std::string localizedName = (it != g_type2localizedType.end()) ? it->second : std::string(); + return localizedName.empty() ? type : localizedName; } std::string GetLocalizedBrandName(std::string const & brand) diff --git a/tools/python/generate_desktop_ui_strings.py b/tools/python/generate_desktop_ui_strings.py new file mode 100755 index 000000000..73ea9953d --- /dev/null +++ b/tools/python/generate_desktop_ui_strings.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +""" +Generate localized_types_map.cpp from LocalizableTypes.strings + +This script converts the iOS LocalizableTypes.strings file format to the desktop +localized_types_map.cpp C++ map by: +- Removing comments (/* ... */) +- Removing empty lines +- Converting from "key" = "value"; format to key=value format +- Removing unnecessary quotes and spaces +""" + +import re +import os +import sys +from pathlib import Path + +def parse_localizable_types_line(line): + line = line.strip() + if not line: + return None + + if line.startswith('/*') or line.startswith('//') or line.startswith('/****'): + return None + + # Match pattern: "key" = "value"; + match = re.match(r'^"([^"]+)"\s*=\s*"([^"]*)"\s*;?\s*$', line) + if match: + key = match.group(1) + value = match.group(2) + return (key, value) + + return None + + +def convert_to_localized_types_cpp(input_file, output_file): + with open(input_file, 'r', encoding='utf-8') as f: + lines = f.readlines() + + entries = [] + for line_num, line in enumerate(lines, 1): + try: + parsed = parse_localizable_types_line(line) + if parsed: + key, value = parsed + entries.append((key, value)) + except Exception as e: + print(f"Warning: Error parsing line {line_num}: {e}") + print(f" Line content: {line.strip()}") + continue + + with open(output_file, 'w', encoding='utf-8') as f: + f.write('#pragma once\n\n') + f.write('#include \n') + f.write('#include \n\n') + f.write('// This file is generated automatically. Do not edit.\n') + f.write('// See: tools/python/generate_desktop_ui_strings.py\n') + f.write('using Type2LocalizedType = std::unordered_map;\n') + f.write('const Type2LocalizedType g_type2localizedType = {\n') + for i, (key, value) in enumerate(entries): + comma = ',' if i < len(entries) - 1 else '' + f.write(f' {{"{key}", "{value}"}}{comma}\n') + f.write('};\n') + print(f"Successfully converted {len(entries)} entries from '{input_file}' to '{output_file}'") + + +def main(): + input_file = Path('iphone/Maps/LocalizedStrings/en.lproj/LocalizableTypes.strings') + output_file = Path('libs/indexer/localized_types_map.cpp') + convert_to_localized_types_cpp(str(input_file), str(output_file)) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/unix/generate_desktop_ui_strings.sh b/tools/unix/generate_desktop_ui_strings.sh new file mode 100755 index 000000000..6cd06175f --- /dev/null +++ b/tools/unix/generate_desktop_ui_strings.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +./tools/python/generate_desktop_ui_strings.py