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
1=== modified file 'data/templates/html/Default.html'
2--- data/templates/html/Default.html 2014-11-03 17:15:23 +0000
3+++ data/templates/html/Default.html 2016-02-16 16:20:11 +0000
4@@ -42,21 +42,21 @@
5 <!-- Header -->
6 <div class='header'>
7 [% IF navigation.prev %]
8- [ <a href='[% uri(navigation.prev) %]'>Prev</a> ]
9+ [ <a href='[% uri(navigation.prev) %]'>[% gettext("Prev") %]</a> ]
10 [% ELSE %]
11- [ <span class='insen'>Prev</span> ]
12+ [ <span class='insen'>[% gettext("Prev") %</span> ]
13 [% END %]
14
15 [% IF links.get("index") %]
16- [ <a href='[% uri(links.get("index")) %]'>Index</a> ]
17+ [ <a href='[% uri(links.get("index")) %]'>[% gettext("Index") %]</a> ]
18 [% ELSE %]
19- [ <span class='insen'>Index</span> ]
20+ [ <span class='insen'>[% gettext("Index") %]</span> ]
21 [% END %]
22
23 [% IF navigation.next %]
24- [ <a href='[% uri(navigation.next) %]'>Next</a> ]
25+ [ <a href='[% uri(navigation.next) %]'>[% gettext("Next") %]</a> ]
26 [% ELSE %]
27- [ <span class='insen'>Next</span> ]
28+ [ <span class='insen'>[% gettext("Next") %]</span> ]
29 [% END %]
30 </div>
31
32@@ -78,7 +78,7 @@
33
34 <div class='page-footer'>
35 <!--[% FOR link IN page.backlinks %]-->
36- [% IF loop.first %]<b>Backlinks:</b>[% END %]
37+ [% IF loop.first %]<b>[% gettext("Backlinks:") %]</b>[% END %]
38
39 <a href='[% uri(link) %]'>[% link.name %]</a>
40
41@@ -87,7 +87,7 @@
42
43 <!--[% FOR file IN page.attachments %]-->
44 [% IF loop.first %]
45- <b>Attachments:</b>
46+ <b>[% gettext("Attachments:") %]</b>
47 <table>
48 [% END %]
49
50
51=== modified file 'data/templates/html/Default_with_index.html'
52--- data/templates/html/Default_with_index.html 2015-06-13 15:14:18 +0000
53+++ data/templates/html/Default_with_index.html 2016-02-16 16:20:11 +0000
54@@ -51,21 +51,21 @@
55 <!-- Header -->
56 <div class='header'>
57 [% IF navigation.prev %]
58- [ <a href='[% uri(navigation.prev) %]'>Prev</a> ]
59+ [ <a href='[% uri(navigation.prev) %]'>[% gettext("Prev") %]</a> ]
60 [% ELSE %]
61- [ <span class='insen'>Prev</span> ]
62+ [ <span class='insen'>[% gettext("Prev") %]</span> ]
63 [% END %]
64
65 [% IF links.get("index") %]
66- [ <a href='[% uri(links.get("index")) %]'>Index</a> ]
67+ [ <a href='[% uri(links.get("index")) %]'>[% gettext("Index") %]</a> ]
68 [% ELSE %]
69- [ <span class='insen'>Index</span> ]
70+ [ <span class='insen'>[% gettext("Index") %]</span> ]
71 [% END %]
72
73 [% IF navigation.next %]
74- [ <a href='[% uri(navigation.next) %]'>Next</a> ]
75+ [ <a href='[% uri(navigation.next) %]'>[% gettext("Next") %]</a> ]
76 [% ELSE %]
77- [ <span class='insen'>Next</span> ]
78+ [ <span class='insen'>[% gettext("Next") %]</span> ]
79 [% END %]
80 </div>
81
82@@ -93,7 +93,7 @@
83
84 <div class='page-footer'>
85 <!--[% FOR link IN page.backlinks %]-->
86- [% IF loop.first %]<b>Backlinks:</b>[% END %]
87+ [% IF loop.first %]<b>[% gettext("Backlinks:") %]</b>[% END %]
88
89 <a href='[% uri(link) %]'>[% link.name %]</a>
90
91@@ -102,7 +102,7 @@
92
93 <!--[% FOR file IN page.attachments %]-->
94 [% IF loop.first %]
95- <b>Attachments:</b>
96+ <b>[% gettext("Attachments:") %]</b>
97 <table>
98 [% END %]
99
100
101=== modified file 'data/templates/wiki/Default.txt'
102--- data/templates/wiki/Default.txt 2011-01-31 21:23:41 +0000
103+++ data/templates/wiki/Default.txt 2016-02-16 16:20:11 +0000
104@@ -1,3 +1,2 @@
105 ======= [% page.basename %] =======
106-Created [% strftime("%A %d %B %Y") %]
107-
108+[% gettext("Created") %] [% strftime("%A %d %B %Y") %]
109
110=== modified file 'data/templates/wiki/Journal.txt'
111--- data/templates/wiki/Journal.txt 2013-01-23 20:18:04 +0000
112+++ data/templates/wiki/Journal.txt 2016-02-16 16:20:11 +0000
113@@ -19,6 +19,6 @@
114
115 [%- ELSE -%]
116 ======= [% page.basename %] =======
117-Created [% strftime("%A %d %B %Y") %]
118+[% gettext("Created") %] [% strftime("%A %d %B %Y") %]
119
120 [%- END %]
121
122=== modified file 'tools/xgettext.sh'
123--- tools/xgettext.sh 2011-02-19 16:27:44 +0000
124+++ tools/xgettext.sh 2016-02-16 16:20:11 +0000
125@@ -1,4 +1,6 @@
126 echo 'Extracting translatable strings ...'
127 find zim -name '*.py' | sort | xgettext -f - -o translations/zim.pot
128+find data/templates -name '*.txt' | sort | xgettext -j -f - -o translations/zim.pot
129+find data/templates -name '*.html' | sort | xgettext -j -f - -o translations/zim.pot
130 echo 'Extracting comments ...'
131 ./tools/extract_translator_comments.py
132
133=== modified file 'zim/templates/functions.py'
134--- zim/templates/functions.py 2015-09-26 12:26:12 +0000
135+++ zim/templates/functions.py 2016-02-16 16:20:11 +0000
136@@ -36,6 +36,7 @@
137 'strfcal': template_strfcal,
138 'html_encode': ExpressionFunction(html_encode),
139 'url_encode': ExpressionFunction(partial(url_encode, mode=URL_ENCODE_DATA)),
140+ 'gettext': template_gettext,
141 }
142
143
144@@ -67,3 +68,11 @@
145 return datetime.strfcal(format, date)
146 except:
147 logger.exception('Error in strftime "%s"', format)
148+
149+@ExpressionFunction
150+def template_gettext(string):
151+ '''Template function wrapper for gettext'''
152+ try:
153+ return (_(string))
154+ except:
155+ logger.exception('Error in gettext "%s"', string)