之前博客讲过函数:
GetUserDefaultUILanguage
Returns the language identifier for the user UI language for the current user.
我们国际化主要是支持三种语言,简体中文、繁体中文、以及英文。
获得用户使用语言
所以我们可以通过GetUserDefaultUILanguage函数来判断用户使用的是何种语言:
int response_code = GetUserDefaultUILanguage();
switch (response_code)
{
case 2052:
//显示简体中文
break;
case 1028:
//显示繁体中文
break;
default:
//其他情况都使用英文
break;
}
创建相应的xml
前一篇关于windows客户端的博客也介绍了如何使用tinyxml来解析xml,也为我们的国际化做了铺垫。
所以,我们可以创建三个xml文件,分别是
simple_chinese.xml
traditional_chinese.xml
English.xml
这三个xml文件中,每个节点的key相同,value不同。
比如在simple_chinese.xml中这样写:
<?xml version="1.0" encoding="utf-8"?>
<Strings>
<!--close button tip-->
<String>
<StringKey>CloseTips</StringKey>
<StringValue>关闭</StringValue>
</String>
<Strings>
在traditional_chinese.xml中可以这么写:
<?xml version="1.0" encoding="utf-8"?>
<Strings>
<!--close button tip-->
<String>
<StringKey>CloseTips</StringKey>
<StringValue>關閉</StringValue>
</String>
<Strings>
而在English.xml中就可以这么写:
<?xml version="1.0" encoding="utf-8"?>
<Strings>
<!--close button tip-->
<String>
<StringKey>CloseTips</StringKey>
<StringValue>close</StringValue>
</String>
<Strings>
这样呢,就会根据用户使用的语言来读取相应的xml文件。可以把xml文件中的内容读取到map中,然后剩下的工作就是在程序代码中显示了。
原文:http://blog.csdn.net/wangshubo1989/article/details/50966203