public void UpdateLocalizedTranslationForBasicRestaurant()
{
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant].");
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 != "")
{
if (dish.LocalizedName != null)
{
string locHebrewName = dish.LocalizedName.GetDescription("he");
if (locHebrewName != null)
{
if (locHebrewName != dish.Name)
{
string text = dish.Name;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
dish.LocalizedName.UpdateDescription("en-US", translation);
dish.LocalizedName.UpdateDescription("he", dish.Name);
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, dishLocalizedName={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishNameCount++;
}
if (translation == text) log.WarnFormat("[UpdateLocalizedTranslationForBasicRestaurant] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
}
else //locHebrewName == null
{
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] locHebrewName == null, add hebrew name to Localized, Name={0}", dish.Name);
dish.LocalizedName.AddDescription("he", dish.Name);
}
}
else //dish.LocalizedName == null
{
string text = dish.Name;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
dish.LocalizedName = new Localized("en-US", translation);
dish.LocalizedName.AddDescription("he", dish.Name);
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, LocalizedName={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishNameCount++;
}
if (translation == text) log.WarnFormat("[UpdateLocalizedTranslationForBasicRestaurant] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
}
if (dish.Description != null && dish.Description != "")
{
if (dish.LocalizedDescription != null)
{
string locHebrewDesc = dish.LocalizedDescription.GetDescription("he");
if (locHebrewDesc != null)
{
if (locHebrewDesc != dish.Description)
{
string text = dish.Description;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
dish.LocalizedDescription.UpdateDescription("en-US", translation);
dish.LocalizedDescription.UpdateDescription("he", dish.Description);
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, LocalizedDescription={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishDescCount++;
}
if (translation == text) log.WarnFormat("[UpdateLocalizedTranslationForBasicRestaurant] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
}
else //locHebrewDesc == null
{
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] locHebrewDesc == null, add hebrew name to Localized, Name={0}", dish.Description);
dish.LocalizedDescription.AddDescription("he", dish.Description);
}
}
else //dish.LocalizedDescription == null
{
string text = dish.Description;
charsCount += text.Length;
string translation = GoogleTranslate(text, "en");
if (translation != null && translation != "" && translation != text)
{
dish.LocalizedDescription = new Localized("en-US", translation);
dish.LocalizedDescription.AddDescription("he", dish.Description);
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] menuPartId={0}, dishId{1}, LocalizedDescription={2}, translation={3}", menuPart.Id, dish.Id, text, translation);
DishDescCount++;
}
if (translation == text) log.WarnFormat("[UpdateLocalizedTranslationForBasicRestaurant] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
}
serviceLayer.UpdateDish(dish, restId, menuPart.Id);
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] After translation.");
}
}
log.InfoFormat("[UpdateLocalizedTranslationForBasicRestaurant] Count of updated dish names={0}, Count of updated dish descriptions={1}.", DishNameCount, DishDescCount);
}
catch (Exception e)
{
log.ErrorFormat("[UpdateLocalizedTranslationForBasicRestaurant] Exception={0}, current dishes count={1}", e, count);
}
}