Qt 翻译来自非源文件的字符串 [英] Qt translate strings from non-source files

查看:37
本文介绍了Qt 翻译来自非源文件的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 XML 文件的 Qt 项目.这些 XML 文件包含人类可读的文本,应使用 Qt 工具(lupdate、lrelease、QtLinguist)翻译这些文本.

I have a Qt project which uses XML files. Those XML files contain human-readable text and this text should be translated by using the Qt tools (lupdate, lrelease, QtLinguist).

问题是是否可以通过 lupdate 在 .ts 文件中生成条目,而无需使用 QT_TR_NOOP() 宏和朋友从源代码文件中的 XML 文件中复制字符串?或者一般来说,你如何为 Qt 项目翻译非源文件中的字符串?

The question is if it is possible to generate entries in .ts file via lupdate without duplicating the strings from the XML files in a source code file by using the QT_TR_NOOP() macro and friends? Or in general, how do you translate strings in non-source files for Qt projects?

推荐答案

我们遇到了同样的问题:包含人类可读字符串的 XML 文件.

We had the same problem : XML files containing human readable strings.

我们的解决方案是确保 XML 文件中人类可读的字符串易于提取(我们将它们放在 LABEL 属性中),并且我们开发了一个小工具来解析 XML 文件,提取字符串,生成上下文(通过从 XML 文件中提取数据),然后生成包含 QT_TR_NOOP() 列表的 CPP 头文件.

Our solution was to make sure that human readable strings in the XML files were easy to extract (we put them in a LABEL attribute) and we developped a small tool which would parse the XML files, extract the strings, generate a context (by extracting data from the XML file), and then generating a CPP header file containing a list of QT_TR_NOOP().

此文件已添加到 lupdate 使用的项目文件 (.pro) 中.

This file was added to our project file (.pro) that was used by lupdate.

这个解决方案对我们来说很好,但我们必须非常小心两件事:

This solution was fine for us but we had to be very careful about two things :

  • 每次 XML 文件的内容更改时都运行此工具.
  • 确保 XML 文件采用 UTF-8 编码.

这篇关于Qt 翻译来自非源文件的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆