首页 > REDM基础教程 > REDM基础教程17-多国语言配置
2016十二月2

REDM基础教程17-多国语言配置

[隐藏]

 MyTest下载–>

MyTest.zip

  修改后的MyTest下载–>  

  

MyTest.zip

  

这一节我们来为QQ登陆弹框增加多语言切换,首先,我们来看一下DM的语言包xml构成:

<!--没有特定配置,全从custom中读取翻译-->
<dmlg name="lg_en"><!--给一个唯一标识-->
	<node name="custom"><!--通用标识custom,当特定note无法找到时,会转向custom这个node中查找-->
		<item src="QQ号码/手机/邮箱"  trans="QQ num/phone/mbox"/>
		<item src="密码"  trans="psword"/>
		<item src="记住密码"  trans="remb psword"/>
		<item src="自动登陆"  trans="auto load"/>
		<item src="注册帐号"  trans="reg account"/>
		<item src="找回密码"  trans="find psword"/>
		
		<item src="官方支持(禁用态)"  trans="Official support (disabled)"/>
		<item src="多语言切换"  trans="Multi-language switching"/>
		<item src="自定高度"  trans="Custom height"/>
		<item src="退出"  trans="Exit"/>
		
		<item src="英语"  trans="English"/>
		<item src="俄语"  trans="Russian"/>
		<item src="中文"  trans="Chinese"/>
	</node>
</dmlg>

1.以<dmlg>为根结点  

2.每个<item>对应一项翻译,src表示初始配置的text,trans表示翻译后的text

3.支持多个node,在<DM>表示的窗口xml或<MENU>表示的菜单xml中有个transid="xx"来关联特定的node,可参看QQRes的dui_exitmenu.xml

查找顺序为:如果未设置transid,DM会直接在name="custom"的node中遍历查找(遍历item,找到src匹配的,返回trans)

如果设置了transid,DM会先在name为transid的node中先遍历查找,如果找不到,再去name="custom"的node中遍历查找

  

这样做的目的是解决有些text在特定的窗口有特定的翻译,如果没有这种需求,一个custom的node就可以了

  

1.加载语言包XML

  

内置的加载语言包文件有两种方式,一种是通过xml的id直接从MyRes资源包中取得,另一种是直接传入语言包文件全路径

第一种已介绍多次了,比如:

1.把dmlg_en.xml放在\MyRes\layout\language\文件夹下

2.\MyRes\layout\dmindexm.xml中增加en这个id(DM通过en来找到path,最终找到dmlg_en.xml的全路径)

<?xml version="1.0"?>
<resource>
	<global>
		<file name="global" path="layout\xml\global.xml" />
	</global>
	<layout>
		<file name="main" path="layout\xml\main.xml" />
		<file name="exitmenu" path="layout\xml\dui_exitmenu.xml" />
		
		<!--语言包-->
		<file name="en" path="layout\language\dmlg_en.xml" />
	</layout>
</resource>

或者你可以通过设计器加载进去,前面已多次介绍了方式,这里不再演示

在Test.cpp中增加语言包:

theApp.LoadTrans((WPARAM)L"en");

  

另一种方式,比如:

1.把dmlg_rn.xml放在\MyRes\目录下(你也可以放在D盘,E盘,这里只是为了查找方便)

2.加载语言包

wchar_t szLangPath[MAX_PATH] = {0};
GetRootFullPath(L".\\MyRes\\dmlg_rn.xml",szLangPath,MAX_PATH);// 得到语言包全路径
theApp.LoadTrans((WPARAM)szLangPath,1);// 传1表示使用语言包全路径解析

  

dmlg_en.xml的实际内容:(点击展开)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--没有特定配置,全从custom中读取翻译-->
<dmlg name="lg_en"><!--给一个唯一标识-->
	<node name="custom"><!--通用标识custom,当特定note无法找到时,会转向custom这个node中查找-->
		<item src="QQ号码/手机/邮箱"  trans="QQ num/phone/mbox"/>
		<item src="密码"  trans="psword"/>
		<item src="记住密码"  trans="remb psword"/>
		<item src="自动登陆"  trans="auto load"/>
		<item src="注册帐号"  trans="reg account"/>
		<item src="找回密码"  trans="find psword"/>
 
		<item src="官方支持(禁用态)"  trans="Official support (disabled)"/>
		<item src="多语言切换"  trans="Multi-language switching"/>
		<item src="自定高度"  trans="Custom height"/>
		<item src="退出"  trans="Exit"/>
 
		<item src="英语"  trans="English"/>
		<item src="俄语"  trans="Russian"/>
		<item src="中文"  trans="Chinese"/>
	</node>
</dmlg>

dmlg_rn.xml的实际内容:(点击展开)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--没有特定配置,全从custom中读取翻译-->
<dmlg name="lg_rn"><!--给一个唯一标识-->
	<node name="custom"><!--通用标识custom,当特定note无法找到时,会转向custom这个node中查找-->
		<item src="QQ号码/手机/邮箱"  trans="QQ номер/телефон/почта"/>
		<item src="密码"  trans="пароль"/>
		<item src="记住密码"  trans="Запомнить пароль"/>
		<item src="自动登陆"  trans="автоматическая посадка"/>
		<item src="注册帐号"  trans="Регистрация аккаунта"/>
		<item src="找回密码"  trans="Забыл пароль"/>
 
		<item src="官方支持(禁用态)"  trans="Официальная поддержка (неактивное состояние)"/>
		<item src="多语言切换"  trans="Многоязычная переключатель"/>
		<item src="自定高度"  trans="Нестандартная высота"/>
		<item src="退出"  trans="выход"/>
 
		<item src="英语"  trans="английский"/>
		<item src="俄语"  trans="русский"/>
		<item src="中文"  trans="китайский"/>
	</node>
</dmlg>

 

注意,要切换语言,设置的是<dmlg>的name属性,注意SetTrans函数设置lg_en和lg_rn,不是文件名,也不是xml的标识id

  

2.切换语言设置

  

在MyTest\Test\inc\MainWnd.h增加

/// <summary>
///		和dui_exitmenu.xml配置的id相同
/// </summary>
enum QQMenuId
{
	QQMENU_LANG_EN = 100,// 
	QQMENU_LANG_RN = 101,
	QQMENU_LANG_CH = 102,
	QQMENU_EXIT    = 200,
};

 

在MyTest\Test\src\MainWnd.cpp中增加

void CMainWnd::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
{
	switch (nID)
	{
	case QQMENU_EXIT:// dui_exitmenu.xml配置的
		{
			OnClose();
		}
		break;

	case QQMENU_LANG_EN:
		{
			g_pDMApp->SetTrans(L"lg_en");// 注意,是<dmlg> 的name属性名
			g_pDMApp->RedrawAll();
		}
		break;

	case QQMENU_LANG_RN:
		{
			g_pDMApp->SetTrans(L"lg_rn");
			g_pDMApp->RedrawAll();
		}
		break;

	case QQMENU_LANG_CH:
		{
			g_pDMApp->SetTrans(L""); // 为L""表示使用原始的语言
			g_pDMApp->RedrawAll();
		}
		break;

	default:
		break;
	}
}

   

效果如下:

28.gif  

 

    下一节教程:REDM设计器教程12-增加主题包

    

  

文章作者:hgy413
本文地址:http://hgy413.com/3891.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

16 Responses to “REDM基础教程17-多国语言配置”

  1. #1 minecraft 回复 | 引用 Post:2018-10-04 20:29

    Hello to every body, it’s my first visit of
    this web site; this webpage carries amazing and really fine stuff in favor of readers.

  2. #2 minecraft 回复 | 引用 Post:2018-10-06 20:01

    Hi there! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing
    several weeks of hard work due to no backup. Do you have any solutions to prevent hackers?

  3. I was suggested this web site by my cousin. I’m not sure whether this post is written by him as no one else know such
    detailed about my trouble. You’re amazing! Thanks!

  4. I’m no longer sure the place you are getting your information, however great topic.
    I must spend some time finding out much more or working out more.
    Thanks for fantastic information I used to be searching for this
    info for my mission.

  5. #5 Coconut Oil Benefits 回复 | 引用 Post:2018-10-24 00:42

    I blog quite often and I seriously thank you for your content.
    This article has truly peaked my interest.
    I will bookmark your website and keep checking for new information about once per week.
    I subscribed to your Feed too.

  6. Good day! I could have sworn I’ve been to this website before but after checking
    through some of the post I realized it’s new to me. Anyhow, I’m definitely happy I found
    it and I’ll be book-marking and checking back often!

  7. #7 quest bars cheap 回复 | 引用 Post:2018-11-03 08:17

    It’s amazing in support of me to have a web page, which is good for my experience.
    thanks admin

  8. #8 quest bars cheap 回复 | 引用 Post:2018-11-03 21:32

    An outstanding share! I’ve just forwarded this onto
    a coworker who was conducting a little research on this.
    And he in fact bought me breakfast because I discovered it for him…
    lol. So allow me to reword this…. Thanks for the meal!!
    But yeah, thanks for spending the time to discuss this issue here on your website.

  9. #9 Quest Protein Bars 回复 | 引用 Post:2018-11-06 09:39

    Everyone loves what you guys tend to be up too.
    This type of clever work and exposure! Keep up the wonderful works guys I’ve included you guys to blogroll.

  10. #10 quest bars 回复 | 引用 Post:2018-11-06 10:35

    Fine way of telling, and fastidious article to get information about my presentation subject, which
    i am going to present in school.

  11. Helpful information. Lucky me I discovered your
    website unintentionally, and I am shocked why this
    coincidence didn’t took place in advance! I bookmarked it.

  12. #12 Sling TV 回复 | 引用 Post:2018-11-14 20:29

    Hi there are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set
    up my own. Do you require any html coding expertise to make your own blog?

    Any help would be greatly appreciated!

  13. #13 Sling TV 回复 | 引用 Post:2018-11-14 23:32

    Hi there, i read your blog from time to time and i own a similar one and i
    was just curious if you get a lot of spam responses?
    If so how do you prevent it, any plugin or anything you can suggest?
    I get so much lately it’s driving me crazy so any assistance is very much
    appreciated.

  14. I’m amazed, I have to admit. Rarely do I come across a blog that’s both equally educative and amusing,
    and without a doubt, you have hit the nail on the head.

    The issue is something which not enough people are speaking intelligently about.
    I am very happy that I found this during my search for something concerning this.

  15. We are a group of volunteers and starting a new scheme in our community.

    Your website provided us with valuable information to work on.
    You’ve done an impressive job and our whole community will be grateful to you.

  16. Thanks for sharing your thoughts on What Equipment is
    Needed for Sling TV. Regards

发表评论