From 9562fb6b62c418fae6889a4a34e525898a43c6ca Mon Sep 17 00:00:00 2001 From: Andrew Gubskiy Date: Mon, 21 Oct 2013 23:56:28 +0300 Subject: [PATCH] Added transliteration support --- Properties/AssemblyInfo.cs | 8 +- Transliterator.cs | 151 +++++++++++++++++++++++++++++++++++++ X.Text.csproj | 1 + 3 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 Transliterator.cs diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 1f19ee9..9d76abd 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -8,9 +8,9 @@ [assembly: AssemblyTitle("X.Text")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("agi.net.ua")] +[assembly: AssemblyCompany("Andrew Gubskiy")] [assembly: AssemblyProduct("X.Text")] -[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyCopyright("Copyright © Ernado 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.3.1")] -[assembly: AssemblyFileVersion("1.1.3.1")] +[assembly: AssemblyVersion("1.2.0.0")] +[assembly: AssemblyFileVersion("1.2.0.0")] diff --git a/Transliterator.cs b/Transliterator.cs new file mode 100644 index 0000000..31defae --- /dev/null +++ b/Transliterator.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; + +namespace X.Text +{ + /// + /// + /// + public class Transliterator + { + private static readonly Dictionary _cyrrilic; + + static Transliterator() + { + _cyrrilic = new Dictionary + { + + {"щ", "shch"}, + {"Щ", "Shch"}, + + {"ё", "yo"}, + {"Ё", "Yo"}, + + {"є", "ye"}, + + {"ж", "zh"}, + {"Ж", "Zh"}, + + {"ї", "yi"}, + {"Ї", "Yi"}, + + {"э", "e"}, + {"Э", "E"}, + + {"ч", "ch"}, + {"Ч", "Ch"}, + + {"ш", "sh"}, + {"Ш", "Sh"}, + + {"ц", "ts"}, + {"Ц", "Ts"}, + + {"ю", "yu"}, + {"Ю", "Yu"}, + + {"Я", "Ya"}, + {"я", "ya"}, + + {"ъ", "__"}, + {"Ъ", "__"}, + + {"х", "kh"}, + {"Х", "Kh"}, + + {"ь", "_"}, + {"Ь", "_"}, + + {"б", "b"}, + {"Б", "B"}, + + {"в", "v"}, + {"В", "V"}, + + {"г", "g"}, + {"Г", "G"}, + + {"ґ", "g"}, + {"Ґ", "G"}, + + {"д", "d"}, + {"Д", "D"}, + + {"е", "e"}, + {"Е", "E"}, + + + {"з", "z"}, + {"З", "Z"}, + + {"и", "i"}, + {"И", "I"}, + + {"й", "y"}, + {"Й", "Y"}, + + {"к", "k"}, + {"К", "K"}, + + {"л", "l"}, + {"Л", "L"}, + + {"м", "m"}, + {"М", "M"}, + + {"н", "n"}, + {"Н", "N"}, + + {"п", "p"}, + {"П", "P"}, + + {"р", "r"}, + {"Р", "R"}, + + {"с", "s"}, + {"С", "S"}, + + {"т", "t"}, + {"Т", "T"}, + + {"о", "o"}, + {"О", "O"}, + + {"а", "a"}, + {"А", "A"}, + + {"ф", "f"}, + {"Ф", "F"}, + + {"і", "i"}, + {"І", "I"}, + + {"У", "U"}, + {"у", "u"}, + + {"ы", "y"}, + {"Ы", "Y"}, + }; + } + + public static String FromTransliterationToCyrillic(string text) + { + foreach (var item in _cyrrilic) + { + text = text.Replace(item.Value, item.Key); + } + + return text; + } + + public static String FromCyrillicToTransliteration(string text) + { + foreach (var item in _cyrrilic) + { + text = text.Replace(item.Key, item.Value); + } + + return text; + } + } +} diff --git a/X.Text.csproj b/X.Text.csproj index 7a7f2d2..29b098e 100644 --- a/X.Text.csproj +++ b/X.Text.csproj @@ -39,6 +39,7 @@ +