public void AddTranslationForIngredient(Ingredient ingredient)
{
log.InfoFormat("[AddTranslationForIngredient] ingredient.USDA_NDB_No={0}, ingredient.LongDesc={1}.", ingredient.USDA_NDB_No, ingredient.LongDesc.GetDescription());
string text = "";
string translation = "";
if (ingredient.LongDesc != null && ingredient.LongDesc.GetDescription() != null && ingredient.LongDesc.GetDescription() != "")
{
text = ingredient.LongDesc.GetDescription();
charsCount += text.Length;
translation = GoogleTranslate(text, "iw");
if (translation != null && translation != "" && translation != text)
{
ingredient.LongDesc.AddDescription("he", translation);
log.InfoFormat("[AddTranslationForIngredient] Ingredient.LongDescription={0}, translation={1}", text, translation);
LongDescCount++;
}
if (translation == text) log.WarnFormat("[AddTranslationForIngredient] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
if (ingredient.ComName != null && ingredient.ComName.GetDescription() != null && ingredient.ComName.GetDescription() != "")
{
text = ingredient.ComName.GetDescription();
charsCount += text.Length;
translation = GoogleTranslate(text, "iw");
if (translation != null && translation != "" && translation != text )
{
ingredient.ComName.AddDescription("he", translation);
log.InfoFormat("[AddTranslationForIngredient] Ingredient.ComName={0}, translation={1}", text, translation);
ComNameCount++;
}
if (translation == text) log.WarnFormat("[AddTranslationForIngredient] Translation same to input text. translation=input={0}. Translation not added.", translation);
}
IngredientCount++;
serviceLayer.UpdateIngredient(ingredient);
//log.InfoFormat("[AddTranslationForIngredient] Ingredient.LongDescription={0}, translation={1}", text, translation);
Console.Write("[AddTranslationForIngredient] Ingredient.LongDescription={0}, translation={1}, Ingredient.ComName={0}.\n", ingredient.LongDesc.GetDescription(), translation);
}