Skip to content

Commit

Permalink
Added transliteration support
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Oct 21, 2013
1 parent de015be commit 9562fb6
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]

Expand All @@ -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")]
151 changes: 151 additions & 0 deletions Transliterator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;

namespace X.Text
{
/// <summary>
///
/// </summary>
public class Transliterator
{
private static readonly Dictionary<String, String> _cyrrilic;

static Transliterator()
{
_cyrrilic = new Dictionary<string, string>
{

{"щ", "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;
}
}
}
1 change: 1 addition & 0 deletions X.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ItemGroup>
<Compile Include="TextHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Transliterator.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 9562fb6

Please sign in to comment.