| 47 | } |
| 48 | |
| 49 | void ParseTranslations(json_t * root, std::set<string> const & keys, map<uint32_t, string> & idToKey) |
| 50 | { |
| 51 | string const empty; |
| 52 | auto getKey = [&](string & translation) -> string const & |
| 53 | { |
| 54 | strings::MakeLowerCaseInplace(translation); |
| 55 | translation = strings::Normalize(translation); |
| 56 | replace(translation.begin(), translation.end(), ' ', '_'); |
| 57 | replace(translation.begin(), translation.end(), '-', '_'); |
| 58 | replace(translation.begin(), translation.end(), '\'', '_'); |
| 59 | auto const it = keys.find(translation); |
| 60 | if (it != keys.end()) |
| 61 | return *it; |
| 62 | return empty; |
| 63 | }; |
| 64 | |
| 65 | char const * key; |
| 66 | json_t * value; |
| 67 | json_object_foreach(root, key, value) |
| 68 | { |
| 69 | vector<string> enTranslations; |
| 70 | if (!FromJSONObjectOptional(value, "en", enTranslations)) |
| 71 | continue; |
| 72 | |
| 73 | for (auto & translation : enTranslations) |
| 74 | { |
| 75 | auto const & indexKey = getKey(translation); |
| 76 | if (!indexKey.empty()) |
| 77 | { |
| 78 | uint32_t id; |
| 79 | if (!strings::to_uint(key, id)) |
| 80 | MYTHROW(ParsingError, ("Incorrect brand id:", key)); |
| 81 | idToKey.emplace(id, indexKey); |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | bool LoadBrands(string const & brandsFilename, string const & translationsFilename, map<GeoObjectId, string> & brands) |
| 89 | { |
no test coverage detected