maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Is there a way to generate a ts-file for qml and python at the same time? (https://talk.maemo.org/showthread.php?t=88211)

EmaNymton 2012-12-11 17:10

Is there a way to generate a ts-file for qml and python at the same time?
 
May be a dump question but I have the following problem:

I have projects with both qml and python-files which contains strings, that should be translated.

There are tools for generating a ts-file for python-files (pyside-lupdate) and qml-files (lupdate) and they work fine for their own files but not for the others.
So every time I change something, I have to generate two seperate ts-files and merge the two ts-files by hand.

Call me lazy, but if there is a way to do it in one step, please let me know :p

EmaNymton

gionni88 2012-12-11 17:44

Re: Is there a way to generate a ts-file for qml and python at the same time?
 
I have never tried pyside, but can't you create the ts file with a script which calls both pyside-lupdate and lupdate which operates on python files and qml files but on the same ts file? Won't the ts file be filled by both programs?

EmaNymton 2012-12-11 19:22

Re: Is there a way to generate a ts-file for qml and python at the same time?
 
Unfortunately this doesn't work, because both programs seems to override the ts-file:

pyside-lupdate after lupdate:
Code:

pyside-lupdate -verbose main.py -ts base.ts
Updating 'base.ts'...
    Found 3 source texts (3 new and 0 already existing)
    Kept 0 obsolete translations
    Removed 26 obsolete untranslated entries

lupdate after pyside-lupdate
Code:

lupdate qml/* -ts base.ts Bringe 'base.ts' auf aktuellen Stand...
    Found 26 source text(s) (26 new and 0 already existing)
    Kept 3 obsolete entries

but the 3 obsolete entries are gone :confused:

gionni88 2012-12-12 08:09

Re: Is there a way to generate a ts-file for qml and python at the same time?
 
Check the ts version both commands use, are they different? You have to open the ts file with a text editor.

Another solution is to script everything:
Code:

pyside-lupdate main.py -ts temp.ts
tail -n +4 temp.ts
lupdate qml/* -ts base.ts
head -n -1 base.ts
cat temp.ts >> base.ts

EDIT: you create the first ts file and remove first 3 lines. Than create the second ts file, remove its last line (</TS>) and append the first ts file. So you get the complete ts file with just one (double) click.

EmaNymton 2012-12-12 09:25

Re: Is there a way to generate a ts-file for qml and python at the same time?
 
Thanks for the suggestion with the script, the version of pyside generated ts-file and lupdate are different (1.1 and 2.0). So I tried to change 1.1 to 2.0 by hand but the same outcome. I checked the PyQt lupdate and the ts-versions are the same, but the same result. :(

Code:

pylupdate4 version 4.8.1
pyside-lupdate version 4.8.0
lupdate Version 4.8.1

Funnily the generated headers of the files contains different line breaks, so you have to adapt the script a little bit (+4 should be +3).

lupdate
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0">
...

pylupdate4
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
...

pyside-lupdate
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1">
...

Because I'm not so good at bash scripting (tail and head don't change the ts.file, right?) I wrote a python script for myself that I will use.
Code:

#!/usr/bin/python
#-*- coding: utf-8 -*-
import os
os.system('lupdate qml/* -ts lupdate.ts')
os.system('pyside-lupdate main.py -ts pylupdate.ts')
with open('lupdate.ts','r') as lupdate:
    lines_lupdate = lupdate.readlines()
with open('pylupdate.ts','r') as pylupdate:
    lines_pylupdate = pylupdate.readlines()
with open('base.ts','w') as base:
    base.write(''.join(lines_lupdate[:-1]+lines_pylupdate[2:]))
os.system('rm lupdate.ts pylupdate.ts')

Thanks for your help!


All times are GMT. The time now is 15:15.

vBulletin® Version 3.8.8