forked from challenge-project/challenge-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.Script.txt
More file actions
100 lines (81 loc) · 2.51 KB
/
Copy pathDictionary.Script.txt
File metadata and controls
100 lines (81 loc) · 2.51 KB
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
/*
// Dictionary.Script.txt
// by BigBang1112
// part of Universe Library Set
// Manage list of terms for translation.
// This library does depend on more libraries from the Universe Library Set:
// - File.Script.txt
// You only need to use the libraries above, although it's recommended to use the whole set.
*/
/*
// Compatible contexts:
// - CManiaApp
// - CMode
// - CServerPlugin?
*/
/*
// Void SetTranslationFolder(Text _Folder)
// Text GetTranslationFolder()
// Text Get(Text _Definition, Text _Language)
// Void Set(Text _Definition, Text _Language, Text _Translation)
// Text TranslateAllPhrases(Text _Source)
*/
#Include "TextLib" as TextLib
#Include "Libs/BigBang1112/File.Script.txt" as File
declare Text[Text][Text] G_Dictionaries;
declare Text G_TranslationFolder;
declare Text G_Language;
Void SetTranslationFolder(Text _Folder) {
G_TranslationFolder = _Folder;
}
Text GetTranslationFolder() {
return G_TranslationFolder;
}
Void SetTranslationLanguage(Text _Language) {
G_Language = _Language;
}
Text GetTranslationLanguage() {
return G_Language;
}
Text Get(Text _Definition, Text _Language) {
if(!G_Dictionaries.existskey(_Language)) {
declare Content = File::Read(G_TranslationFolder^"/"^_Language^".json");
declare Text[Text] Phrases;
declare JsonSuccess = Phrases.fromjson(Content);
G_Dictionaries[_Language] = Phrases;
}
if(G_Dictionaries[_Language].existskey(_Definition)) {
return G_Dictionaries[_Language][_Definition];
}
if(!G_Dictionaries.existskey("en")) {
declare Content = File::Read(G_TranslationFolder^"/en.json");
declare Text[Text] Phrases;
declare JsonSuccess = Phrases.fromjson(Content);
G_Dictionaries["en"] = Phrases;
}
if(G_Dictionaries["en"].existskey(_Definition)) {
if(_Language == LocalUser.Language)
return TextLib::GetTranslatedText(G_Dictionaries["en"][_Definition]);
return G_Dictionaries["en"][_Definition];
}
return _Definition;
}
Text Get(Text _Definition) {
return Get(_Definition, G_Language);
}
Void Set(Text _Definition, Text _Language, Text _Translation) {
G_Dictionaries[_Language][_Definition] = _Translation;
}
Text TranslateAllPhrases(Text _Source, Text _Language) {
declare Txt = _Source;
declare Phrases = TextLib::RegexFind("\\{\\{\\{\\{(.*?)\\}\\}\\}\\}", Txt, "gi");
foreach(P,Phrases) {
declare Phrase = TextLib::SubText(P,4,TextLib::Length(P)-8);
Phrase = Get(Phrase, _Language);
Txt = TextLib::Replace(Txt, P, Phrase);
}
return Txt;
}
Text TranslateAllPhrases(Text _Source) {
return TranslateAllPhrases(_Source, G_Language);
}