PDA

View Full Version : How to tranlaste #define and text from file



stevocz
16th December 2013, 12:50
Hi,

i have in .h file this:

#define ITEM "textToTranslate"

how can i translate it?


and second, i have in file some text, which is loaded into QDraw. how can i transtale this text. text for translating is still same.

wysota
16th December 2013, 13:15
Hi,

i have in .h file this:

#define ITEM "textToTranslate"

how can i translate it?

You could try:

#define ITEM QT_TR_NOOP("textToTranslate")

and then tr(ITEM) but in general using such defines in C++ is not a very good approach.

Much cleaner solution is:


const char * const ITEM = QT_TR_NOOP("textToTranslate");


sth->setText(tr(ITEM));



and second, i have in file some text, which is loaded into QDraw.
What is QDraw?


how can i transtale this text. text for translating is still same.
You'd need to manually teach your message catalog about the string to be translated. It's better to avoid such solutions. What do you need it for?

A possible solution could be to reimplement QTranslator::translate().

stevocz
16th December 2013, 13:56
thank you for reply.

i am try
#define ITEM QT_TR_NOOP("textToTranslate")

and then tr(ITEM)

but doesnt work. textToTranslate missing in ts file.


What is QDraw?
sorry i mean in painter drawText

i have one application which create xml file and text. this text is for show in second application

wysota
16th December 2013, 14:39
thank you for reply.

i am try
#define ITEM QT_TR_NOOP("textToTranslate")

and then tr(ITEM)

but doesnt work. textToTranslate missing in ts file.
So use the other possibility I gave you.

stevocz
16th December 2013, 14:54
second possibility doesnt work too. after lupdate, textToTranslate missing in ts file.

wysota
16th December 2013, 14:56
second possibility doesnt work too.

Then it means you are doing something wrong, it should work just fine.

sulliwk06
16th December 2013, 17:02
maybe i'm missing something here, but isn't it SUPPOSED to not be able to translate "textToTranslate" ? Without spaces its not really a word.

stevocz
16th December 2013, 17:20
textToTranslat is only example. i have text with spaces and text with only one word.


something is wrong, but i don't know what, because i can't transtale this:

ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Ok"));
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
application after start crash

but other things work ok.

wysota
17th December 2013, 07:31
application after start crash
You probably get a null pointer from button().

stevocz
17th December 2013, 07:40
i am stupid :D i call Ok button but i have Save button.


but #define or const char * const ITEM still not work

wysota
17th December 2013, 07:50
but #define od const char * const ITEM still not work

Please post a minimal compilable example reproducing the problem. Make sure you have the file containing the QT_TR_NOOP macro explicitly added to your project file, otherwise lupdate won't scan it.

stevocz
17th December 2013, 09:34
I am edited one example


and QDialogButtonBox text is in .ts file but translate doesn' work. why?

wysota
17th December 2013, 12:10
The translation mark is outside a context. Either put it in a context or use QT_TRANSLATE_NOOP instead of QT_TR_NOOP passing a context to the call. Make sure the same context is used with the tr() call.

stevocz
17th December 2013, 12:34
can you fix it and send me back this application?

because i am try this:

const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("translateCategory", "Translate");

and "Translate" is in .ts file, but in application text isn't changed.

and please fix QDialogButtonBox

anda_skoa
17th December 2013, 12:48
maybe a stupid question, but why translate the QDialogButtonBox strings again?

Those strings from Qt should already be translate for Qt.
If they aren't, maybe the Qt translation catalogue wasn't loaded?
See http://qt-project.org/doc/qt-4.8/i18n-source-translation.html#enabling-translation

Cheers,
_

stevocz
17th December 2013, 13:10
when i am erased .ts file and create new, QT_TRANSLATE_NOOP works ok

this

const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("translateCategory", "translate");
ui.label_2->setText(QApplication::translate("translateCategory",TEXT_TO_TRANSLATE));

and this

const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("QObject", "translate");
ui.label_2->setText(QObject::tr(TEXT_TO_TRANSLATE));

booth work.



or best for this example

const char * const TEXT_TO_TRANSLATE = QT_TRANSLATE_NOOP("MainWindow", "translate");
ui.label_2->setText(tr(TEXT_TO_TRANSLATE));

work too.

wysota
17th December 2013, 13:11
and "Translate" is in .ts file, but in application text isn't changed.

Did you modify the respective tr() call to take data from the "translateCategory" context?

stevocz
17th December 2013, 13:16
yes, tr() is modified and works. now i must edit QDialogButtonBox.

wysota
17th December 2013, 14:56
yes, tr() is modified and works. now i must edit QDialogButtonBox.

No, you just have to load the bundled message catalog for it.

stevocz
17th December 2013, 18:57
but how? i am tried load QLibraryInfo but doesnt work

wysota
17th December 2013, 22:01
What does QLibraryInfo have to do with this??? You are supposed to install a translator on your application using Qt's message catalog that resides in the translations subdirectory of your Qt installation.

stevocz
18th December 2013, 06:57
and how do it?

wysota
18th December 2013, 06:58
The same as you do it with any other translator -- you load the message catalog and install the translator on the application.

stevocz
18th December 2013, 07:32
thank this works, but there are only few languages. how add my language?

wysota
18th December 2013, 08:06
TS files for Qt are available. You can provide your own translations using Linguist or search the web if an external catalog for your language is available.