Exemplo n.º 1
0
        public static string Front(string text, TransliterationType type)

        {
            var output = text;


            output = Regex.Replace(output, @"\s|\.|\(", " ");

            output = Regex.Replace(output, @"\s+", " ");

            output = Regex.Replace(output, @"[^\s\w\d-]", "");

            output = output.Trim();


            var tdict = GetDictionaryByType(type);


            foreach (var key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }

            return(output);
        }
Exemplo n.º 2
0
        public static string Front(string text, TransliterationType type)
        {
            string output = text;
            Dictionary <string, string> tdict = GetDictionaryByType(type);

            return(tdict.Aggregate(output, (current, key) => current.Replace(key.Key, key.Value)));
        }
Exemplo n.º 3
0
        public static string Back(string text, TransliterationType type)
        {
            var output = text;
            var tdict  = GetDictionaryByType(type);

            return(tdict.Aggregate(output, (current, key) => current.Replace(key.Value, key.Key)));
        }
Exemplo n.º 4
0
        private static Dictionary <string, string> GetDictionaryByType(TransliterationType type)
        {
            var tdict = iso;

            if (type == TransliterationType.Gost)
            {
                tdict = gost;
            }
            return(tdict);
        }
        private Dictionary <string, string> GetDictionaryByType(TransliterationType type)
        {
            Dictionary <string, string> tdict = Iso;

            if (type == TransliterationType.Gost)
            {
                tdict = Gost;
            }
            return(tdict);
        }
Exemplo n.º 6
0
        public static string Front(string text, TransliterationType type = TransliterationType.GOST)
        {
            string output = string.Empty;
            Dictionary <char, string> dict = (type == TransliterationType.ISO) ? isoFront : gostFront;

            foreach (char c in text)
            {
                output += dict.ContainsKey(c) ? dict[c] : c.ToString();
            }
            return(output);
        }
Exemplo n.º 7
0
        public static string Back(this string text, TransliterationType type)
        {
            string output = text;
            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (string key in tdict.Keys)
            {
                output = output.Replace(tdict[key], key);
            }
            return(output);
        }
Exemplo n.º 8
0
        public static string Back(string text, TransliterationType type)
        {
            var output = text;
            var tdict  = GetDictionaryByType(type);

            foreach (var key in tdict)
            {
                output = output.Replace(key.Value, key.Key);
            }
            return(output);
        }
Exemplo n.º 9
0
        public static string Back(string text, TransliterationType type)
        {
            string output = text;
            Dictionary<string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair<string, string> key in tdict)
            {
                output = output.Replace(key.Value, key.Key);
            }
            return output.Replace("__", "_").Replace("__", "_").Trim(new[] { ' ', '_' });
        }
        public string Back(string text, TransliterationType type = TransliterationType.ISO)
        {
            string output = text;
            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                output = output.Replace(key.Value, key.Key);
            }
            return(output);
        }
Exemplo n.º 11
0
        public static string Front(string text, TransliterationType type, bool ReplaceSpaces = true)
        {
            var _result = Front(text, type);

            if (ReplaceSpaces)
            {
                return(_result.Replace(' ', '_'));
            }

            return(_result);
        }
Exemplo n.º 12
0
        public static string Back(string text, TransliterationType type)
        {
            var output = text;
            var tdict  = GetDictionaryByType(type);

            foreach (var x in tdict)
            {
                if (x.Value.Length > 0)
                {
                    output = output.Replace(x.Value, x.Key);
                }
            }
            return(output);
        }
        private static string Front(string text, TransliterationType type)
        {
            Log.Trace("Entered text start to translit.");
            string output = text;

            output = output.Trim();

            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }
            return(output);
        }
        public string ToRussian(string text, TransliterationType type = TransliterationType.ISO)
        {
            string output = text;

            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                if (!string.IsNullOrEmpty(key.Value))
                {
                    output = output.Replace(key.Value, key.Key);
                }
            }

            return(output);
        }
        /// <summary>
        /// Перевод с русского на английский по указанному стандарту.
        /// (Если в результате транслитерации получится пустая строка, то вернётся ""Transliteration" + random").
        /// </summary>
        /// <param name="text">Переводимый текст на русском языке.</param>
        /// <param name="type">Используемый стандарт.</param>
        /// <returns>Переведённый текст на английском языке.</returns>
        public static string Front(string text, TransliterationType type)
        {
            string output = text;
            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }

            if (string.IsNullOrEmpty(text) || text.Trim() == string.Empty)
            {
                output = "Transliteration" + DateTime.Now.Ticks;
            }

            return(output);
        }
        }                                                    //ISO 9-95

        public string Front(string text, TransliterationType type = TransliterationType.ISO)
        {
            string output = text;

            output = Regex.Replace(output, @"\s|\.|\(", " ");
            output = Regex.Replace(output, @"\s+", " ");
            output = Regex.Replace(output, @"[^\s\w\d-]", "");
            output = output.Trim();

            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }
            return(output);
        }
Exemplo n.º 17
0
        public static string Front(string text, TransliterationType type)
        {
            Dictionary <string, string> tdict = GetDictionaryByType(type);
            string        output = "";
            StringBuilder sb     = new StringBuilder(text);

            for (int i = 0; i < sb.Length; i++)
            {
                if (tdict.ContainsKey(sb[i].ToString()))
                {
                    output += tdict[sb[i].ToString()];
                }
                else
                {
                    output += sb[i].ToString();
                }
            }

            return(output);
        }
Exemplo n.º 18
0
        public static string Back(string text, TransliterationType type = TransliterationType.GOST)
        {
            int    l      = text.Length;
            string output = string.Empty;
            Dictionary <string, char> dict = (type == TransliterationType.ISO) ? isoBack : gostBack;
            int i = 0;

            while (i < l)
            {
                string s = text.Substring(i, Math.Min(3, l - i));
                do
                {
                    if (dict.ContainsKey(s))
                    {
                        output += dict[s];
                        i      += s.Length;
                        break;
                    }
                    s = s.Remove(s.Length - 1);
                } while (s.Length > 0);
                i += s.Length == 0 ? 3 : 0;
            }
            return(output);
        }
        /// <summary>
        /// Перевод с английского на русский по указанному стандарту.
        /// (Если в результате транслитерации получится пустая строка, то вернётся ""Транслитерация" + random").
        /// </summary>
        /// <param name="text">Переводимый текст на английском языке.</param>
        /// <param name="type">Используемый стандарт.</param>
        /// <returns>Переведённый текст на русском языке.</returns>
        public static string Back(string text, TransliterationType type)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            string output = text;
            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict.Where(x => !string.IsNullOrEmpty(x.Value)))
            {
                output = output.Replace(key.Value, key.Key);
            }

            output = ReleaseStringFromEnglishSymbols(output);

            if (string.IsNullOrEmpty(output) || text.Trim() == string.Empty)
            {
                output = "Транслитерация" + DateTime.Now.Ticks;
            }

            return(output);
        }
Exemplo n.º 20
0
        public static string GetFriendlyUrl(string url, TransliterationType type)
        {
            string output = (url ?? "").ToLower();

            output = Regex.Replace(output, @"\&+", "and");
            output = output.Replace("'", "");
            output = Regex.Replace(output, @"[^a-zа-я0-9]", "-");
            output = Regex.Replace(output, @"-+", "-");
            output = Regex.Replace(output, @"_", "-");
            output = output.Trim('-');
            output = Regex.Replace(output, @"\s|\.|\(", " ");
            output = Regex.Replace(output, @"\s+", " ");
            output = Regex.Replace(output, @"[^\s\w\d-]", "");
            output = output.Trim();

            Dictionary <string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair <string, string> key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }

            return(output);
        }
Exemplo n.º 21
0
 private static Dictionary<string, string> GetDictionaryByType(TransliterationType type)
 {
     return (type == TransliterationType.Gost) ? Gost : Iso;
 }
 private Dictionary<String, String> GetDictionaryByType(TransliterationType type)
 {
     Dictionary<String, String> tdict = iso;
     if (type == TransliterationType.Gost) tdict = gost;
     return tdict;
 }
 private string Front(string text, TransliterationType type)
 {
     string output = text;
     Dictionary<String, String> tdict = GetDictionaryByType(type);
     foreach (KeyValuePair<String, String> key in tdict)
     {
         output = output.Replace(key.Key, key.Value);
     }
     output = output.Replace("ij", "y");
     return output;
 }
Exemplo n.º 24
0
 public static string Translit(this string value, TransliterationType type)
 {
     return(Translitter.Front(value, type));
 }
Exemplo n.º 25
0
 public static string UnTranslit(this string value, TransliterationType type)
 {
     return(Translitter.Back(value, type));
 }
Exemplo n.º 26
0
 private static Dictionary<string, string> GetDictionaryByType(TransliterationType type)
 {
     Dictionary<string, string> tdict = iso;
     if (type == TransliterationType.Gost) tdict = gost;
     return tdict;
 }
Exemplo n.º 27
0
 private static Dictionary<string, string> GetDictionaryByType(TransliterationType type)
 {
     var tdict = iso;
     if (type == TransliterationType.Gost) tdict = gost;
     return tdict;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Из кириллицы в латиницу
        /// </summary>
        public static string Transliterate(string text, CharCase charCase = CharCase.Upper, TransliterationType type = TransliterationType.ISO)
        {
            Dictionary <string, string> tdict = GetDictionaryByType(type);
            string        output = string.Empty;
            StringBuilder sb     = new StringBuilder(text);

            for (int i = 0; i < sb.Length; i++)
            {
                if (tdict.ContainsKey(sb[i].ToString()))
                {
                    output += tdict[sb[i].ToString()];
                }
                else
                {
                    output += sb[i].ToString();
                }
            }
            switch (charCase)
            {
            case CharCase.AsIs:     return(output);

            case CharCase.Upper:    return(output.ToUpper());

            case CharCase.Lower:    return(output.ToLower());

            default: return(output);
            }

            /*
             * string output = text;
             * Dictionary<string, string> tdict = GetDictionaryByType(type);
             *
             * foreach (var key in tdict)
             * {
             *  output = output.Replace(key.Key, key.Value);
             * }
             * return output;
             */
        }
        private static Dictionary <string, string> GetDictionaryByType(TransliterationType type)
        {
            Dictionary <string, string> tdict = Iso;

            return(tdict);
        }
Exemplo n.º 30
0
        public static string Front(string text, TransliterationType type)
        {
            string output = text;
            Dictionary<string, string> tdict = GetDictionaryByType(type);

            return tdict.Aggregate(output, (current, key) => current.Replace(key.Key, key.Value));
        }
Exemplo n.º 31
0
        public static string Back(string text, TransliterationType type)
        {
            string output = text;
            var tdict = GetDictionaryByType(type);

            foreach (var key in tdict)
            {
                output = output.Replace(key.Value, key.Key);
            }
            return output;
        }
Exemplo n.º 32
0
 private static Dictionary<string, string> GetDictionaryByType(TransliterationType type)
 {
     Dictionary<string, string> tdict = ISO;
     if (type == TransliterationType.Gost) tdict = Gost;
     return tdict;
 }
Exemplo n.º 33
0
        public static string Front(string text, TransliterationType type)
        {
            Dictionary<string, string> tdict = GetDictionaryByType(type);
                string output = "";
                StringBuilder sb = new StringBuilder(text);
                for (int i = 0; i < sb.Length; i++)
                {
                    if (tdict.ContainsKey(sb[i].ToString()))
                        output += tdict[sb[i].ToString()];
                    else output += sb[i].ToString();
                }

                return output;
        }
 private static Dictionary <string, string> iso = new Dictionary <string, string>(); //ISO 9-95
 public static string Do(string text, TransliterationType TransliterationType)
 {
     return(TransliterationType == TransliterationType.ToEng ? ToEng(text) :
            TransliterationType == TransliterationType.ToRussian ? ToRussian(text) :
            TransliterationType == TransliterationType.ClearLetters ? ClearLetters(text) : text);
 }
Exemplo n.º 35
0
        public static string Front(string text, TransliterationType type)
        {
            string output = text;
            Dictionary<string, string> tdict = GetDictionaryByType(type);

            foreach (KeyValuePair<string, string> key in tdict)
            {
                output = output.Replace(key.Key, key.Value);
            }
            return output;
        }
Exemplo n.º 36
0
        public static string Back(string text, TransliterationType type)
        {
            var output = text;
            var tdict = GetDictionaryByType(type);

            return tdict.Aggregate(output, (current, key) => current.Replace(key.Value, key.Key));
        }