mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[desktop] Display type names
Signed-off-by: Dobri Dabar <dobridabar@noreply.codeberg.org> Co-authored-by: Dobri Dabar <dobridabar@noreply.codeberg.org> Co-committed-by: Dobri Dabar <dobridabar@noreply.codeberg.org>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -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
|
||||
|
||||
|
||||
@@ -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..."
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#include <ctime>
|
||||
#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)
|
||||
|
||||
74
tools/python/generate_desktop_ui_strings.py
Executable file
74
tools/python/generate_desktop_ui_strings.py
Executable file
@@ -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 <string>\n')
|
||||
f.write('#include <unordered_map>\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<std::string, std::string>;\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())
|
||||
2
tools/unix/generate_desktop_ui_strings.sh
Executable file
2
tools/unix/generate_desktop_ui_strings.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env sh
|
||||
./tools/python/generate_desktop_ui_strings.py
|
||||
Reference in New Issue
Block a user