123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #pragma once
- #include<string>
- #include<Windows.h>
- #include "duilib.h"
- #pragma region 文件说明
- ///备注时间:2022/11/26
- /// 目前可采用两种方式对多语的逻辑进行处理:
- ///
- /// 方案1.加载多语言文件xml(未采用):
- /// 实现的思路:比如创建三个xml,内容分别是<Text id="okId" value ="OK"/>, <Text id="okId" value = "确认"/>,<Text okId="ok" value="確認"/>;
- /// 在xml界面文件里,可以使用如<Button Text="okId"/>即可动态加载对应的文案;
- /// 核心代码:(具体实现,可参考Duilib的Demo:duidemo)
- /// CResourceManager::GetInstance()->SetLanguage(_T("en"));
- /// CResourceManager::GetInstance()->LoadLanguage(_T("lan_en.xml"));
- /// CResourceManager::GetInstance()->ReloadText();
- /// InvalidateRect(m_hWnd, NULL, TRUE);
- /// m_pm.NeedUpdate();
- ///
- /// 方案2.创建多语类来处理文案(当前项目已采用):
- /// 理由:
- /// 1)考虑到下载安装器本身要求exe小,且需要的多语文案比较少,如果再添加多语文件资源,就会增加程序的大小。虽然多语文件不大,但应当尽量减少引用;
- /// 2)如果将来要实现频繁切换语言类型的逻辑,使用文件资源,就会增加潜在问题的风险;
- /// 3)多语xml文件需要跟界面文件同步id和文案,这会增加改动内容的复杂度;如果多个多语xml文件分别来写对应的文案,就会容易疏漏或填错内容;
- /// 建议采用方案1的情况:程序需要显示文案内容太多,比如内置用户协议内容;
- #pragma endregion
- ///如果有文案名称需要调整或有新文案时,此处必须要调整下对应的内容,以及函数GetContent(TextType textType)里的内容;
- #pragma region 添加编辑文案
- enum class TextType
- {
- NONE,
- //主页
- Btn_Install,
- Btn_CutomInstall,
- Link_Install,
- Txt_ByClickInstall,
- Btn_PrivacyPolicy,
- Txt_And,
- Btn_TermsService,
- Text_InstallPath,
- Btn_FilePath,
- //安装中
- Text_Installing,
- Text_NoNetwork,
- //安装完成
- Btn_OpenApp,
- Btn_GoToFilesPath,
- //提示弹窗
- MSG_IsExitApp,
- MSG_LatestVersion,
- MSG_UpgradeVersion,
- MSG_OverHighVersion,
- MSG_InstalledIsExitApp,
- MSG_DiskNoSpace,
- MSG_BtnCancel,
- MSG_BtnOK,
- MSG_BtnYes,
- MSG_BtnNo,
- MSG_BtnOpenInstallationFolder,
- MSG_ContentOpenInstallationFolder,
- MSG_ContentInstallFailed,
- MSG_BtnBackHomePage,
- MSG_BtnUseDefaultPath,
- MSG_InstalledNetReStartSystem,
- MSG_BtnRestartSystem
- };
- #pragma endregion
- enum class LanguageType
- {
- EN_US,//英语
- ZH_CN,//简中
- ZH_TW,//繁中
- Other,//其他语言
- NONE //未进行获取系统语言时,程序初始化前默认值
- };
- static class CLanguage
- {
- private:
- static LanguageType CurrentLanguage;
- static LanguageType LastLanguage;//上次选择的语言,或程序初始化时
- public:
- #pragma region UI文案字符类型转换
- static CDuiString GetDuiText(TextType textType);
- #pragma endregion
- /// <summary>
- /// //获取当前系统显示的语言种类
- /// </summary>
- static LanguageType GetLocalLanguage(bool isGetText = true);
- static std::wstring GetText(TextType textType);//获取文案
- private:
- static std::wstring GetContent(TextType textType);
- static std::wstring LoadLanguage(std::wstring EnStr, std::wstring zhsStr, std::wstring zhStr);
- };
|