public void TranslateRecipeMicrosoft(BusinessObjects.Recipe recipe) { CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture; if (!currentCulture.TwoLetterISOLanguageName.ToLowerInvariant().Equals("es")) { if (traslator == null) { traslator = new MicrosoftTransProvider(KEY, SECRET); } string target = currentCulture.TwoLetterISOLanguageName; recipe.Title = traslator.Translate(HttpUtility.HtmlDecode(recipe.Title), target); recipe.MainIngredient = traslator.Translate(recipe.MainIngredient, target); recipe.Category = traslator.Translate(recipe.Category, target); if (!string.IsNullOrEmpty(recipe.Procedure)) { string procedure = recipe.Procedure.Replace("\r\n\r\n", " [n] ").Replace("\n ", " [n] "); procedure = traslator.Translate(procedure, target); procedure = HttpUtility.HtmlDecode(procedure); recipe.Procedure = procedure.Replace("[n] ", "\n").Replace("[N] ", "\n").Replace("[ n] ", "\n").Replace("[n ] ", "\n"); } if (recipe.Ingridients != null && recipe.Ingridients.Count > 0) { recipe.Ingridients = TranslateList(traslator, recipe.Ingridients, target); } if (recipe.Alarms != null && recipe.Alarms.Count > 0) { var list = new List<string>(); recipe.Alarms.ForEach(al => al.Name = traslator.Translate(al.Name, target)); } } }
private List<string> TranslateList(MicrosoftTransProvider traslator, List<string> list, string targetLeng) { List<string> result = new List<string>(); string tr = list.First(); for (int i = 1; i < list.Count; i++) { tr += ". " + HttpUtility.HtmlDecode(list.ElementAt(i)); } tr = traslator.Translate(tr, targetLeng); string[] ltr = tr.Split('.'); for (int j = 0; j < ltr.Length; j++) { result.Add(ltr[j].Trim()); } return result; }