[generator:geo_objects] Fix object name

This commit is contained in:
Anatoly Serdtcev 2019-07-22 16:41:06 +03:00 committed by LaGrunge
parent 58998510de
commit 041d47cd27
4 changed files with 38 additions and 10 deletions

View file

@ -68,11 +68,11 @@ void UpdateCoordinates(m2::PointD const & point, base::JSONPtr & json)
base::JSONPtr AddAddress(FeatureBuilder const & fb, KeyValue const & regionKeyValue)
{
auto result = regionKeyValue.second->MakeDeepCopyJson();
int const kHouseOrPoiRank = 30;
UpdateCoordinates(fb.GetKeyPoint(), result);
auto properties = base::GetJSONObligatoryField(result.get(), "properties");
auto address = base::GetJSONObligatoryFieldByPath(properties, "locales", "default", "address");
ToJSONObject(*properties, "rank", kHouseOrPoiRank);
auto const street = fb.GetParams().GetStreet();
if (!street.empty())
ToJSONObject(*address, "street", street);
@ -84,6 +84,12 @@ base::JSONPtr AddAddress(FeatureBuilder const & fb, KeyValue const & regionKeyVa
else
ToJSONObject(*address, "building", base::NewJSONNull());
Localizator localizator(*properties);
localizator.SetLocale("name", Localizator::EasyObjectWithTranslation(fb.GetMultilangName()));
int const kHouseOrPoiRank = 30;
ToJSONObject(*properties, "rank", kHouseOrPoiRank);
ToJSONObject(*properties, "dref", KeyValueStorage::SerializeDref(regionKeyValue.first));
// auto locales = json_object_get(result.get(), "locales");
// auto en = json_object_get(result.get(), "en");
@ -100,9 +106,11 @@ std::shared_ptr<JsonValue> FindHousePoi(FeatureBuilder const & fb,
base::JSONPtr MakeGeoObjectValueWithoutAddress(FeatureBuilder const & fb, JsonValue const & json)
{
auto jsonWithAddress = json.MakeDeepCopyJson();
auto properties = json_object_get(jsonWithAddress.get(), "properties");
Localizator localizator(*properties);
localizator.AddLocale("name", Localizator::EasyObjectWithTranslation(fb.GetMultilangName()));
localizator.SetLocale("name", Localizator::EasyObjectWithTranslation(fb.GetMultilangName()));
UpdateCoordinates(fb.GetKeyPoint(), jsonWithAddress);
return jsonWithAddress;
}

View file

@ -111,7 +111,7 @@ private:
CHECK(region.GetLevel() != regions::PlaceLevel::Unknown, ());
auto const label = GetLabel(region.GetLevel());
CHECK(label, ());
localizator.AddLocale(label, region, "address");
localizator.SetLocale(label, region, "address");
if (m_verbose)
{
localizator.AddVerbose(
@ -124,7 +124,7 @@ private:
}
}
localizator.AddLocale("name", main);
localizator.SetLocale("name", main);
ToJSONObject(*properties, "rank", main.GetRank());
if (path.size() > 1)

View file

@ -190,17 +190,17 @@ base::JSONPtr StreetsBuilder::MakeStreetValue(uint64_t regionId, JsonValue const
m2::RectD const & bbox, m2::PointD const & pinPoint)
{
auto streetObject = base::NewJSONObject();
auto && regionLocales = base::GetJSONObligatoryFieldByPath(regionObject, "properties", "locales");
auto locales = base::JSONPtr{json_deep_copy(const_cast<json_t *>(regionLocales))};
auto properties = base::NewJSONObject();
ToJSONObject(*properties, "locales", std::move(locales));
Localizator localizator(*properties);
auto const & localizee = Localizator::EasyObjectWithTranslation(streetName);
localizator.AddLocale("name", localizee);
localizator.AddLocale("street", localizee, "address");
localizator.SetLocale("name", localizee);
localizator.SetLocale("street", localizee, "address");
ToJSONObject(*properties, "dref", KeyValueStorage::SerializeDref(regionId));
ToJSONObject(*streetObject, "properties", std::move(properties));

View file

@ -53,14 +53,17 @@ public:
explicit Localizator(json_t & node) : m_node(GetOrCreateNode("locales", node)) {}
template <class Object>
void AddLocale(std::string const & label, Object const & objectWithName,
void SetLocale(std::string const & label, Object const & objectWithName,
std::string const & level = std::string())
{
RemoveLocale(DefaultLocaleName(), level, label);
AddLocale(DefaultLocaleName(), level, objectWithName.GetName(), label);
auto const & languages = LocaleLanguages();
for (std::string const & language : languages)
{
RemoveLocale(language, level, label);
std::string const & translation = objectWithName.GetTranslatedOrTransliteratedName(
StringUtf8Multilang::GetLangIndex(language));
@ -114,6 +117,23 @@ private:
return *node;
}
void RemoveLocale(std::string const & language, std::string const & level,
std::string const & label)
{
json_t * node = base::GetJSONOptionalField(&m_node, language);
if (!node)
return;
if (!level.empty())
{
node = base::GetJSONOptionalField(node, level);
if (!node)
return;
}
json_object_del(node, label.c_str());
}
std::vector<std::string> const & LocaleLanguages() const;
json_t & m_node;