- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageData.cs
More file actions
Latest commit
76 lines (68 loc) · 3.03 KB
/
Copy pathLanguageData.cs
File metadata and controls
76 lines (68 loc) · 3.03 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
usingSystem.Collections;
usingSystem.Collections.Generic;
usingUnityEngine;
usingSystem;
usingSystem.Text;
usingSystem.Xml;
usingSystem.IO;
namespaceLanguageModule{
/// <summary>
/// Cette classe permet de récupérer les strings du jeu dans la langue choisir par le joueur.
/// </summary>
publicclassLanguageData{
/// <summary>
/// Get a string from the resources folder
/// </summary>
/// <param name="language">Language you want thr string in</param>
/// <param name="stringShortCode">shortCode from the string (XML banner), must be the same
/// for every string that represent same thing in different languages</param>
/// <param name="fileName">Name of the file where is the stringShortCode banner</param>
publicstaticstringGetString(stringstringShortCode,stringlanguage,stringfileName="global"){
XmlDocumentxmlDoc=newXmlDocument();
try{
TextAssettextAsset;
textAsset=(TextAsset)Resources.Load("Languages/"+language+"/"+fileName,typeof(TextAsset));
if(textAsset==null){
// If file does not exist, we search it in English, in case it was not written for other languages.
textAsset=(TextAsset)Resources.Load("Languages/"+"English"+"/"+fileName,typeof(TextAsset));
}
xmlDoc.LoadXml(textAsset.text);
XmlNodeListtransformList=xmlDoc.GetElementsByTagName(stringShortCode)[0].ChildNodes;
stringtoReturn=xmlDoc.SelectSingleNode("transforms/"+stringShortCode).InnerText;
if(toReturn!=null){
returntoReturn;
}
else{
thrownewException("String not found");
}
}catch(NullReferenceExceptione){
thrownewException("FileNotFoundException : Your File "+fileName+".xml doesn't exist");
}
}
/// <summary>
/// Same method as <see cref="GetString(string, string, string)"</see> but the language used is the one
/// from PlayerPrefs. />
/// </summary>
/// <param name="stringShortCode"></param>
/// <param name="fileName"></param>
/// <returns></returns>
publicstaticstringGetString(stringstringShortCode,stringfileName){
stringlanguage=PlayerPrefs.GetString("Language");
returnGetString(stringShortCode,language,fileName);
}
/// <summary>
/// Change Language from the Player
/// </summary>
/// <param name="Language"></param>
publicstaticvoidSetLanguage(stringLanguage){
PlayerPrefs.SetString("Language",Language);
}
/// <summary>
/// Get Language from the Player
/// </summary>
/// <returns></returns>
publicstaticstringGetLanguage(){
returnPlayerPrefs.GetString("Language");
}
}
}