[PyQt] Qt Linguist and pylupdate4: project layout and paths in my_software_*.ts
Jérôme
jerome at jolimont.fr
Mon Mar 9 13:12:26 GMT 2015
Hi all.
I'm writing a PyQt4 project and I'm having a hard time with the
translation features.
My project is structured as follows:
------------------------------------------------------------------------------------
src/
my_software.py
my_software.pro
my_software/
module_1.py
module_2.py
submodule_1/
submodule_1_module_1.py
submodule_1_module_2.py
resources/
ui/
module_1.ui
module_2.ui
submodule_1/
submodule_1_module_1.ui
submodule_1_module_2.ui
i18n/
ts/
my_software_fr.ts
my_software_fr.qm
tools/
tool_1.py
------------------------------------------------------------------------------------
The project file looks like :
-- my_software.pro
-----------------------------------------------------------------
FORMS = resources/ui/module_1.ui resources/ui/module_2.ui
resources/ui/submodule_1_module_1.ui
resources/ui/submodule_1_module_2.ui
SOURCES = my_software/module_1.py my_software/module_2.py
resources/ui/submodule_1_module_1.py
resources/ui/submodule_1_module_2.py
TRANSLATIONS = i18n/ts/my_software_fr.ts
------------------------------------------------------------------------------------
When I call pylupdate4 and lrelease on my_software.pro, I get the .ts
and .qm files created. Fine.
The only shortcoming right now is Qt Linguist doesn't display the
context: it searches for the files in e.g.
/absolute/path/to/project/src/i18n/ts/my_software/module_1.py
The .ts file looks like
-- my_software_fr.ts
---------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="fr_FR">
<context>
<name>Class</name>
<message>
<location filename="my_software/module_1.py" line="134"/>
<source>Source text</source>
<translation>Translated text</translation>
------------------------------------------------------------------------------------
and apparently, Qt Linguist considers relative paths starting from the
.ts file, not the .pro file.
How can I get Qt Linguist to display the source code ?
I can put the .pro file in the ts/ directory. In fact, I wouldn't mind.
I only use it for translation purposes, and my scripts create it and
erase it each time I need a translation update. But is this how it is
meant to be ?
Considering Qt Linguist's behaviour, shouldn't pylupdate4 write paths in
the .ts file relative to the .ts file itself, rather than the .pro file
?
Remarks :
- The C++ version of lupdate has an --absolute|relative flag that might
be related to this.
- I don't wan't to maintain my_software.pro, so I created scripts to
generate it and do the pylupdate4 and lrelease calls.
- This project layout might not be the most sensible. I searched the
web, found different ways of doing this and used a mix of them. I'm open
to suggestions. I'm trying to do things the way they should, rather than
find a workaround to my specific issue.
Thanks for any help.
--
Jérôme
More information about the PyQt
mailing list