예제 #1
0
        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);
            }
        }
예제 #2
0
        protected void AddSupportedLanguage(string language, string ocrLanguageName)
        {
            CultureInfo culture;

            if (LocaleHelper.TryParseCulture(language, out culture))
            {
                SupportedLanguages[culture.Name] = ocrLanguageName;
                //SupportedLanguages[language] = ocrLanguageName;
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
파일: LocaleHelper.cs 프로젝트: radtek/Ocr
        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);
        }