How to load translation for static library widget
-
I didn't say that!
I said I get Failed to load translation from static libraryIndeed you did, it's my mistake, sorry.
which points to myTranslator->load(":/languages/arabic") failure!
Could you verify that this file is available? For example what does
QFile::exists(":/languages/arabic")
return, true or false? If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.Kind regards.
-
@kshegunov said:
Could you verify that this file is available? For example what does
QFile::exists(":/languages/arabic")
return, true or false?I get
true
If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.
After reviewing the project I discovered there are two "resources.qrc" the first one in the static library and the other in tester app. so I supposed this maybe makes Qt confused so I renamed one of them to a different name but unfortunately I still get same result.
-
@mrjj said:
QDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next(); }
to have a look how the files are named in the running exe to to verify
that they are indeed under ":/i18n" and paths are as you expect.I got this output:
Failed to load translation from static library ":/qt-project.org" ":/qt-project.org/qmime" ":/qt-project.org/qmime/freedesktop.org.xml" ":/qt-project.org/styles" ":/qt-project.org/styles/commonstyle" ":/qt-project.org/styles/commonstyle/images" ":/qt-project.org/styles/commonstyle/images/networkdrive-16.png" ":/qt-project.org/styles/commonstyle/images/networkdrive-32.png" ":/qt-project.org/styles/commonstyle/images/dvd-16.png" ":/qt-project.org/styles/commonstyle/images/cdr-16.png" ":/qt-project.org/styles/commonstyle/images/up-16.png" ":/qt-project.org/styles/commonstyle/images/up-32.png" ":/qt-project.org/styles/commonstyle/images/dvd-32.png" ":/qt-project.org/styles/commonstyle/images/cdr-32.png" ":/qt-project.org/styles/commonstyle/images/left-32.png" ":/qt-project.org/styles/commonstyle/images/stop-32.png" ":/qt-project.org/styles/commonstyle/images/file-16.png" ":/qt-project.org/styles/commonstyle/images/down-16.png" ":/qt-project.org/styles/commonstyle/images/stop-24.png" ":/qt-project.org/styles/commonstyle/images/left-16.png" ":/qt-project.org/styles/commonstyle/images/down-32.png" ":/qt-project.org/styles/commonstyle/images/file-32.png" ":/qt-project.org/styles/commonstyle/images/dirlink-32.png" ":/qt-project.org/styles/commonstyle/images/diropen-32.png" ":/qt-project.org/styles/commonstyle/images/diropen-16.png" ":/qt-project.org/styles/commonstyle/images/cleartext-16.png" ":/qt-project.org/styles/commonstyle/images/dirlink-16.png" ":/qt-project.org/styles/commonstyle/images/networkdrive-128.png" ":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-open-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-16.png" ":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png" ":/qt-project.org/styles/commonstyle/images/newdirectory-128.png" ":/qt-project.org/styles/commonstyle/images/filecontents-128.png" ":/qt-project.org/styles/commonstyle/images/floppy-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-32.png" ":/qt-project.org/styles/commonstyle/images/harddrive-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-close-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-close-16.png" ":/qt-project.org/styles/commonstyle/images/dirclosed-128.png" ":/qt-project.org/styles/commonstyle/images/trash-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-32.png" ":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png" ":/qt-project.org/styles/commonstyle/images/newdirectory-32.png" ":/qt-project.org/styles/commonstyle/images/dirclosed-32.png" ":/qt-project.org/styles/commonstyle/images/newdirectory-16.png" ":/qt-project.org/styles/commonstyle/images/dirclosed-16.png" ":/qt-project.org/styles/commonstyle/images/up-128.png" ":/qt-project.org/styles/commonstyle/images/media-pause-32.png" ":/qt-project.org/styles/commonstyle/images/media-pause-16.png" ":/qt-project.org/styles/commonstyle/images/cdr-128.png" ":/qt-project.org/styles/commonstyle/images/dvd-128.png" ":/qt-project.org/styles/commonstyle/images/media-volume-16.png" ":/qt-project.org/styles/commonstyle/images/harddrive-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-16.png" ":/qt-project.org/styles/commonstyle/images/harddrive-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-32.png" ":/qt-project.org/styles/commonstyle/images/viewdetailed-128.png" ":/qt-project.org/styles/commonstyle/images/fusion_groupbox.png" ":/qt-project.org/styles/commonstyle/images/right-128.png" ":/qt-project.org/styles/commonstyle/images/fileinfo-16.png" ":/qt-project.org/styles/commonstyle/images/filelink-16.png" ":/qt-project.org/styles/commonstyle/images/filelink-32.png" ":/qt-project.org/styles/commonstyle/images/fileinfo-32.png" ":/qt-project.org/styles/commonstyle/images/dirlink-128.png" ":/qt-project.org/styles/commonstyle/images/media-seek-forward-16.png" ":/qt-project.org/styles/commonstyle/images/media-seek-forward-32.png" ":/qt-project.org/styles/commonstyle/images/diropen-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-help-128.png" ":/qt-project.org/styles/commonstyle/images/viewdetailed-16.png" ":/qt-project.org/styles/commonstyle/images/viewdetailed-32.png" ":/qt-project.org/styles/commonstyle/images/media-seek-backward-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-no-128.png" ":/qt-project.org/styles/commonstyle/images/media-seek-backward-32.png" ":/qt-project.org/styles/commonstyle/images/refresh-32.png" ":/qt-project.org/styles/commonstyle/images/refresh-24.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-save-128.png" ":/qt-project.org/styles/commonstyle/images/viewlist-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-128.png" ":/qt-project.org/styles/commonstyle/images/computer-32.png" ":/qt-project.org/styles/commonstyle/images/computer-16.png" ":/qt-project.org/styles/commonstyle/images/parentdir-32.png" ":/qt-project.org/styles/commonstyle/images/parentdir-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png" ":/qt-project.org/styles/commonstyle/images/media-play-16.png" ":/qt-project.org/styles/commonstyle/images/desktop-16.png" ":/qt-project.org/styles/commonstyle/images/media-stop-16.png" ":/qt-project.org/styles/commonstyle/images/desktop-32.png" ":/qt-project.org/styles/commonstyle/images/media-play-32.png" ":/qt-project.org/styles/commonstyle/images/down-128.png" ":/qt-project.org/styles/commonstyle/images/media-stop-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-128.png" ":/qt-project.org/styles/commonstyle/images/media-skip-backward-32.png" ":/qt-project.org/styles/commonstyle/images/media-skip-backward-16.png" ":/qt-project.org/styles/commonstyle/images/fusion_arrow.png" ":/qt-project.org/styles/commonstyle/images/viewlist-16.png" ":/qt-project.org/styles/commonstyle/images/viewlist-32.png" ":/qt-project.org/styles/commonstyle/images/file-128.png" ":/qt-project.org/styles/commonstyle/images/floppy-32.png" ":/qt-project.org/styles/commonstyle/images/left-128.png" ":/qt-project.org/styles/commonstyle/images/floppy-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-no-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-no-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-16.png" ":/qt-project.org/styles/commonstyle/images/media-skip-forward-32.png" ":/qt-project.org/styles/commonstyle/images/media-skip-forward-16.png" ":/qt-project.org/styles/commonstyle/images/filelink-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-open-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png" ":/qt-project.org/styles/commonstyle/images/fileinfo-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-help-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-help-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-save-16.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-16.png" ":/qt-project.org/styles/commonstyle/images/parentdir-128.png" ":/qt-project.org/styles/commonstyle/images/filecontents-32.png" ":/qt-project.org/styles/commonstyle/images/trash-32.png" ":/qt-project.org/styles/commonstyle/images/filecontents-16.png" ":/qt-project.org/styles/commonstyle/images/trash-16.png" ":/qt-project.org/styles/commonstyle/images/right-16.png" ":/qt-project.org/styles/commonstyle/images/right-32.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-128.png" ":/qt-project.org/styles/commonstyle/images/standardbutton-close-128.png" ":/qt-project.org/styles/macstyle" ":/qt-project.org/styles/macstyle/images" ":/qt-project.org/styles/macstyle/images/toolbar-ext.png" ":/qt-project.org/styles/macstyle/images/dockdock-down-16.png" ":/qt-project.org/styles/macstyle/images/closedock-16.png" ":/qt-project.org/styles/macstyle/images/dockdock-16.png" ":/qt-project.org/styles/macstyle/images/closedock-down-16.png" ":/qt-project.org/styles/macstyle/images/toolbar-ext@2x.png" ":/qt-project.org/qmessagebox" ":/qt-project.org/qmessagebox/images" ":/qt-project.org/qmessagebox/images/qtlogo-64.png" ":/i18n" ":/i18n/tester_ar.qm" ":/i18n/tester_de.qm" ":/i18n/tester_fr.qm" ":/i18n/tester_en.qm" ":/i18n/tester_ru.qm" ":/i18n/tester_it.qm" ":/languages" ":/languages/i18n" ":/languages/i18n/WidgetKeyboard_fr.qm" ":/languages/i18n/WidgetKeyboard_ar.qm" ":/languages/i18n/WidgetKeyboard_de.qm" ":/languages/i18n/WidgetKeyboard_en.qm" ":/languages/i18n/WidgetKeyboard_it.qm" ":/languages/i18n/WidgetKeyboard_ru.qm" ":/images" ":/images/cut" ":/images/copy" ":/images/logo" ":/images/paste" ":/images/normalEcho" ":/images/passwdEcho" ":/sounds" ":/sounds/click.wav" QSoundEffect(pulseaudio): Error decoding source
-
@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.