Game Development Reference
In-Depth Information
77 {
78 //id matches, now set value
79 field.SetValue(GM, LocalText);
80 }
81 }
82 }
83 }
84 }
85 }
86 }
87 }
88 //-------------------------------------------
The following are the comments for code sample 8-13:
Lines 02-07 : Remember to include wide range of namespaces as shown here.
Our code will rely on them all to some degree.
Lines 11-23 : For this sample application, the three languages: English ,
French , and Yoda are selectable from the application menu. For your own
projects, your language list may be different. But crucially, based on the
localization system given here, integration of additional languages, even
at a much later time, is easy.
Line 32 : The Resources.Load function is called here to open the XML text
file from the Resources folder in the project that extracts its text contents into
one single concatenated string variable.
Lines 35-36 : The XML string is loaded into an XmlDocument object, which is a
Mono class encapsulating a complete XML file, either on disk or in memory.
The class also validates the document on loading, which means an exception
will be generated here if the file contains syntax errors.
Line 53 : Once a language is selected from the XML file, all child nodes of the
language (each node a unique string) are cycled to find a matching ID.
Line 61 : For each string entry, all public string members for the text class are
searched for an appropriate LocalizationTextAttribute and when found,
the string ID is compared to check for a match. When a match is found, the
string variable is assigned the corresponding localized string.
 
Search WWH ::




Custom Search