CLanguage.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include<string>
  3. #include<Windows.h>
  4. #include "duilib.h"
  5. #pragma region 文件说明
  6. ///备注时间:2022/11/26
  7. /// 目前可采用两种方式对多语的逻辑进行处理:
  8. ///
  9. /// 方案1.加载多语言文件xml(未采用):
  10. /// 实现的思路:比如创建三个xml,内容分别是<Text id="okId" value ="OK"/>, <Text id="okId" value = "确认"/>,<Text okId="ok" value="確認"/>;
  11. /// 在xml界面文件里,可以使用如<Button Text="okId"/>即可动态加载对应的文案;
  12. /// 核心代码:(具体实现,可参考Duilib的Demo:duidemo)
  13. /// CResourceManager::GetInstance()->SetLanguage(_T("en"));
  14. /// CResourceManager::GetInstance()->LoadLanguage(_T("lan_en.xml"));
  15. /// CResourceManager::GetInstance()->ReloadText();
  16. /// InvalidateRect(m_hWnd, NULL, TRUE);
  17. /// m_pm.NeedUpdate();
  18. ///
  19. /// 方案2.创建多语类来处理文案(当前项目已采用):
  20. /// 理由:
  21. /// 1)考虑到下载安装器本身要求exe小,且需要的多语文案比较少,如果再添加多语文件资源,就会增加程序的大小。虽然多语文件不大,但应当尽量减少引用;
  22. /// 2)如果将来要实现频繁切换语言类型的逻辑,使用文件资源,就会增加潜在问题的风险;
  23. /// 3)多语xml文件需要跟界面文件同步id和文案,这会增加改动内容的复杂度;如果多个多语xml文件分别来写对应的文案,就会容易疏漏或填错内容;
  24. /// 建议采用方案1的情况:程序需要显示文案内容太多,比如内置用户协议内容;
  25. #pragma endregion
  26. ///如果有文案名称需要调整或有新文案时,此处必须要调整下对应的内容,以及函数GetContent(TextType textType)里的内容;
  27. #pragma region 添加编辑文案
  28. enum class TextType
  29. {
  30. NONE,
  31. //主页
  32. Btn_Install,
  33. Btn_CutomInstall,
  34. Link_Install,
  35. Txt_ByClickInstall,
  36. Btn_PrivacyPolicy,
  37. Txt_And,
  38. Btn_TermsService,
  39. Text_InstallPath,
  40. Btn_FilePath,
  41. //安装中
  42. Text_Installing,
  43. Text_NoNetwork,
  44. //安装完成
  45. Btn_OpenApp,
  46. Btn_GoToFilesPath,
  47. //提示弹窗
  48. MSG_IsExitApp,
  49. MSG_LatestVersion,
  50. MSG_UpgradeVersion,
  51. MSG_OverHighVersion,
  52. MSG_InstalledIsExitApp,
  53. MSG_DiskNoSpace,
  54. MSG_BtnCancel,
  55. MSG_BtnOK,
  56. MSG_BtnYes,
  57. MSG_BtnNo,
  58. MSG_BtnOpenInstallationFolder,
  59. MSG_ContentOpenInstallationFolder,
  60. MSG_ContentInstallFailed,
  61. MSG_BtnBackHomePage,
  62. MSG_BtnUseDefaultPath,
  63. MSG_InstalledNetReStartSystem,
  64. MSG_BtnRestartSystem
  65. };
  66. #pragma endregion
  67. enum class LanguageType
  68. {
  69. EN_US,//英语
  70. ZH_CN,//简中
  71. ZH_TW,//繁中
  72. Other,//其他语言
  73. NONE //未进行获取系统语言时,程序初始化前默认值
  74. };
  75. static class CLanguage
  76. {
  77. private:
  78. static LanguageType CurrentLanguage;
  79. static LanguageType LastLanguage;//上次选择的语言,或程序初始化时
  80. public:
  81. #pragma region UI文案字符类型转换
  82. static CDuiString GetDuiText(TextType textType);
  83. #pragma endregion
  84. /// <summary>
  85. /// //获取当前系统显示的语言种类
  86. /// </summary>
  87. static LanguageType GetLocalLanguage(bool isGetText = true);
  88. static std::wstring GetText(TextType textType);//获取文案
  89. private:
  90. static std::wstring GetContent(TextType textType);
  91. static std::wstring LoadLanguage(std::wstring EnStr, std::wstring zhsStr, std::wstring zhStr);
  92. };