zoukankan      html  css  js  c++  java
  • Qt 翻译系统自带与自己自定义的字符串

    <section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: black; padding: 0 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;"><h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px;"><span class="prefix" style="display: none;"></span><span class="content">Qt 翻译的条件</span><span class="suffix"></span></h2>
    <ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;">
    <li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">QTranslator类就是使用Qt的翻译文件,可以对界面中菜单栏、label、对话框等进行翻译。使用的前提是,开发者要自己创建翻译文 。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">确保每一个用户可见的字符串都使用了tr()函数。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">确保工程目录下的 Lang/ 文件有 .qm 文件,.qm 文件是一个二进制文件,是由 .ts 文件生成,而 .ts 文件是一个可编辑的 XML 文件。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">翻译文件在程序加载的位置必须在界面实例化之前完成。</section></li></ul>
    <h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content">具体实现的代码</span><span class="suffix" style="display: none;"></span></h3>
    <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://files.mdnice.com/point.png); height: 30px;  100%; background-size: 40px; background-repeat: no-repeat; background-color: #282c34; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;">&nbsp;QTranslator&nbsp;qtsetbaseTranslator;//翻译自己定义的字符串<br>&nbsp;QTranslator&nbsp;qtranslator;//翻译系统的文件<br>&nbsp;<span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">if</span>(EDVersion::LangID()==&nbsp;EDVersion::&nbsp;LangCHN)//判断语言<br>&nbsp;&nbsp;&nbsp;&nbsp;qtsetbaseTranslator.load(path&nbsp;+&nbsp;<span class="hljs-string" style="color: #98c379; line-height: 26px;">"qt_zh_ch"</span>);//path&nbsp;是.qm&nbsp;的保存路径<br>QString&nbsp;langPath&nbsp;=&nbsp;path&nbsp;+&nbsp;<span class="hljs-string" style="color: #98c379; line-height: 26px;">"lang/"</span>&nbsp;+&nbsp;EDVersion::langBrev()&nbsp;+&nbsp;<span class="hljs-string" style="color: #98c379; line-height: 26px;">".qm"</span>;<br>qtranslator.load(langPath)//翻译系统的语言的文件。<br></code></pre>
    <h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content">要注意的坑</span><span class="suffix" style="display: none;"></span></h3>
    <ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;">
    <li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">必须要使用 QTranslator 对象分别去加载 .qm 文件。一个是自己的所写的字符串,经Qt - Linguist 编辑发布的 .qm 文件。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">系统的翻译 .qm 文件要去 Qt 安装目录下的 Lang/ 找到相应的文件复制至本工程的 Lang/目录下。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">如果 .qm 文件都存在,切有不能翻译的字符串,则需要检查加载路径是否一致字符串是否全部加 tr函数。</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">使用的 Qt- Linguist 的版本要跟 Qt 的编译环境一致,例如 Qt 的编译环境是MSvc 32 bit 则 Qt-Linguist 也需要 MSvc - 32 bit 的,不然有时会导致翻译不出来。</section></li></ul>
    </section>
    
  • 相关阅读:
    基于范围的for循环
    ML.NET技术研究系列-2聚类算法KMeans
    SQLServer常用运维SQL整理
    ML.NET技术研究系列-1入门篇
    Kafka基本知识整理
    .NetCore技术研究-EntityFramework Core 3.0 Preview
    容器技术研究-Kubernetes基本概念
    特来电混沌工程实践-混沌事件注入
    .Net Core技术研究-Span<T>和ValueTuple<T>
    Visual Studio Git本地Repos和GitHub远程Repos互操作
  • 原文地址:https://www.cnblogs.com/wickhamchen/p/14394873.html
Copyright © 2011-2022 走看看