How to load translation for static library widget
-
@kshegunov said:
And as a second suggestion: I think you should create another
QTranslator
object for the second translation file.Thanks. This fixed
Tester
app. problem but it didn't fix the main problem (loading translation from static library) I still get this error message:Failed to load translation from static library
-
Can I ask some silly maybe ?
The list shows
:/i18n/tester_ar.qmThere is no "arabic" under languages
there is
":/languages/i18n/WidgetKeyboard_ar.qm" -
@kshegunov said:
And have you tried the loading like this
translator->load("arabic", ":/languages");
, since you didn't comment on that?I tried to use
translator->load(":/languages/i18n/WidgetKeyboard_ar")
instead. The error message disappeared ("Failed to load translation from static library") but the widget comes from the static library still appears in English! -
Silly question number 2.
The test calls ui->retranslateUi(this);
void Tester::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
} else
QWidget::changeEvent(event);
}
But tester ui->retranslate() knows about the widgets from the library ?
retranslateUi() just call all ->setText for elements inserted on the UI.
How can it know about widgets in the Lib?
Who calls widget_in_lib->setText? -
@mrjj said:
But tester ui->retranslate() knows about the widgets from the library ?
retranslateUi() just call all ->setText for elements inserted on the UI.
How can it know about widgets in the Lib?
Who calls widget_in_lib->setText?Fair point. But as you can see from the code the widget in static library built manually not by using Qt Designer so
retranslate
doesn't exist and I don't know how to create an alternative to it :( -
@mbnoimi
well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
void WidgetKeyBoard::createKeyboard(void) again.
As it seems to be the only place with tr(text);
retranslateUi() is very simple in all programs. it simply just sets the texts again
and the tr function gets the new text from the active translation.
Alternatively you need enum all widgets (in keyboard), get the text and re-set it via tr / directly look up trans text.
But it can be messy if many types of Widgets as then u need to handle the "setText" for each. -
@mrjj said:
@mbnoimi
well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
void WidgetKeyBoard::createKeyboard(void) again.I tried to call
createKeyboard()
once again as following but still gives same result although this function callstr()
so it suppose to do what you talked about!void Tester::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui->retranslateUi(this); myKeyboard->createKeyboard(); } else QWidget::changeEvent(event); }
-
Hi
Maybe you can
delete myKeyboard;
myKeyboard = new Keyboard(this);
as im not sure if calling createKeyboard() for same instance is 100% ok. (did not try it)Then there is the context thing.
for mainwindow, its "mainwindow" (doh), but I do wonder about the translation that comes from static.Since they are linked into "main", I assume its context is the same as main (tester) but if the
qm is different, it will not work.So open them (qms) in Linguist and check the context they were extracted as.
then try with
http://doc.qt.io/qt-5/qcoreapplication.html#translateTo test a translation with that context and see if it does resolve.
First then I would worry about tr working in createKeyboard()
If I may say so.
update:
Context is "WidgetKeyBoard"
So calling createKeyboard() should be in the right context as we are in that class.So testing with qcoreapplication.html#translate
to see if all is loaded and happy. -
Thank you guys, I'm no longer work on this project since Digia announcement.