Bug 43594 - Integrate translations into package build via debian/*.univention-l10n files
Integrate translations into package build via debian/*.univention-l10n files
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UMC (Generic)
UCS 4.2
Other Linux
: P5 normal (vote)
: UCS 4.2
Assigned To: Eduard Mai
Alexander Kläser
: interim-2
: 41807 42810 (view as bug list)
Depends on:
Blocks: 42173
  Show dependency treegraph
 
Reported: 2017-02-21 10:00 CET by Alexander Kläser
Modified: 2017-06-16 19:16 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kläser univentionstaff 2017-02-21 10:00:35 CET
At several places (e.g., login, setup, activation, portal) we need a way to integrate the translations into the package build. It would be very helpful to have a tool which uses the existing libraries to read debian/*.univention-l10n files and which can be integrated into debian/rules file.
Comment 1 Alexander Kläser univentionstaff 2017-02-21 10:02:31 CET
From Bug 38824, comment 10:
> There is no de.po anymore in univention-management-console/ for the
> javascript files.
Comment 2 Jürn Brodersen univentionstaff 2017-02-21 11:13:26 CET
Self service translations are missing, cf. Bug 42267, comment 6:
> [...] 
> (f) German translations are missing.
Comment 3 Alexander Kläser univentionstaff 2017-02-22 18:19:13 CET
As far as I see, the following packages/package parts are not translated ATM:

base/univention-system-setup/var/www/univention/setup/
management/univention-portal/www
management/univention-self-service/www
management/univention-management-console/www/
management/univention-management-console-module-passwordchange/js/
Comment 4 Eduard Mai univentionstaff 2017-03-02 21:27:34 CET
Revisions r77130 r77131 r77132 r77297 and r77303 extend translationhelper to able to generate all message catalogs per source package. This enables us to use its API to build the integration described in comment #1.
Two tools to use with(in) debian/rules are added (univention-l10-build & univention-l10n-install)

UCS 4.2:

Package: univention-ucs-translation-template
Version: 4.2.0-0A~4.2.0.201703022124
Branch: ucs_4.2-0

TODO: changelog entry...
Comment 5 Alexander Kläser univentionstaff 2017-03-03 14:57:22 CET
I get a traceback when xgettext returns a non-zero exit code. 

> usr/share/univention-system-setup-boot/www/de.po:55: Mehrfachdefinition der Meldung...
> usr/share/univention-system-setup-boot/www/de.po:25: ...dies ist die Stelle der ersten Definition
> xgettext: es ist 1 fataler Fehler aufgetreten
>Traceback (most recent call last):
>  File "/usr/bin/univention-l10n-build", line 56, in <module>
>    source_file_set.process_po(po_target.new_po_path)
>  File "/usr/lib/pymodules/python2.7/univention/translationhelper/sourcefileprocessing.py", line 107, in process_po
>    message_catalogs.join_existing('JavaScript', new_po_path, html_path, cwd=self.src_pkg_path)
>  File "/usr/lib/pymodules/python2.7/univention/translationhelper/message_catalogs.py", line 87, in join_existing
>    _call_gettext('xgettext', '--from-code=UTF-8', '--join-existing', '--omit-header', '--language', language, '-o', output_file, *input_files, cwd=cwd)
>  File "/usr/lib/pymodules/python2.7/univention/translationhelper/message_catalogs.py", line 101, in _call_gettext
>    raise GettextError("Error: A gettext tool exited unsuccessfully. Attempted command:\n{}".format(exc.cmd))
> univention.translationhelper.message_catalogs.GettextError: Error: A gettext tool exited unsuccessfully. Attempted command:
> ['xgettext', '--from-code=UTF-8', '--join-existing', '--omit-header', '--language', 'JavaScript', '-o', u'usr/share/univention-system-setup-boot/www/de.po', 'usr/share/univention-system-setup-boot/www/index.html']

It also seems that (at least for HTML files) new entries are added to the PO file which are empty and which have already been defined in the PO file.
Comment 6 Alexander Kläser univentionstaff 2017-03-03 14:59:18 CET
I added handling for a po_path property which allows to directly specify a path for the PO file.

BTW, I just realized that you did some commits using an old Bug number (42260).

univention-ucs-translation-template (4.2.0-1):
r77329 | Bug #42260: allow po_path property
Comment 7 Alexander Kläser univentionstaff 2017-03-03 15:23:42 CET
Here an example output for univention-system-setup:

> ./usr/share/univention-system-setup-boot/www/i18n/de/main.json
> ./usr/share/univention-system-setup-boot/www/i18n/de/main.po
> ./usr/share/locale/de/LC_MESSAGES/univention-system-setup-scripts.po
> ./usr/share/univention-system-setup/www/i18n/de/main.json
> ./usr/share/univention-system-setup/www/de.po
> ./debian/univention-system-setup/usr/share/locale/de/LC_MESSAGES/univention-system-setup-scripts.mo

I would vote for installing json and mo files directly debian/<packageName>
Comment 8 Alexander Kläser univentionstaff 2017-03-03 15:34:55 CET
(In reply to Alexander Kläser from comment #5)
> [...]
> It also seems that (at least for HTML files) new entries are added to the PO
> file which are empty and which have already been defined in the PO file.

I fixed this. Besides from that, I realized that obsolete entries of a HTML file are not removed/commented out.

univention-ucs-translation-template (4.2.0-2):
r77332 | Bug #43594: fix double po entries for HTML files
Comment 9 Alexander Kläser univentionstaff 2017-03-03 15:49:55 CET
(In reply to Alexander Kläser from comment #8)
> [...]
> I fixed this. Besides from that, I realized that obsolete entries of a HTML
> file are not removed/commented out.

Same applies to JavaScript files. After removing a translation string from the source file, the string is still present in the built po file.
Comment 10 Alexander Kläser univentionstaff 2017-03-04 07:05:52 CET
Eduard, please check. I adjusted the process_target() method in order to install the target files below debian/<packageName>. This looked fine in my tests.

I actually do not understand why not all classes posses this method.

univention-ucs-translation-template (4.2.0-4):
r77349 | Bug #43594: make sure to install mo/json files to debian/<packageName>
Comment 11 Alexander Kläser univentionstaff 2017-03-04 18:14:48 CET
I observed problems with JavaScript files being detected as HTML files. This happened in package univention-self-service with the file hook/passwordreset.js:

> $ file hook/passwordreset.js 
> hook/passwordreset.js: HTML document, ASCII text

Therefore I added in MimeChecker::get() a first test for file suffix. Python magic is then only used if the suffix is unknown.

univention-ucs-translation-template (4.2.0-5):
r77352 | Bug #43594: fix problems with mime type detection for JavaScript files
Comment 12 Alexander Kläser univentionstaff 2017-03-06 17:28:31 CET
(In reply to Alexander Kläser from comment #9)
> (In reply to Alexander Kläser from comment #8)
> > [...]
> > I fixed this. Besides from that, I realized that obsolete entries of a HTML
> > file are not removed/commented out.
> 
> Same applies to JavaScript files. After removing a translation string from
> the source file, the string is still present in the built po file.

If I understand correctly, there seems to be a logic error. The current logic does create PO entries which are merged (via xgettext --join-existing) into the already existing PO file. This PO file is then compiled into MO/JSON.

It should be:
* Create a new POT file (with empty translations) using xgettext --join-existing. 
* Merge the existing PO file with the POT file (using msgmerge)

This logic exists already in univention-ucs-translation-merge.
Comment 13 Alexander Kläser univentionstaff 2017-03-13 09:32:22 CET
*** Bug 42810 has been marked as a duplicate of this bug. ***
Comment 14 Eduard Mai univentionstaff 2017-03-20 10:39:12 CET
Rev. 77964:
The logic issues are resolved. PO can now be concatenated, which enables us to build a single PO template from mixed source types, e.g. HTML and JS files in
univention-management-console. In the future it would be beneficial to move those catalog operations to dh_umc completely and not rely on message_catalogs at all.

Package: univention-ucs-translation-template
Version: 4.2.1-0A~4.2.0.201703201036
Branch: ucs_4.2-0

TODO: changelog
Comment 15 Alexander Kläser univentionstaff 2017-03-29 15:30:41 CEST
AFAIS, this looks good now. I used it for a few packages and the output is fine.

→ VERIFIED
Comment 16 Stefan Gohmann univentionstaff 2017-04-04 18:28:41 CEST
UCS 4.2 has been released:
 https://docs.software-univention.de/release-notes-4.2-0-en.html
 https://docs.software-univention.de/release-notes-4.2-0-de.html

If this error occurs again, please use "Clone This Bug".
Comment 17 Eduard Mai univentionstaff 2017-06-16 19:16:16 CEST
*** Bug 41807 has been marked as a duplicate of this bug. ***