-
Notifications
You must be signed in to change notification settings - Fork 3
/
Language Worker.txt
82 lines (72 loc) · 2.23 KB
/
Language Worker.txt
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
public class LanguageWorker_Catalan : LanguageWorker
{
public override string WithIndefiniteArticle(string str, Gender gender, bool plural = false, bool name = false)
{
if( str.NullOrEmpty() )
return str;
if( name )
return WithElLaArticle(str, gender, true);
else if( plural )
return (gender == Gender.Female ? "unes " : "uns ") + str;
else
return (gender == Gender.Female ? "una " : "un ") + str;
}
public override string WithDefiniteArticle(string str, Gender gender, bool plural = false, bool name = false)
{
if( str.NullOrEmpty() )
return str;
if( name )
return WithElLaArticle(str, gender, true);
else if( plural )
return (gender == Gender.Female ? "les " : "els ") + str;
else
return WithElLaArticle(str, gender, false);
}
private string WithElLaArticle(string str, Gender gender, bool name)
{
if( str.Length != 0 && (IsVowel(str[0]) || str[0] == ’h’ || str[0] == ’H’) )
{
if( name && gender == Gender.Male)
return "n’" + str;
else
return "l’" + str;
}
else
return (gender == Gender.Female ? "la " : "el ") + str;
}
public override string OrdinalNumber(int number, Gender gender = Gender.None)
{
if( gender == Gender.Female )
return number + "a";
switch ( number )
{
case 1: return number + "r"; // Primer
case 2: return number + "n"; // Segon
case 3: return number + "r"; // Tercer
case 4: return number + "t"; // Quart
default: return number + "è"; // Cinquè i posteriors
}
}
public bool IsVowel(char ch)
{
return "aeiouAEIOUàèéíòóúÀÈÉÍÒÓÚïüÏÜ".IndexOf(ch) >= 0;
}
public override string PostProcessed(string str)
{
return PostProcessedInt(base.PostProcessed(str));
}
public override string PostProcessedKeyedTranslation(string translation)
{
return PostProcessedInt(base.PostProcessedKeyedTranslation(translation));
}
private string PostProcessedInt(string str)
{
return str.Replace(" de el ", " del ")
.Replace(" de els ", " dels ")
.Replace(" a el ", " al ")
.Replace(" a els ", " als ")
.Replace(" per el ", " pels ")
.Replace(" per els ", " pels ");
//.Replace("’", "’"); This would be great, but nicknames use ’this approach’.
}
}