Discussion:
[Interest] tr() a string while ignoring context?
Vadim Peretokin
2018-11-09 16:12:30 UTC
Permalink
I'd like to translate a string while ignoring the context of it, but
QCoreApplication::translate("", sourceText.toUtf8().constData()) isn't
cutting it. Any ideas on what would work?
Andy
2018-11-09 16:51:53 UTC
Permalink
Aside from QObject::tr() which works without a context string, I think
QT_TR_NOOP() is the only other one without a context.


https://doc.qt.io/qt-5/i18n-source-translation.html#using-qt-tr-noop-and-qt-translate-noop-in-c

Note that QObject::tr can be used outside the class. See
some_global_function example here:


https://doc.qt.io/qt-5/i18n-source-translation.html#using-qcoreapplication-translate

Also of interest might be "Translating Non-Qt Classes":


https://doc.qt.io/qt-5/i18n-source-translation.html#translating-non-qt-classes

---
Andy Maloney // https://asmaloney.com
Post by Vadim Peretokin
I'd like to translate a string while ignoring the context of it, but
QCoreApplication::translate("", sourceText.toUtf8().constData()) isn't
cutting it. Any ideas on what would work?
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Vadim Peretokin
2018-11-09 17:47:18 UTC
Permalink
I tried QObject::tr but I'm still having difficulty. I'd like to translate
dynamic input that's not known as compile-time.

Basically, I'd like to expose the wealth of translations already available
for my application to my scripting layer, and as you can see that means the
context needs to be stripped out - so given any input string, return the
first known translation, irregardless of the context. Is this feasible and
am I just misunderstanding you?

- Vadim
Post by Andy
Aside from QObject::tr() which works without a context string, I think
QT_TR_NOOP() is the only other one without a context.
https://doc.qt.io/qt-5/i18n-source-translation.html#using-qt-tr-noop-and-qt-translate-noop-in-c
Note that QObject::tr can be used outside the class. See
https://doc.qt.io/qt-5/i18n-source-translation.html#using-qcoreapplication-translate
https://doc.qt.io/qt-5/i18n-source-translation.html#translating-non-qt-classes
---
Andy Maloney // https://asmaloney.com
Post by Vadim Peretokin
I'd like to translate a string while ignoring the context of it, but
QCoreApplication::translate("", sourceText.toUtf8().constData()) isn't
cutting it. Any ideas on what would work?
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
René Hansen
2018-11-09 17:56:55 UTC
Permalink
QT_TR_NOOP() and QT_TRANSLATE_NOOP() is what you're looking for.

/René
Post by Vadim Peretokin
I tried QObject::tr but I'm still having difficulty. I'd like to translate
dynamic input that's not known as compile-time.
Basically, I'd like to expose the wealth of translations already available
for my application to my scripting layer, and as you can see that means the
context needs to be stripped out - so given any input string, return the
first known translation, irregardless of the context. Is this feasible and
am I just misunderstanding you?
- Vadim
Post by Andy
Aside from QObject::tr() which works without a context string, I think
QT_TR_NOOP() is the only other one without a context.
https://doc.qt.io/qt-5/i18n-source-translation.html#using-qt-tr-noop-and-qt-translate-noop-in-c
Note that QObject::tr can be used outside the class. See
https://doc.qt.io/qt-5/i18n-source-translation.html#using-qcoreapplication-translate
https://doc.qt.io/qt-5/i18n-source-translation.html#translating-non-qt-classes
---
Andy Maloney // https://asmaloney.com
Post by Vadim Peretokin
I'd like to translate a string while ignoring the context of it, but
QCoreApplication::translate("", sourceText.toUtf8().constData()) isn't
cutting it. Any ideas on what would work?
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Thiago Macieira
2018-11-09 20:20:29 UTC
Permalink
Post by Vadim Peretokin
I tried QObject::tr but I'm still having difficulty. I'd like to translate
dynamic input that's not known as compile-time.
You can only translate content known at compile time.

Any dynamism is basically matching the runtime string to one of the static
strings and then applying the translation of that static strings.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Loading...