Merge lp:~angeloc/python-distutils-extra/fix_for_qt_translation into lp:python-distutils-extra

Proposed by Angelo Compagnucci
Status: Rejected
Rejected by: Martin Pitt
Proposed branch: lp:~angeloc/python-distutils-extra/fix_for_qt_translation
Merge into: lp:python-distutils-extra
Diff against target: 154 lines (+72/-60)
1 file modified
DistUtilsExtra/command/build_i18n.py (+72/-60)
To merge this branch: bzr merge lp:~angeloc/python-distutils-extra/fix_for_qt_translation
Reviewer Review Type Date Requested Status
Martin Pitt (community) Needs Fixing
Review via email: mp+110669@code.launchpad.net

Description of the change

Added support for QT translation files in qm folder.

If a qm folder is present and has qm files in it, this folder is chosen over po folder and QT translation files are packaged instead gettext ones.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks Angelo for working on this!

So the mere presence of an empty qm/ folder will trigger this, and then convert the .po files? That looks kind of strange. Also, I'm really not sure that we should promote the really sad idea of a parallel translation standard; gettext works everywhere, obviously also with Qt, and if you can automatically create qm files out of po files then there is nothing that this would give us?

If we really need this, at least the .pot file should be built even in the presence of qm/, as you need that for translators.

review: Needs Fixing
Revision history for this message
Angelo Compagnucci (angeloc) wrote :

Hi Martin,

Sorry for haven't explained well the rationale behind this this patch.
There 2 components in this patch:

1) Packaging qm folder. Pyside developers, and pyqt ones, generally prefer
use internal QT translation mechanism. Gettext it's not supported and using
it is somewhat tricky. So the idea is to have qm folder packaged if present
and I think there is nothing wrong.

2) Po -> qm is necessary in Quickly QT templates, because to exploit full
potential of launchpad, you have to produce a pot file and translate it in
po files. With quickly, po files are produced on Launchpad and synchronized
with local repository successively, so you have a completely filled and
synced po translation folder just before packaging. Just before packaging
also, if package has a qm folder, this folder should be filled in with qm
files generated by the po ones.
This part is really out of place here, I reworked the patch exclude it.

Angelo

2012/6/19 Martin Pitt <email address hidden>

> Review: Needs Fixing
>
> Thanks Angelo for working on this!
>
> So the mere presence of an empty qm/ folder will trigger this, and then
> convert the .po files? That looks kind of strange. Also, I'm really not
> sure that we should promote the really sad idea of a parallel translation
> standard; gettext works everywhere, obviously also with Qt, and if you can
> automatically create qm files out of po files then there is nothing that
> this would give us?
>
> If we really need this, at least the .pot file should be built even in the
> presence of qm/, as you need that for translators.
> --
>
> https://code.launchpad.net/~angeloc/python-distutils-extra/fix_for_qt_translation/+merge/110669
> You are the owner of
> lp:~angeloc/python-distutils-extra/fix_for_qt_translation.
>

--
Profile: http://it.linkedin.com/in/compagnucciangelo

291. By Angelo Compagnucci

Patch reworked to exclude po to qm dinamic conversion.

292. By Angelo Compagnucci

Fixing a wrong debug print.

Revision history for this message
Martin Pitt (pitti) wrote :

OK, thanks. A change of this size needs a test case, similar to test_po() in test/auto.py. Do you want to write one yourself? If not, I can find some time to do it as well, but it might be a few days.

Revision history for this message
Angelo Compagnucci (angeloc) wrote :

Yes! I'll write one as soon as possible!

2012/6/21 Martin Pitt <email address hidden>

> OK, thanks. A change of this size needs a test case, similar to test_po()
> in test/auto.py. Do you want to write one yourself? If not, I can find some
> time to do it as well, but it might be a few days.
> --
>
> https://code.launchpad.net/~angeloc/python-distutils-extra/fix_for_qt_translation/+merge/110669
> You are the owner of
> lp:~angeloc/python-distutils-extra/fix_for_qt_translation.
>

--
Profile: http://it.linkedin.com/in/compagnucciangelo

Unmerged revisions

292. By Angelo Compagnucci

Fixing a wrong debug print.

291. By Angelo Compagnucci

Patch reworked to exclude po to qm dinamic conversion.

290. By Angelo Compagnucci

Added support for QT translation files in qm folder.

289. By Angelo Compagnucci

Initial fix for qm translation files support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUtilsExtra/command/build_i18n.py'
2--- DistUtilsExtra/command/build_i18n.py 2010-06-23 18:47:30 +0000
3+++ DistUtilsExtra/command/build_i18n.py 2012-06-19 06:41:22 +0000
4@@ -44,12 +44,15 @@
5 self.merge_po = False
6 self.bug_contact = None
7 self.po_dir = None
8+ self.qm_dir = None
9
10 def finalize_options(self):
11 if self.domain is None:
12 self.domain = self.distribution.metadata.name
13 if self.po_dir is None:
14 self.po_dir = "po"
15+ if self.qm_dir is None:
16+ self.qm_dir = "qm"
17
18 def run(self):
19 """
20@@ -85,65 +88,74 @@
21 selected_languages = open(linguas_file).read().split()
22 if "LINGUAS" in os.environ:
23 selected_languages = os.environ["LINGUAS"].split()
24-
25- # Update po(t) files and print a report
26- # We have to change the working dir to the po dir for intltool
27- cmd = ["intltool-update", (self.merge_po and "-r" or "-p"), "-g", self.domain]
28- wd = os.getcwd()
29- os.chdir(self.po_dir)
30- self.spawn(cmd)
31- os.chdir(wd)
32- max_po_mtime = 0
33- for po_file in glob.glob("%s/*.po" % self.po_dir):
34- lang = os.path.basename(po_file[:-3])
35- if selected_languages and not lang in selected_languages:
36- continue
37- mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES")
38- mo_file = os.path.join(mo_dir, "%s.mo" % self.domain)
39- if not os.path.exists(mo_dir):
40- os.makedirs(mo_dir)
41- cmd = ["msgfmt", po_file, "-o", mo_file]
42- po_mtime = os.path.getmtime(po_file)
43- mo_mtime = os.path.exists(mo_file) and os.path.getmtime(mo_file) or 0
44- if po_mtime > max_po_mtime:
45- max_po_mtime = po_mtime
46- if po_mtime > mo_mtime:
47- self.spawn(cmd)
48-
49- targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
50- data_files.append((targetpath, (mo_file,)))
51-
52- # merge .in with translation
53- for (option, switch) in ((self.xml_files, "-x"),
54- (self.desktop_files, "-d"),
55- (self.schemas_files, "-s"),
56- (self.rfc822deb_files, "-r"),
57- (self.ba_files, "-b"),
58- (self.key_files, "-k"),):
59- try:
60- file_set = eval(option)
61- except:
62- continue
63- for (target, files) in file_set:
64- build_target = os.path.join("build", target)
65- if not os.path.exists(build_target):
66- os.makedirs(build_target)
67- files_merged = []
68- for file in files:
69- if file.endswith(".in"):
70- file_merged = os.path.basename(file[:-3])
71- else:
72- file_merged = os.path.basename(file)
73- file_merged = os.path.join(build_target, file_merged)
74- cmd = ["intltool-merge", switch, self.po_dir, file,
75- file_merged]
76- mtime_merged = os.path.exists(file_merged) and \
77- os.path.getmtime(file_merged) or 0
78- mtime_file = os.path.getmtime(file)
79- if mtime_merged < max_po_mtime or mtime_merged < mtime_file:
80- # Only build if output is older than input (.po,.in)
81- self.spawn(cmd)
82- files_merged.append(file_merged)
83- data_files.append((target, files_merged))
84+
85+ if os.path.isdir(self.qm_dir):
86+ wd = os.getcwd()
87+ os.chdir(self.qm_dir)
88+ for qm_file in glob.glob("*.qm"):
89+ data_files.append((os.path.join('share', self.distribution.get_name(), 'qm'),
90+ [os.path.join('qm', qm_file)]))
91+ os.chdir(wd)
92+
93+ else:
94+ # Update po(t) files and print a report
95+ # We have to change the working dir to the po dir for intltool
96+ cmd = ["intltool-update", (self.merge_po and "-r" or "-p"), "-g", self.domain]
97+ wd = os.getcwd()
98+ os.chdir(self.po_dir)
99+ self.spawn(cmd)
100+ os.chdir(wd)
101+ max_po_mtime = 0
102+ for po_file in glob.glob("%s/*.po" % self.po_dir):
103+ lang = os.path.basename(po_file[:-3])
104+ if selected_languages and not lang in selected_languages:
105+ continue
106+ mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES")
107+ mo_file = os.path.join(mo_dir, "%s.mo" % self.domain)
108+ if not os.path.exists(mo_dir):
109+ os.makedirs(mo_dir)
110+ cmd = ["msgfmt", po_file, "-o", mo_file]
111+ po_mtime = os.path.getmtime(po_file)
112+ mo_mtime = os.path.exists(mo_file) and os.path.getmtime(mo_file) or 0
113+ if po_mtime > max_po_mtime:
114+ max_po_mtime = po_mtime
115+ if po_mtime > mo_mtime:
116+ self.spawn(cmd)
117+
118+ targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
119+ data_files.append((targetpath, (mo_file,)))
120+
121+ # merge .in with translation
122+ for (option, switch) in ((self.xml_files, "-x"),
123+ (self.desktop_files, "-d"),
124+ (self.schemas_files, "-s"),
125+ (self.rfc822deb_files, "-r"),
126+ (self.ba_files, "-b"),
127+ (self.key_files, "-k"),):
128+ try:
129+ file_set = eval(option)
130+ except:
131+ continue
132+ for (target, files) in file_set:
133+ build_target = os.path.join("build", target)
134+ if not os.path.exists(build_target):
135+ os.makedirs(build_target)
136+ files_merged = []
137+ for file in files:
138+ if file.endswith(".in"):
139+ file_merged = os.path.basename(file[:-3])
140+ else:
141+ file_merged = os.path.basename(file)
142+ file_merged = os.path.join(build_target, file_merged)
143+ cmd = ["intltool-merge", switch, self.po_dir, file,
144+ file_merged]
145+ mtime_merged = os.path.exists(file_merged) and \
146+ os.path.getmtime(file_merged) or 0
147+ mtime_file = os.path.getmtime(file)
148+ if mtime_merged < max_po_mtime or mtime_merged < mtime_file:
149+ # Only build if output is older than input (.po,.in)
150+ self.spawn(cmd)
151+ files_merged.append(file_merged)
152+ data_files.append((target, files_merged))
153
154 # class build

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: