LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-26-2023, 03:38 AM   #1
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
[Qt Translations] using += lrelease and += embed_translations


Good morning.

I do not understand the documentation of the qmake config-variables, nor the use of QM_FILES_RESOURCE_PREFIX, cannot see, how those translations under /usr/share/Qt[n]/translations are found by the respective applications, and have no clue about how I get my *.qm files read by my own application.

Here are the pertinent excerpts from my project. These are not working.

upsslideshow.pro
Code:
QM_FILES_RESOURCE_PREFIX = "/usr/share/upsslideshow"

CONFIG += lrelease 
CONFIG += embed_translations
(...)
TRANSLATIONS += upsslideshow_fr_FR.ts \
                upsslideshow_de_DE.ts
main.cpp
Code:
QTranslator translator;
  QString locale = QLocale::system().name();
  [[maybe_unused]]  bool isso = translator.load(QString("upsslideshow_") + locale);
  a.installTranslator(&translator);
I have moved the .qm files all over the place but the only way to make them available to the executable, had been to store them along the program, in the same directory. Each modification of my *.pro file had been followed by make distclean;qmake.
Anyway, I cannot see that QM_FILES_RESOURCE_PREFIX were honored anywhere, at least not in the generated Makefile.

For 15 years, I have not considered it necessary to produce translations for this program; I may just as well continue this way.

The only translation mechanism that satisfies me today, is my own, for the Ruby-language. No big deal, I would have said... but I am probably wrong.

Thank you for any hints.

Cheerio.

Edit: In the Qt-forum several responses are given to similar questions. Apart from imitating the code-examples, given there, and then to hope for the best, I see no way of taking benefit from these discussions, either. The procedures are illogical and the descriptions cryptic. I will not code something that I do not understand.

Last edited by Michael Uplawski; 03-26-2023 at 01:20 PM. Reason: Ornitho ... orthographix and some grammatix, too. Typing with 9¾ fingers.
 
Old 03-26-2023, 04:32 AM   #2
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Side-note: as I can imagine xslt-processing the *.ts files into a C++ header-file, can you imagine problems with the idea?

Side-note 2: YAML. Do you have experience with a YAML library for C++ ? This could be easier to integrate than a header-file, but may slow down the execution, as I cannot conditionally instantiate locale-specific translators.., I guess.

Last edited by Michael Uplawski; 03-26-2023 at 01:27 PM. Reason: yaml
 
Old 03-26-2023, 03:19 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Examples:

https://doc.qt.io/qt-5/qtranslator.html
Code:
QTranslator* translator = new QTranslator();
if (translator->load("myfile.qm", "/path/to/folder/with/qm/files")) {
    app.installTranslator(translator);
}
https://doc.qt.io/qt-5/resources.html
Code:
QTranslator* translator = new QTranslator();
if (translator->load("myfile.qm", ":/resources/translations")) {
    app.installTranslator(translator);
}
Code:
if(!QFile::exists("myfile.qm"))
    qWarning("failed-no file");
https://wiki.qt.io/How_to_create_a_m...ge_application

Last edited by teckk; 03-26-2023 at 03:21 PM.
 
Old 03-26-2023, 03:30 PM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Example pro file
Code:
TEMPLATE = app
TARGET = pdfviewer
QT += core gui widgets pdfwidgets

SOURCES += \
    main.cpp \
    mainwindow.cpp \
    pageselector.cpp \
    zoomselector.cpp

HEADERS += \
    mainwindow.h \
    pageselector.h \
    zoomselector.h

FORMS += \
    mainwindow.ui

RESOURCES += \
    resources.qrc
    
TRANSLATIONS += \
    languages/translation_en.ts \
    languages/translation_fr.ts \
    languages/translation_ru.ts

target.path = $$[QT_INSTALL_EXAMPLES]/pdfwidgets/pdfviewer
INSTALLS += target

Last edited by teckk; 03-26-2023 at 03:32 PM.
 
Old 03-27-2023, 01:55 AM   #5
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by teckk View Post
(...)
TRANSLATIONS += \
languages/translation_en.ts \
languages/translation_fr.ts \
languages/translation_ru.ts

target.path = $$[QT_INSTALL_EXAMPLES]/pdfwidgets/pdfviewer
INSTALLS += target[/code]
I have not advanced any further, but consent to discuss the examples.
1) the directory “languages” is a top level object in the project? Like in
Code:
--------------
/home/user/projects/pdfviewer
     src
     languages
     lib

(...)
---------------
2) :resources, from your second code example, is what and where?

3) There is no translation embedded in your examples. I ignore, thus, the detail which should help me advance with my own project. Maybe comment the code in this way, I do not yet get it.

More questions to follow.

Last edited by Michael Uplawski; 03-27-2023 at 02:00 AM. Reason: finger bandaged.
 
Old 03-27-2023, 06:45 AM   #6
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
... and

I discover that qmake has produced another file that I have never heard of, qmake_qmake_qm_files.qrc. Content:
Code:
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="[see below]">
<file alias="upsslideshow_fr_FR.qm">/home/michael/prog/upsslideshow/.qm/upsslideshow_fr_FR.qm</file>
<file alias="upsslideshow_de_DE.qm">/home/michael/prog/upsslideshow/.qm/upsslideshow_de_DE.qm</file>
</qresource>
</RCC>
Nothing I did not know, myself. Maybe someone knows what this file is supposed to do and why it does not help me.

THE GENERATIONS TO COME, HEAR ME
Edit: qmake_qmake_qm_files.qrc is a default resource file, when nothing else is set (nothing *.qrc in the project file).

And: Solved
The ominous path in the second argument to Translator.load() is a resource path. You can define your own, but if you choose to embed translations in your program, this path does not need to point at an existing directory: It depends on the content of the *.qrc file:
Code:
qresource prefix="i18n">
This is from the automatically generated default resource file, when none is named in the project-file. The prefix “i18n” will serve as parameter to Translator.load():
Code:
[[maybe_unused]]  bool isso = translator.load(QString("upsslideshow_") + locale, ":i18n");
The remainder of the configuration is made only in the project-file *.pro:
Code:
CONFIG += lrelease 
CONFIG += embed_translations
TRANSLATIONS += upsslideshow_fr_FR.ts \
                upsslideshow_de_DE.ts
You need *no* Prefixes other than i18n in the main.cpp (where the QTranslator is instantiated) and no file-paths whatsoever. lrelease will compile *.qm files to te directory “.qm” that is referenced in the default resource-file and the prefix i18n is enough to find it there.

Run qmake and make. Additional *.cpp- and *.h files will be generated, containing the translations, then compiled and linked in the executable.

Big Mess, but it works now.

Big mess in the documentation and all the discussions that I have found,

Last edited by Michael Uplawski; 03-27-2023 at 09:01 AM. Reason: syntax, update
 
Old 03-29-2023, 11:59 AM   #7
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
New Web-Page:
Qt: Embedding Translations
Blog

Last edited by Michael Uplawski; 03-29-2023 at 02:45 PM. Reason: blog
 
  


Reply

Tags
internationalization, lrelease, qmake, qt



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] lrelease: command not found Apprentice+ Linux - Software 3 11-01-2022 07:13 AM
[SOLVED] lrelease missing from qt47 john.wythe@activant.com Linux - Virtualization and Cloud 1 10-19-2011 05:19 PM
LXer: opentaps Open Source ERP + CRM Targets Europe, Latin America with VAT Support and Translations LXer Syndicated Linux News 0 07-27-2011 10:11 AM
LXer: Linux: Kernel Documentation and Translations LXer Syndicated Linux News 0 06-24-2007 05:01 PM
LXer: KDE 3.5.6 Released with New Features, Translations and Fixes LXer Syndicated Linux News 0 01-26-2007 04:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration