| 45 | } |
| 46 | |
| 47 | void NewFeatureCategories::AddLanguage(std::string const & lang) |
| 48 | { |
| 49 | std::string lowerLang = lang; |
| 50 | strings::AsciiToLower(lowerLang); |
| 51 | std::replace(lowerLang.begin(), lowerLang.end(), '_', '-'); |
| 52 | |
| 53 | // Extract base language (e.g., "en-AU" -> "en") to load dialect variations together |
| 54 | std::string const baseLang = lowerLang.substr(0, lowerLang.find('-')); |
| 55 | |
| 56 | bool anyAdded = false; |
| 57 | if (m_baseLangs.insert(baseLang).second) |
| 58 | anyAdded = true; |
| 59 | |
| 60 | // Always ensure English serves as a fallback. |
| 61 | if (m_baseLangs.insert("en").second) |
| 62 | anyAdded = true; |
| 63 | |
| 64 | if (!anyAdded) |
| 65 | return; // This language group was already processed |
| 66 | |
| 67 | m_categoriesData.clear(); |
| 68 | m_categoriesData.reserve(m_types.size()); |
| 69 | |
| 70 | auto const & c = classif(); |
| 71 | auto const & holder = GetDefaultCategories(); |
| 72 | |
| 73 | for (auto const & typeName : m_types) |
| 74 | { |
| 75 | uint32_t const type = c.GetTypeByReadableObjectName(typeName); |
| 76 | if (type == 0) |
| 77 | continue; |
| 78 | |
| 79 | CategoryData data; |
| 80 | data.m_typeName = typeName; |
| 81 | |
| 82 | auto const addSynonym = [&data](std::string const & s) |
| 83 | { |
| 84 | auto norm = strings::ToUtf8(search::NormalizeAndSimplifyString(s)); |
| 85 | if (!norm.empty()) |
| 86 | data.m_synonyms.push_back(std::move(norm)); |
| 87 | }; |
| 88 | |
| 89 | // 1. Add primary localized name (from types_strings.txt via platform) |
| 90 | addSynonym(platform::GetLocalizedTypeName(typeName)); |
| 91 | |
| 92 | // 2. Add all dialect variants efficiently via existing CategoriesHolder mappings |
| 93 | holder.ForEachNameByType(type, [&](auto const & name) { |
| 94 | // name.m_locale comes safely from CategoriesHolder's internal mapping. |
| 95 | std::string l(CategoriesHolder::MapIntegerToLocale(name.m_locale)); |
| 96 | strings::AsciiToLower(l); |
| 97 | |
| 98 | // Match the base language (e.g., if locale is "pt-br", nameBase is "pt") |
| 99 | std::string const nameBase = l.substr(0, l.find('-')); |
| 100 | if (m_baseLangs.contains(nameBase)) |
| 101 | addSynonym(name.m_name); |
| 102 | }); |
| 103 | |
| 104 | // Strip out duplicate normalized strings to maximize search performance |