public string Translate(string value, string fromLanguage, string toLanguage) { CultureInfo fromCulture, toCulture; if (!LocaleHelper.TryParseCulture(fromLanguage, out fromCulture) || !LocaleHelper.TryParseCulture(toLanguage, out toCulture)) { return(null); } string fromApiLanguage = GetSupportedLanguageName(fromCulture.Name); string toApiLanguage = GetSupportedLanguageName(toCulture.Name); if (string.IsNullOrEmpty(fromApiLanguage) || string.IsNullOrEmpty(toApiLanguage)) { return(null); } try { return(Translate(value, fromCulture.Name, toCulture.Name, fromApiLanguage, toApiLanguage)); } catch { return(null); } }
protected void AddSupportedLanguage(string language, string ocrLanguageName) { CultureInfo culture; if (LocaleHelper.TryParseCulture(language, out culture)) { SupportedLanguages[culture.Name] = ocrLanguageName; //SupportedLanguages[language] = ocrLanguageName; } }
protected bool AddSupportedLanguage(string language, string ocrLanguageName) { CultureInfo culture; if (LocaleHelper.TryParseCulture(language, out culture)) { SupportedLanguages[culture.Name] = ocrLanguageName; //SupportedLanguages[language] = ocrLanguageName; return(true); } return(false); }
public static string GetLanguageKey(Dictionary <string, string> languages, string language) { CultureInfo cultureInfo; if (!LocaleHelper.TryParseCulture(language, out cultureInfo)) { return(null); } List <string> systemLanguages = languages.Keys.ToList(); string name = systemLanguages.FirstOrDefault(x => x.Equals(cultureInfo.Name, StringComparison.OrdinalIgnoreCase)); if (name != null) { return(name); } string threeLetterISO = systemLanguages.FirstOrDefault(x => x.Equals(cultureInfo.ThreeLetterISOLanguageName, StringComparison.OrdinalIgnoreCase)); if (threeLetterISO != null) { return(threeLetterISO); } string twoLetterISO = systemLanguages.FirstOrDefault(x => x.Equals(cultureInfo.TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase)); if (twoLetterISO != null) { return(twoLetterISO); } string displayName = systemLanguages.FirstOrDefault(x => x.Equals(cultureInfo.DisplayName, StringComparison.OrdinalIgnoreCase)); if (displayName != null) { return(displayName); } return(null); }