-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathLocalization.cs
More file actions
57 lines (51 loc) · 1.51 KB
/
Localization.cs
File metadata and controls
57 lines (51 loc) · 1.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
//-----------------------------------------------------------------------------
// Localization Singleton that stores a Dictionary of all the UI strings
// that are visible in the game.
// Right now there's only an en_us.xml file, but you could easily perform
// translations with this system.
//
// __Defense Sample for Game Programming Algorithms and Techniques
// Copyright (C) Sanjay Madhav. All rights reserved.
//
// Released under the Microsoft Permissive License.
// See LICENSE.txt for full details.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace defense
{
public class Localization : Patterns.Singleton<Localization>
{
Dictionary<string, string> m_Translations = new Dictionary<string, string>();
public Localization()
{
}
public void Start(string sLocFilename)
{
m_Translations.Clear();
using (XmlTextReader reader = new XmlTextReader(sLocFilename))
{
while (reader.Read())
{
if (reader.Name == "text" && reader.NodeType == XmlNodeType.Element)
{
reader.MoveToAttribute("id");
string key = reader.Value;
reader.MoveToElement();
// Grab everything from this element INCLUDING any other markup
// so it can be parsed later on
string value = reader.ReadInnerXml();
m_Translations.Add(key, value);
}
}
}
}
public string Text(string Key)
{
return m_Translations[Key];
}
}
}