之前博客讲过函数:
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
前一篇关于windowsclient的博客也介绍了怎样使用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中,然后剩下的工作就是在程序代码中显示了。