<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 18, 2014 at 2:05 PM, Aurélien Gâteau <span dir="ltr"><<a href="mailto:agateau@kde.org" target="_blank">agateau@kde.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
I started working on how to handle Qt based translations, and make it as<br>
simple as possible to work with for framework maintainers as well as<br>
framework users.<br>
<br>
I picked KBookmarks as my guinea pig and got to the point where<br>
kbookmarkdialogtest shows a translated dialog.<br>
<br>
Here is how it currently works. All of this is liberally inspired from<br>
the way Trojita works:<br>
<br>
# String extraction<br>
<br>
I created a src/Messages.sh which contains the following:<br>
<br>
lupdate -silent -recursive . -ts $podir/tmp.ts<br>
lconvert $podir/tmp.ts --sort-contexts --output-format pot -o<br>
$podir/kbookmarks5.pot<br>
rm $podir/tmp.ts<br>
<br>
# String compilation<br>
<br>
I modified the toplevel CMakeLists.txt, adding these lines:<br>
<br>
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/po)<br>
include(${CMAKE_CURRENT_SOURCE_DIR}/QmSupport.cmake)<br>
qm_setup(kbookmarks5 po)<br>
endif()<br>
<br>
I created a QmSupport.cmake file, which exposes a qm_setup() function.<br>
This function does three things:<br>
1. Create a "qm" target which turns all .po into .qm files.<br>
<br>
2. Call install(FILES...) on the generated qm files, installing them in<br>
share/${name}/locale, where ${name} is the firt argument of qm_setup().<br>
<br>
3. Generate a "${name}_translation.h" which contain two inline functions<br>
to make it easy to load the translations.<br>
Using the translation is then just a matter of including<br>
${name}_translation.h and calling ${name}_installTranslator(). If more<br>
control is needed, ${name}_installTranslator() also accepts an optional<br>
argument: the language. For even finer control, the .h also contains a<br>
${name}_createTranslator() function, which returns a QTranslator loaded<br>
with strings for the right language.<br>
<br>
# Questions<br>
<br>
Does this approach sounds sane to you?<br>
<br>
I think QmSupport.cmake should go to extra-cmake-modules. Any<br>
objections?<br>
<br>
Right now qm_setup() is very inflexible: it installs files and creates<br>
the _translation.h file based on the name argument, meaning in my<br>
example it creates share/kbookmarks5/locale/kbookmarks5_*.qm and<br>
include/kbookmarks5_translation.h, which contains the functions<br>
kbookmarks5_createTranslator and kbookmarks5_installTranslator.<br>
<br>
I think we want to be able to customize the install dir of the<br>
_translation.h file because some frameworks install header files in a<br>
subdir, others do not.<br>
<br>
Should we also be able to customize the install data dir for qm files,<br>
as well as the prefix of the function names from _translation.h? I am<br>
tempted to default to ${PROJECT_NAME} for the prefix of the function<br>
names, its lowercase version for the install data dir and add an<br>
optional PROJECT_NAME argument to qm_setup(). Opinions?<br>
<br>
I am attaching the diff of the current state. I do not intend to commit<br>
it as is since po files are not supposed to be in the framework<br>
repository, but it should make it easy for you to try it if you are<br>
interested.<br>
<span class=""><font color="#888888"><br>
Aurélien<br>
</font></span><br>_______________________________________________<br>
Kde-frameworks-devel mailing list<br>
<a href="mailto:Kde-frameworks-devel@kde.org">Kde-frameworks-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kde-frameworks-devel" target="_blank">https://mail.kde.org/mailman/listinfo/kde-frameworks-devel</a><br>
<br></blockquote></div><br></div><div class="gmail_extra">Hi Aurélien,</div><div class="gmail_extra">Wouldn't it make sense that the library called the createTranslation itself, instead of expecting the application to call it? I can easily see applications forgetting it.</div>
<div class="gmail_extra">Maybe using Q_COREAPP_STARTUP_FUNCTION?</div><div class="gmail_extra"><br></div><div class="gmail_extra">Aleix</div><div class="gmail_extra"><br></div></div>