Zim

Merge lp:~jsauer-deactivatedaccount/zim/translatable-templates into lp:~jaap.karssenberg/zim/pyzim

Proposed by Jens Sauer
Status: Merged
Merged at revision: 824
Proposed branch: lp:~jsauer-deactivatedaccount/zim/translatable-templates
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 155 lines (+29/-19)
6 files modified
data/templates/html/Default.html (+8/-8)
data/templates/html/Default_with_index.html (+8/-8)
data/templates/wiki/Default.txt (+1/-2)
data/templates/wiki/Journal.txt (+1/-1)
tools/xgettext.sh (+2/-0)
zim/templates/functions.py (+9/-0)
To merge this branch: bzr merge lp:~jsauer-deactivatedaccount/zim/translatable-templates
Reviewer Review Type Date Requested Status
Jaap Karssenberg Pending
Review via email: mp+286200@code.launchpad.net

Description of the change

Implement translatable templates

Translatable text can now marked with [% gettext("text") %]
in templates.
Modify the html and wiki templates to use the new feature and
tools/xgettext.sh to extract the strings from the files.

To post a comment you must log in.
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Looks good, merged in trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/templates/html/Default.html'
--- data/templates/html/Default.html 2014-11-03 17:15:23 +0000
+++ data/templates/html/Default.html 2016-02-16 16:20:11 +0000
@@ -42,21 +42,21 @@
42<!-- Header -->42<!-- Header -->
43<div class='header'>43<div class='header'>
44[% IF navigation.prev %]44[% IF navigation.prev %]
45 [ <a href='[% uri(navigation.prev) %]'>Prev</a> ]45 [ <a href='[% uri(navigation.prev) %]'>[% gettext("Prev") %]</a> ]
46[% ELSE %]46[% ELSE %]
47 [ <span class='insen'>Prev</span> ]47 [ <span class='insen'>[% gettext("Prev") %</span> ]
48[% END %]48[% END %]
4949
50[% IF links.get("index") %]50[% IF links.get("index") %]
51 [ <a href='[% uri(links.get("index")) %]'>Index</a> ]51 [ <a href='[% uri(links.get("index")) %]'>[% gettext("Index") %]</a> ]
52[% ELSE %]52[% ELSE %]
53 [ <span class='insen'>Index</span> ]53 [ <span class='insen'>[% gettext("Index") %]</span> ]
54[% END %]54[% END %]
5555
56[% IF navigation.next %]56[% IF navigation.next %]
57 [ <a href='[% uri(navigation.next) %]'>Next</a> ]57 [ <a href='[% uri(navigation.next) %]'>[% gettext("Next") %]</a> ]
58[% ELSE %]58[% ELSE %]
59 [ <span class='insen'>Next</span> ]59 [ <span class='insen'>[% gettext("Next") %]</span> ]
60[% END %]60[% END %]
61</div>61</div>
6262
@@ -78,7 +78,7 @@
7878
79 <div class='page-footer'>79 <div class='page-footer'>
80 <!--[% FOR link IN page.backlinks %]-->80 <!--[% FOR link IN page.backlinks %]-->
81 [% IF loop.first %]<b>Backlinks:</b>[% END %]81 [% IF loop.first %]<b>[% gettext("Backlinks:") %]</b>[% END %]
8282
83 <a href='[% uri(link) %]'>[% link.name %]</a>83 <a href='[% uri(link) %]'>[% link.name %]</a>
8484
@@ -87,7 +87,7 @@
8787
88 <!--[% FOR file IN page.attachments %]-->88 <!--[% FOR file IN page.attachments %]-->
89 [% IF loop.first %]89 [% IF loop.first %]
90 <b>Attachments:</b>90 <b>[% gettext("Attachments:") %]</b>
91 <table>91 <table>
92 [% END %]92 [% END %]
9393
9494
=== modified file 'data/templates/html/Default_with_index.html'
--- data/templates/html/Default_with_index.html 2015-06-13 15:14:18 +0000
+++ data/templates/html/Default_with_index.html 2016-02-16 16:20:11 +0000
@@ -51,21 +51,21 @@
51<!-- Header -->51<!-- Header -->
52<div class='header'>52<div class='header'>
53[% IF navigation.prev %]53[% IF navigation.prev %]
54 [ <a href='[% uri(navigation.prev) %]'>Prev</a> ]54 [ <a href='[% uri(navigation.prev) %]'>[% gettext("Prev") %]</a> ]
55[% ELSE %]55[% ELSE %]
56 [ <span class='insen'>Prev</span> ]56 [ <span class='insen'>[% gettext("Prev") %]</span> ]
57[% END %]57[% END %]
5858
59[% IF links.get("index") %]59[% IF links.get("index") %]
60 [ <a href='[% uri(links.get("index")) %]'>Index</a> ]60 [ <a href='[% uri(links.get("index")) %]'>[% gettext("Index") %]</a> ]
61[% ELSE %]61[% ELSE %]
62 [ <span class='insen'>Index</span> ]62 [ <span class='insen'>[% gettext("Index") %]</span> ]
63[% END %]63[% END %]
6464
65[% IF navigation.next %]65[% IF navigation.next %]
66 [ <a href='[% uri(navigation.next) %]'>Next</a> ]66 [ <a href='[% uri(navigation.next) %]'>[% gettext("Next") %]</a> ]
67[% ELSE %]67[% ELSE %]
68 [ <span class='insen'>Next</span> ]68 [ <span class='insen'>[% gettext("Next") %]</span> ]
69[% END %]69[% END %]
70</div>70</div>
7171
@@ -93,7 +93,7 @@
9393
94 <div class='page-footer'>94 <div class='page-footer'>
95 <!--[% FOR link IN page.backlinks %]-->95 <!--[% FOR link IN page.backlinks %]-->
96 [% IF loop.first %]<b>Backlinks:</b>[% END %]96 [% IF loop.first %]<b>[% gettext("Backlinks:") %]</b>[% END %]
9797
98 <a href='[% uri(link) %]'>[% link.name %]</a>98 <a href='[% uri(link) %]'>[% link.name %]</a>
9999
@@ -102,7 +102,7 @@
102102
103 <!--[% FOR file IN page.attachments %]-->103 <!--[% FOR file IN page.attachments %]-->
104 [% IF loop.first %]104 [% IF loop.first %]
105 <b>Attachments:</b>105 <b>[% gettext("Attachments:") %]</b>
106 <table>106 <table>
107 [% END %]107 [% END %]
108108
109109
=== modified file 'data/templates/wiki/Default.txt'
--- data/templates/wiki/Default.txt 2011-01-31 21:23:41 +0000
+++ data/templates/wiki/Default.txt 2016-02-16 16:20:11 +0000
@@ -1,3 +1,2 @@
1======= [% page.basename %] =======1======= [% page.basename %] =======
2Created [% strftime("%A %d %B %Y") %]2[% gettext("Created") %] [% strftime("%A %d %B %Y") %]
3
43
=== modified file 'data/templates/wiki/Journal.txt'
--- data/templates/wiki/Journal.txt 2013-01-23 20:18:04 +0000
+++ data/templates/wiki/Journal.txt 2016-02-16 16:20:11 +0000
@@ -19,6 +19,6 @@
1919
20[%- ELSE -%]20[%- ELSE -%]
21======= [% page.basename %] =======21======= [% page.basename %] =======
22Created [% strftime("%A %d %B %Y") %]22[% gettext("Created") %] [% strftime("%A %d %B %Y") %]
2323
24[%- END %]24[%- END %]
2525
=== modified file 'tools/xgettext.sh'
--- tools/xgettext.sh 2011-02-19 16:27:44 +0000
+++ tools/xgettext.sh 2016-02-16 16:20:11 +0000
@@ -1,4 +1,6 @@
1echo 'Extracting translatable strings ...'1echo 'Extracting translatable strings ...'
2find zim -name '*.py' | sort | xgettext -f - -o translations/zim.pot2find zim -name '*.py' | sort | xgettext -f - -o translations/zim.pot
3find data/templates -name '*.txt' | sort | xgettext -j -f - -o translations/zim.pot
4find data/templates -name '*.html' | sort | xgettext -j -f - -o translations/zim.pot
3echo 'Extracting comments ...'5echo 'Extracting comments ...'
4./tools/extract_translator_comments.py6./tools/extract_translator_comments.py
57
=== modified file 'zim/templates/functions.py'
--- zim/templates/functions.py 2015-09-26 12:26:12 +0000
+++ zim/templates/functions.py 2016-02-16 16:20:11 +0000
@@ -36,6 +36,7 @@
36 'strfcal': template_strfcal,36 'strfcal': template_strfcal,
37 'html_encode': ExpressionFunction(html_encode),37 'html_encode': ExpressionFunction(html_encode),
38 'url_encode': ExpressionFunction(partial(url_encode, mode=URL_ENCODE_DATA)),38 'url_encode': ExpressionFunction(partial(url_encode, mode=URL_ENCODE_DATA)),
39 'gettext': template_gettext,
39 }40 }
4041
4142
@@ -67,3 +68,11 @@
67 return datetime.strfcal(format, date)68 return datetime.strfcal(format, date)
68 except:69 except:
69 logger.exception('Error in strftime "%s"', format)70 logger.exception('Error in strftime "%s"', format)
71
72@ExpressionFunction
73def template_gettext(string):
74 '''Template function wrapper for gettext'''
75 try:
76 return (_(string))
77 except:
78 logger.exception('Error in gettext "%s"', string)