CLanguage.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #include "Clanguage.h"
  2. #pragma region 添加文案
  3. std::wstring CLanguage::GetContent(TextType textType)
  4. {
  5. std::wstring content = L"";
  6. switch (textType)
  7. {
  8. case TextType::Btn_Install:
  9. content = LoadLanguage(L"Install", L"开始安装", L"開始安裝");
  10. break;
  11. case TextType::Btn_CutomInstall:
  12. content = LoadLanguage(L"Installation Settings", L"自定义安装", L"自定義安裝");
  13. break;
  14. case TextType::Link_Install:
  15. content = LoadLanguage
  16. (
  17. L"Clicking \"Install\" means you agree to the {a https://www.pdfreaderpro.com/terms_of_service}Terms of Service{/a} and the {a https://www.pdfreaderpro.com/privacy-policy}Privacy Policy{/a}.",
  18. L"点击“开始安装”代表你同意{a https://www.pdfreaderpro.com/terms_of_service}服务条款{/a}和{a https://www.pdfreaderpro.com/privacy-policy}隐私权政策{/a}",
  19. L"點擊「開始安裝」代表你同意{a https://www.pdfreaderpro.com/terms_of_service}服務條款{/a}和{a https://www.pdfreaderpro.com/privacy-policy}隱私權政策{/a}"
  20. );
  21. break;
  22. case TextType::Txt_ByClickInstall:
  23. content = LoadLanguage
  24. (
  25. L"Clicking \"Install\" means you agree to the ",
  26. L"点击“开始安装”代表你同意",
  27. L"點擊「開始安裝」代表你同意"
  28. );
  29. break;
  30. case TextType::Btn_TermsService:
  31. content = LoadLanguage
  32. (
  33. L"Terms of Service ",
  34. L"服务条款",
  35. L"服務條款"
  36. );
  37. break;
  38. case TextType::Txt_And:
  39. content = LoadLanguage
  40. (
  41. L"and the ",
  42. L"和",
  43. L"和"
  44. );
  45. break;
  46. case TextType::Btn_PrivacyPolicy:
  47. content = LoadLanguage
  48. (
  49. L"Privacy Policy",
  50. L"隐私权政策",
  51. L"隱私權政策"
  52. );
  53. break;
  54. case TextType::Text_InstallPath:
  55. content = LoadLanguage(L"Installation Folder", L"安装路径", L"安裝路徑");
  56. break;
  57. case TextType::Btn_FilePath:
  58. content = LoadLanguage(L"Select Folder", L"选择文件夹", L"選擇資料夾");
  59. break;
  60. case TextType::Text_Installing:
  61. content = LoadLanguage(L"Installing, please wait...", L"安装中,请稍等...", L"安裝中,請稍後...");
  62. break;
  63. case TextType::Text_NoNetwork:
  64. content = LoadLanguage
  65. (
  66. L"No internet connection, please check your internet and try again later.",
  67. L"无网络连接,请检查网络并重试。",
  68. L"無網路連接,請檢查網路並重試。"
  69. );
  70. break;
  71. case TextType::Btn_OpenApp:
  72. content = LoadLanguage(L"Start Now", L"立即启动", L"立即啟動");
  73. break;
  74. case TextType::Btn_GoToFilesPath:
  75. content = LoadLanguage(L"Offline installer is saved in:", L"安装文件储存路径:", L"安裝檔案存儲路徑:");
  76. break;
  77. case TextType::MSG_IsExitApp:
  78. content = LoadLanguage(L"Are you sure to cancel the process? If you exit now, the program won't be installed.",
  79. L"请确认是否退出程序安装。退出后,安装进程将停止。",
  80. L"請確認是否退出程序安裝。退出後,安裝進程將停止。");
  81. break;
  82. case TextType::MSG_LatestVersion:
  83. content = LoadLanguage(
  84. L"Latest version already installed, you don't need to install again.",
  85. L"PDF Reader Pro 已是目前最新版本,无需再次安装。",
  86. L"PDF Reader Pro 已是目前最新版本,無需再次安裝。");
  87. break;
  88. case TextType::MSG_UpgradeVersion:
  89. content = LoadLanguage(
  90. L"Current version is too old. Would you like to update PDF Reader Pro to the latest version?",
  91. L"当前版本较低,是否升级至最新版本?",
  92. L"當前版本較低,是否升級至最新版本?");
  93. break;
  94. case TextType::MSG_OverHighVersion:
  95. content = LoadLanguage(
  96. L"A newer version of PDF Reader Pro has already been installed, if you want to install this version, please uninstall the current version.",
  97. L"已安装了更高版本的PDF Reader Pro, 请卸载后再安装此版本。",
  98. L"已安裝更高版本的PDF Reader Pro,請擔載後再安裝此版本。");
  99. break;
  100. case TextType::MSG_InstalledIsExitApp:
  101. content = LoadLanguage(
  102. L"PDF Reader Pro has been successfully installed, are you sure to start later?",
  103. L"程序已安装,是否稍后启动?",
  104. L"程式已安裝,是否稍後啟動?");
  105. break;
  106. case TextType::MSG_DiskNoSpace:
  107. content = LoadLanguage(
  108. L"Available space is less than 1GB, please change installation folder.",
  109. L"当前磁盘剩余空间不足1G,请修改安装路径",
  110. L"當前磁碟可用空間不足1G,請變更安裝路徑。");
  111. break;
  112. case TextType::MSG_BtnCancel:
  113. content = LoadLanguage(L"Cancel", L"取消", L"取消");
  114. break;
  115. case TextType::MSG_BtnOK:
  116. content = LoadLanguage(L"OK", L"确定", L"確定");
  117. break;
  118. case TextType::MSG_BtnYes:
  119. content = LoadLanguage(L"Yes", L"是", L"是");
  120. break;
  121. case TextType::MSG_BtnNo:
  122. content = LoadLanguage(L"No", L"否", L"否");
  123. break;
  124. case TextType::NONE:
  125. content = LoadLanguage(L"", L"", L"");
  126. break;
  127. case TextType::MSG_BtnOpenInstallationFolder:
  128. content = LoadLanguage(L"Open Installation Folder", L"打开安装目录", L"打開安裝目錄");
  129. break;
  130. case TextType::MSG_ContentOpenInstallationFolder:
  131. content = LoadLanguage(L"Installation Failed\nPlease find the installation folder and run \"PDFReaderPro.exe\" installation package again.", L"安装失败,请找到\"PDFReaderPro.exe\"安装包,点击重新安装", L"安裝失敗,請找到“PDFReaderPro.exe”安裝包,點擊重新安裝。");
  132. break;
  133. case TextType::MSG_ContentInstallFailed:
  134. content = LoadLanguage(L"Installation Failed\nDestination path too long, please try a location that has shorten path ", L"安装失败\n安装路径过长,请重新选择安装路径", L"安裝失敗\n安裝路徑過長,請重新選擇安裝路徑");
  135. break;
  136. case TextType::MSG_BtnBackHomePage:
  137. content = LoadLanguage(L"OK", L"返回", L"返回");
  138. break;
  139. case TextType::MSG_BtnUseDefaultPath:
  140. content = LoadLanguage(L"Use Default Path", L"使用默认安装路径", L"使用默認安裝路徑");
  141. break;
  142. case TextType::MSG_InstalledNetReStartSystem:
  143. content = LoadLanguage(L"Because the NetFramework was installed together with the software, you need to restart system to run PDF Reader Pro.", L"因安装软件的同时,也安装了NetFramework,当前设备需要重启系统,才能运行PDF Reader Pro", L"因安裝軟件的同時,也安裝了NetFramework,當前設備需要重啓系統,才能運行PDF Reader Pro.");
  144. break;
  145. case TextType::MSG_BtnRestartSystem:
  146. content = LoadLanguage(L"Restart", L"重新启动", L"重新啓動");
  147. break;
  148. default:
  149. break;
  150. }
  151. return content;
  152. }
  153. #pragma endregion
  154. #pragma region 多语言逻辑
  155. LanguageType CLanguage::CurrentLanguage = LanguageType::NONE;
  156. LanguageType CLanguage::LastLanguage = LanguageType::NONE;
  157. std::wstring CLanguage::GetText(TextType textType)
  158. {
  159. CurrentLanguage = GetLocalLanguage();
  160. return GetContent(textType);
  161. }
  162. std::wstring CLanguage::LoadLanguage(std::wstring EnStr, std::wstring zhsStr, std::wstring zhStr)
  163. {
  164. std::wstring content = L"";
  165. switch (CLanguage::CurrentLanguage)
  166. {
  167. case LanguageType::EN_US:
  168. content = EnStr;
  169. break;
  170. case LanguageType::ZH_CN:
  171. content = zhsStr;
  172. break;
  173. case LanguageType::ZH_TW:
  174. content = zhStr;
  175. break;
  176. default:
  177. content = EnStr;
  178. break;
  179. }
  180. return content;
  181. }
  182. LanguageType CLanguage::GetLocalLanguage(bool isGetText)
  183. {
  184. LanguageType language = LanguageType::EN_US;
  185. //加载文案时,不必要重新获取当前系统的语言种类
  186. if (isGetText)
  187. {
  188. if (CurrentLanguage != LanguageType::NONE && CurrentLanguage == LastLanguage)
  189. return CurrentLanguage;
  190. }
  191. LastLanguage = CurrentLanguage;
  192. // LCID lcid = GetSystemDefaultLCID();//系统语言(包括系统所有界面显示语言)
  193. LANGID lcid = ::GetUserDefaultUILanguage();//当前windows应用显示语言
  194. if (lcid == 0x409)
  195. {
  196. language = LanguageType::EN_US;
  197. }
  198. else if (lcid == 0x404)
  199. {
  200. language = LanguageType::ZH_TW;
  201. }
  202. else if (lcid == 0x804)
  203. {
  204. language = LanguageType::ZH_CN;
  205. }
  206. return language;
  207. }
  208. #pragma endregion
  209. #pragma region UI文案字符类型转换
  210. CDuiString CLanguage::GetDuiText(TextType textType)
  211. {
  212. CDuiString duiStr(CLanguage::GetText(textType).c_str());
  213. return duiStr;
  214. }
  215. #pragma endregion