public void AddLocalizedTranslationForBasicRestaurant()
{
log.InfoFormat("[AddLocalizedTranslationForBasicRestaurant].");
int count = 0;
//int menuPartId = 0;
string restId = "52cbed8e3720e811740b9193";
try
{
RestaurantBasicData rest = serviceLayer.GetRestaurantBasicById(restId);
//serviceLayer.UpdateDish();
foreach (MenuPart menuPart in rest.Menu.MenuParts)
{
foreach (Dish dish in menuPart.Dishes)
{
if (dish.Name != null && dish.Name != "")
{
string text = dish.Name;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
if (dish.LocalizedName != null)
{
dish.LocalizedName.AddDescription("en-US", translation);
dish.LocalizedName.AddDescription("he", dish.Name);
}
else
{
dish.LocalizedName = new Localized("en-US", translation);
dish.LocalizedName.AddDescription("he", dish.Name);
}
log.InfoFormat("[AddLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, dishLocalizedName={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishNameCount++;
}
if (translation == text) log.WarnFormat("[AddTranslationForIngredient] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
if (dish.Description != null && dish.Description != "")
{
string text = dish.Description;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
if (dish.LocalizedDescription != null)
{
dish.LocalizedDescription.AddDescription("en-US", translation);
dish.LocalizedDescription.AddDescription("he", dish.Description);
}
else
{
dish.LocalizedDescription = new Localized("en-US", translation);
dish.LocalizedDescription.AddDescription("he", dish.Description);
}
log.InfoFormat("[AddLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, LocalizedDescription={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishDescCount++;
}
if (translation == text) log.WarnFormat("[AddTranslationForIngredient] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
serviceLayer.UpdateDish(dish, restId, menuPart.Id);
log.InfoFormat("[AddLocalizedTranslationForBasicRestaurant] After translation.");
}
}
log.InfoFormat("[AddLocalizedTranslationForBasicRestaurant] Count of dish names={0}, Count of dish descriptions.", DishNameCount, DishDescCount);
}
catch (Exception e)
{
log.ErrorFormat("[AddLocalizedTranslationForBasicRestaurant] Exception={0}, current dishes count={1}", e, count);
}
}