Qt Linguist - set translator for application

断了今生、忘了曾经 提交于 2019-12-12 06:04:15

问题


how can i start creating a ts file that my application will use?

in the options of Linguist i can't create a new one with my own words and translation.... i can only translate a ts file that is allready exist.


回答1:


First, in your project, you need to write texts with tr() if you wanna translate them. For example

QPushButton button(tr("Button"));

In your pro file, add

TRANSLATIONS = chinese.ts\ italian.ts

These files will be created automatically later.

Second, go to Qt Command Prompt. Go to your project directory from command prompt. Then, write

lupdate yourprojectname.pro

and press enter key. It will automatically create "ts" files ("chinese.ts" and "italian.ts") for you.

After that, you need to open Qt Linguist and open your "ts" file. Add translation for your project. When you finish it, release it to get "qm" file.

When you want to translate your application, load the "qm" file.

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);

   QTranslator *translator = new QTranslator;
   translator->load("chinese.qm");

   a.installTranslator(translator);
}



回答2:


I think this can be done by the qt command line tool lupdate.

It will scan your code for strings you marked as translatable (tr() macro) and collect them in a *.ts file.

See the documentation for more information.



来源:https://stackoverflow.com/questions/6290122/qt-linguist-set-translator-for-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!