How to convert Cyrillic string to English in C #

Is it possible to convert a cyrillic string to English (Latin) in C #? For example, I need to convert Petroleum to Oil. Plus, I forgot to mention that if I have a Cyrillic line, I need to stay that way, so that I can somehow check this?

+7
string c #
source share
10 answers

I am not familiar with the Cyrillic alphabet, but if this is just a 1-to-1 mapping of Cyrillic characters to the Latin characters you need, you can use a dictionary of character pairs and display each character separately:

var map = new Dictionary<char, string> { { '', "P" }, { '', "e" }, { '', "t" }, { '', "r" }, ... } var result = string.Concat("".Select(c => map[c])); 
+7
source share

You can, of course, match the letters of the Latin transcription, but in most cases you will not get the English word. For example. The Russian Federation transcribes the "Russian Federation". wikipedia offers an overview of the mapping. You are probably looking for a translation service, google probably offers an api for this.

+3
source share

If you use Windows 7, you can use the new ELS API (Extended Linguistic Services), which provides transliteration for you. Check out the Windows 7 API Code Code - a set of managed shells on top of many of the newer APIs in Windows 7 (like the new taskbar). Look in the Samples folder for an example Transliterator , you will find exactly what you are looking for:

+3
source share

http://code.google.com/apis/ajaxlanguage/documentation/#Transliteration

Google offers this AJAX-based transliteration service. This way you can avoid transliterating yourself and let Google do it on the fly. This will mean that the client side will make a request to Google, so this means that your application will need to have some kind of web output for this solution to work.

+2
source share

You can use the text.Replace(pair.Key, pair.Value) function text.Replace(pair.Key, pair.Value) .

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Transliter { public partial class Form1 : Form { Dictionary<string, string> words = new Dictionary<string, string>(); public Form1() { InitializeComponent(); words.Add("", "a"); words.Add("", "b"); words.Add("", "v"); words.Add("", "g"); words.Add("", "d"); words.Add("", "e"); words.Add("", "yo"); words.Add("", "zh"); words.Add("", "z"); words.Add("", "i"); words.Add("", "j"); words.Add("", "k"); words.Add("", "l"); words.Add("", "m"); words.Add("", "n"); words.Add("", "o"); words.Add("", "p"); words.Add("", "r"); words.Add("", "s"); words.Add("", "t"); words.Add("", "u"); words.Add("", "f"); words.Add("", "h"); words.Add("", "c"); words.Add("", "ch"); words.Add("", "sh"); words.Add("", "sch"); words.Add("", "j"); words.Add("", "i"); words.Add("", "j"); words.Add("", "e"); words.Add("", "yu"); words.Add("", "ya"); words.Add("", "A"); words.Add("", "B"); words.Add("", "V"); words.Add("", "G"); words.Add("", "D"); words.Add("", "E"); words.Add("", "Yo"); words.Add("", "Zh"); words.Add("", "Z"); words.Add("", "I"); words.Add("", "J"); words.Add("", "K"); words.Add("", "L"); words.Add("", "M"); words.Add("", "N"); words.Add("", "O"); words.Add("", "P"); words.Add("", "R"); words.Add("", "S"); words.Add("", "T"); words.Add("", "U"); words.Add("", "F"); words.Add("", "H"); words.Add("", "C"); words.Add("", "Ch"); words.Add("", "Sh"); words.Add("", "Sch"); words.Add("", "J"); words.Add("", "I"); words.Add("", "J"); words.Add("", "E"); words.Add("", "Yu"); words.Add("", "Ya"); } private void button1_Click(object sender, EventArgs e) { string source = textBox1.Text; foreach (KeyValuePair<string, string> pair in words) { source = source.Replace(pair.Key, pair.Value); } textBox2.Text = source; } } } 

If you change

cryllic to latin:

 text.Replace(pair.Key, pair.Value); 

latin to cryllic

 source.Replace(pair.Value,pair.Key); 
+2
source share

This method is very fast:

 static string[] CyrilicToLatinL = "a,b,v,g,d,e,zh,z,i,j,k,l,m,n,o,p,r,s,t,u,f,kh,c,ch,sh,sch,j,y,j,e,yu,ya".Split(','); static string[] CyrilicToLatinU = "A,B,V,G,D,E,Zh,Z,I,J,K,L,M,N,O,P,R,S,T,U,F,Kh,C,Ch,Sh,Sch,J,Y,J,E,Yu,Ya".Split(','); public static string CyrilicToLatin(string s) { var sb = new StringBuilder((int)(s.Length * 1.5)); foreach (char c in s) { if (c >= '\x430' && c <= '\x44f') sb.Append(CyrilicToLatinL[c - '\x430']); else if (c >= '\x410' && c <= '\x42f') sb.Append(CyrilicToLatinU[c - '\x410']); else if (c == '\x401') sb.Append("Yo"); else if (c == '\x451') sb.Append("yo"); else sb.Append(c); } return sb.ToString(); } 
+2
source share

Use the dictionary with Russian and English words as a reference table. It will gain a lot to create it, but it is a complete proof.

0
source share

Why would you want to do that? Changing the characters "one on one" usually does not even lead to a reasonable transliteration, and even more so to a translation. You can find this post to be of interest.

0
source share

Are you looking for a way to transliterate Russian words written in cirillic (in some encodings, for example, even in Latin encoding, since iso 8859-5 aka Latin-5 for Cyrillic) into the Latin alphabet (with accents)?

I donโ€™t know if .NET has something to transliterate, but I dare say that it (like many other good frameworks). This wikipedian link may give you some ideas for transliteration, but this is not the only way to remember that Cyrillic writing systems are not used only by Russians, and the way transliteration is applied may vary in a language using a writing system. For example. look the same for Bulgarian . May this link (always from wp) may also be interesting if you want to program the transliterator yourself.

0
source share

This is a solution for transliterating Serbian Cyrillic latin for this form: form

 namespace WindowsFormsApplication1 { public partial class Form1 : Form { Dictionary<string, string> slova = new Dictionary<string, string>(); public Form1() { InitializeComponent(); slova.Add("ะ‰", "Lj"); slova.Add("ะŠ", "Nj"); slova.Add("ะ", "Dลพ"); slova.Add("ั™", "lj"); slova.Add("ัš", "nj"); slova.Add("ัŸ", "dลพ"); slova.Add("", "a"); slova.Add("", "b"); slova.Add("", "v"); slova.Add("", "g"); slova.Add("", "d"); slova.Add("ั’", "ฤ‘"); slova.Add("", "e"); slova.Add("", "ลพ"); slova.Add("", "z"); slova.Add("", "i"); slova.Add("ั˜", "j"); slova.Add("", "k"); slova.Add("", "l"); slova.Add("", "m"); slova.Add("", "n"); slova.Add("", "o"); slova.Add("", "p"); slova.Add("", "r"); slova.Add("", "s"); slova.Add("", "t"); slova.Add("ั›", "ฤ‡"); slova.Add("", "u"); slova.Add("", "f"); slova.Add("", "h"); slova.Add("", "c"); slova.Add("", "ฤ"); slova.Add("", "ลก"); } // Method for cyrillic to latin private void button1_Click(object sender, EventArgs e) { string source = textBox1.Text; foreach (KeyValuePair<string, string> pair in slova) { source = source.Replace(pair.Key, pair.Value); // For upper case source = source.Replace(pair.Key.ToUpper(), pair.Value.ToUpper()); } textBox2.Text = source; } // Method for latin to cyrillic private void button2_Click(object sender, EventArgs e) { string source = textBox2.Text; foreach (KeyValuePair<string, string> pair in slova) { source = source.Replace(pair.Value, pair.Key); // For upper case source = source.Replace(pair.Value.ToUpper(), pair.Key.ToUpper()); } textBox1.Text = source; } } } 
0
source share

All Articles