Input :
<h2>{translate} Dear Atteck {/translate} <br/></h2>{translate}Please complete registration</h5> {/translate}
Output :
<h2> Дeaр Аттeҗк<b/></h2>Плeaсe җомплeтe</һ5>
Main code:
private static readonly Dictionary<string, IOrderedEnumerable<KeyValuePair<string, string>>> TransliterationMaps = new Dictionary<string, IOrderedEnumerable<KeyValuePair<string, string>>>();
static void Main(string[] args)
{
Transliterate();
const string source = "<h2>{translate} Dear Atteck {/translate} <br/></h2>{translate}Please complete</h5> {/translate} ";
var splitData = Regex.Split(source, "{/");
string alldata = string.Empty;
foreach (var splt in splitData)
{
var data = splt.Split(new[] { "{translate}" }, StringSplitOptions.None);
if (data.Count() > 1)
{
data[0] = Regex.Replace(data[0], "[translate}]", string.Empty);
var result = TransliterationMaps["tatartocyrillic"].Aggregate(data[1], (current, map) => current.Replace(map.Key, map.Value));
alldata += data[0] + result;
}
}
Console.WriteLine(alldata);
}
Transliterate()
method
public static void Transliterate()
{
var tatarToCyrillicMap = new Dictionary<string, string>();
tatarToCyrillicMap.Add(('\u0079' + "" + '\u0075').ToString(CultureInfo.InvariantCulture), '\u044e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0059' + "" + '\u0075').ToString(CultureInfo.InvariantCulture), '\u042e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("YU", '\u042e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("yü", '\u044e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("Yü", '\u042e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("YÜ", '\u042e'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0079' + "" + '\u0061').ToString(CultureInfo.InvariantCulture), '\u044f'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("YA", '\u042f'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0059' + "" + '\u0061').ToString(CultureInfo.InvariantCulture), '\u042f'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add("YO", '\u0451'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0079' + "" + '\u006f').ToString(CultureInfo.InvariantCulture), '\u0451'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0059' + "" + '\u006f').ToString(CultureInfo.InvariantCulture), '\u0401'.ToString(CultureInfo.InvariantCulture));
tatarToCyrillicMap.Add(('\u0079' + "" + '\u00e4').ToString(CultureInfo.InvariantCulture), '\u044f'.ToString(CultureInfo.InvariantCulture));
.......................
...................
...............
.........
TransliterationMaps.Add("tatartocyrillic", tatarToCyrillicMap.OrderByDescending(m => m.Key));
}
Can this code be optimized?