forked from Ludeon/RimWorld-ru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LanguageWorker_Russian.cs
194 lines (181 loc) · 5 KB
/
LanguageWorker_Russian.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
namespace Verse
{
public class LanguageWorker_Russian : LanguageWorker
{
public override int TotalNumCaseCount => 3;
public override string ToTitleCase(string str)
{
return GenText.ToTitleCaseSmart(str);
}
public override string Pluralize(string str, Gender gender, int count = -1)
{
if (str.NullOrEmpty() || (count != -1 && count < 2))
{
return str;
}
if (!TryLookupPluralForm(str, gender, out var plural, count))
{
plural = PluralizeFallback(str, gender, count);
}
if (count == -1)
{
return plural;
}
if (TryLookUp("Case", str, 1, out var result) && TryLookUp("Case", plural, 1, out var result2))
{
return GetFormForNumber(count, str, result, result2);
}
return plural;
}
public override bool TryLookUp(string tableName, string key, int index, out string result, string fullStringForReference = null)
{
Dictionary<string, string[]> lookupTable = LanguageDatabase.activeLanguage.WordInfo.GetLookupTable(tableName);
if (lookupTable == null)
{
result = null;
return false;
}
key = key.ToLower().Trim();
if (key.NullOrEmpty())
{
if (DebugSettings.logTranslationLookupErrors)
Log.Warning($"Tried to lookup a bad key '{key}' in table '{tableName}'.");
result = key;
return true;
}
try
{
// For "mace of steel (norm)" this method checks values 'mace of steel (norm)', 'mace of steel', 'mace of', 'mace'.
// This is necessary to find a clean value in dictionary
int indexOfSpace = key.Length;
while (indexOfSpace > 0)
{
string keyHead = key.Substring(0, indexOfSpace);
string keyTail = key.Substring(indexOfSpace);
string[] tuple = lookupTable.TryGetValue(keyHead, fallback: null);
if (tuple != null)
{
if (index < 0 || tuple.Length <= index)
{
if (DebugSettings.logTranslationLookupErrors)
Log.Warning($"Tried a lookup an out-of-bounds index '{index}' for key '{key}' in table '{tableName}'.");
result = key;
return true;
}
result = tuple[index] + keyTail;
return true; // Success!
}
indexOfSpace = key.LastIndexOf(' ', indexOfSpace - 1);
}
if (DebugSettings.logTranslationLookupErrors)
Log.Warning($"Tried a lookup for key '{key}' in table '{tableName}', which doesn't exist.");
result = key;
return true;
}
catch (Exception ex)
{
Log.Error($"Exception while looking up in tableName: {tableName}, key: {key}, index: {index}, fullStringForReference: {fullStringForReference}: {ex.Message}");
result = key;
return true;
}
}
private string PluralizeFallback(string str, Gender gender, int count = -1)
{
char c = str[str.Length - 1];
char c2 = ((str.Length >= 2) ? str[str.Length - 2] : '\0');
switch (gender)
{
case Gender.None:
switch (c)
{
case 'o':
return str.Substring(0, str.Length - 1) + "a";
case 'O':
return str.Substring(0, str.Length - 1) + "A";
case 'E':
case 'e':
{
char value2 = char.ToUpper(c2);
if ("ГКХЖЧШЩЦ".IndexOf(value2) >= 0)
{
switch (c)
{
case 'e':
return str.Substring(0, str.Length - 1) + "a";
case 'E':
return str.Substring(0, str.Length - 1) + "A";
}
}
else
{
switch (c)
{
case 'e':
return str.Substring(0, str.Length - 1) + "я";
case 'E':
return str.Substring(0, str.Length - 1) + "Я";
}
}
break;
}
}
break;
case Gender.Female:
switch (c)
{
case 'я':
return str.Substring(0, str.Length - 1) + "и";
case 'ь':
return str.Substring(0, str.Length - 1) + "и";
case 'Я':
return str.Substring(0, str.Length - 1) + "И";
case 'Ь':
return str.Substring(0, str.Length - 1) + "И";
case 'A':
case 'a':
{
char value = char.ToUpper(c2);
if ("ГКХЖЧШЩ".IndexOf(value) >= 0)
{
if (c == 'a')
{
return str.Substring(0, str.Length - 1) + "и";
}
return str.Substring(0, str.Length - 1) + "И";
}
if (c == 'a')
{
return str.Substring(0, str.Length - 1) + "ы";
}
return str.Substring(0, str.Length - 1) + "Ы";
}
}
break;
case Gender.Male:
if (IsConsonant(c))
{
return str + "ы";
}
switch (c)
{
case 'й':
return str.Substring(0, str.Length - 1) + "и";
case 'ь':
return str.Substring(0, str.Length - 1) + "и";
case 'Й':
return str.Substring(0, str.Length - 1) + "И";
case 'Ь':
return str.Substring(0, str.Length - 1) + "И";
}
break;
}
return str;
}
private static bool IsConsonant(char ch)
{
return "бвгджзклмнпрстфхцчшщБВГДЖЗКЛМНПРСТФХЦЧШЩ".IndexOf(ch) >= 0;
}
}
}