-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPersianTextSync.cs
117 lines (111 loc) · 3.01 KB
/
GPersianTextSync.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections.Generic;
namespace RMuseum.Services.Implementation.ImportedFromDesktopGanjoor
{
/// <summary>
/// Persian specific text utility class
/// </summary>
public class GPersianTextSync
{
/// <summary>
/// convert persian text to simple pinglish
/// </summary>
/// <param name="inputStr"></param>
/// <returns></returns>
public static string Farglisize(string inputStr)
{
string outStr = "";
string s;
foreach (char c in inputStr)
if (_PinglishDic.TryGetValue(c, out s))
outStr += s;
return outStr;
}
/// <summary>
/// equaivalnet for persian characters
/// </summary>
private static Dictionary<char, string> _PinglishDic = new Dictionary<char, string>()
{
{'ا', "a"},
{'آ', "a"},
{'ب', "b"},
{'پ', "p"},
{'ت', "t"},
{'ث', "s"},
{'ج', "j"},
{'چ', "ch"},
{'ح', "h"},
{'خ', "kh"},
{'د', "d"},
{'ذ', "z"},
{'ر', "r"},
{'ز', "z"},
{'ژ', "zh"},
{'س', "s"},
{'ش', "sh"},
{'ص', "s"},
{'ض', "z"},
{'ط', "t"},
{'ظ', "z"},
{'ع', "E"},
{'غ', "gh"},
{'ف', "f"},
{'ق', "gh"},
{'ک', "k"},
{'گ', "g"},
{'ل', "l"},
{'م', "m"},
{'ن', "n"},
{'ه', "h"},
{'و', "v"},
{'ی', "i"},
{'ئ', "E"},
{'أ', "A"},
{'إ', "E"},
{' ', "-"},
};
public static string UniquelyFarglisize(string inputStr)
{
string outStr = "";
string s;
foreach (char c in inputStr)
if (_UniqueAlphaNames.TryGetValue(c, out s))
outStr += s;
return outStr;
}
private static Dictionary<char, string> _UniqueAlphaNames = new Dictionary<char, string>()
{
{'ا', "a"},
{'آ', "a"},
{'ب', "b"},
{'پ', "p"},
{'ت', "t"},
{'ث', "th"},
{'ج', "j"},
{'چ', "ch"},
{'ح', "hh"},
{'خ', "kh"},
{'د', "d"},
{'ذ', "the"},
{'ر', "r"},
{'ز', "z"},
{'س', "si"},
{'ش', "sh"},
{'ط', "tt"},
{'ظ', "zz"},
{'ص', "ss"},
{'ض', "zzz"},
{'ع', "e"},
{'غ', "gh2"},
{'ف', "f"},
{'ق', "gh"},
{'ک', "k"},
{'گ', "g"},
{'ل', "l"},
{'م', "m"},
{'ن', "n"},
{'ه', "h"},
{'و', "v"},
{'ی', "y"},
};
}
}