]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/po.mdwn
5088677c1c31bfdd645e33d6ec642fb09a11ae75
[ikiwiki.git] / doc / plugins / po.mdwn
1 [[!template id=plugin name=po core=0 author="[[intrigeri]]"]]
2 [[!tag type/format]]
3
4 This plugin adds support for multi-lingual wikis, translated with
5 gettext, using [po4a](http://po4a.alioth.debian.org/).
6
7 It depends on the Perl `Locale::Po4a::Po` library (`apt-get install po4a`).
8 As detailed bellow in the security section, `po4a` is subject to
9 denial-of-service attacks before version 0.35.
10
11 [[!toc levels=2]]
12
13 Introduction
14 ============
15
16 A language is chosen as the "master" one, and any other supported
17 language is a "slave" one.
18
19 A page written in the "master" language is a "master" page. It can be
20 of any page type supported by ikiwiki, except `po`. It does not have to be
21 named a special way: migration to this plugin does not imply any page
22 renaming work.
23
24 Example: `bla/page.mdwn` is a "master" Markdown page written in
25 English; if `usedirs` is enabled, it is rendered as
26 `bla/page/index.en.html`, else as `bla/page.en.html`.
27
28 Any translation of a "master" page into a "slave" language is called
29 a "slave" page; it is written in the gettext PO format. `po` is now
30 a page type supported by ikiwiki.
31
32 Example: `bla/page.fr.po` is the PO "message catalog" used to
33 translate `bla/page.mdwn` into French; if `usedirs` is enabled, it is
34 rendered as `bla/page/index.fr.html`, else as `bla/page.fr.html`
35
36 (In)Compatibility
37 =================
38
39 This plugin does not support the `indexpages` mode. If you don't know
40 what it is, you probably don't care.
41
42
43 Configuration
44 =============
45
46 Supported languages
47 -------------------
48
49 `po_master_language` is used to set the "master" language in
50 `ikiwiki.setup`, such as:
51
52         po_master_language => { 'code' => 'en', 'name' => 'English' }
53
54 `po_slave_languages` is used to set the list of supported "slave"
55 languages, such as:
56
57         po_slave_languages => [ 'fr|Français',
58                                 'es|Español',
59                                 'de|Deutsch',
60         ]
61
62 Decide which pages are translatable
63 -----------------------------------
64
65 The `po_translatable_pages` setting configures what pages are
66 translatable. It is a [[ikiwiki/PageSpec]], so you have lots of
67 control over what kind of pages are translatable.
68
69 The `.po` files are not considered as being translatable, so you don't need to
70 worry about excluding them explicitly from this [[ikiwiki/PageSpec]].
71
72 Internal links
73 --------------
74
75 ### Links targets
76
77 The `po_link_to` option in `ikiwiki.setup` is used to decide how
78 internal links should be generated, depending on web server features
79 and site-specific preferences.
80
81 #### Default linking behavior
82
83 If `po_link_to` is unset, or set to `default`, ikiwiki's default
84 linking behavior is preserved: `\[[destpage]]` links to the master
85 language's page.
86
87 #### Link to current language
88
89 If `po_link_to` is set to `current`, `\[[destpage]]` links to the
90 `destpage`'s version written in the current page's language, if
91 available, *i.e.*:
92
93 * `foo/destpage/index.LL.html` if `usedirs` is enabled
94 * `foo/destpage.LL.html` if `usedirs` is disabled
95
96 #### Link to negotiated language
97
98 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
99 negotiated preferred language, *i.e.* `foo/page/`.
100
101 (In)compatibility notes:
102
103 * if `usedirs` is disabled, it does not make sense to set `po_link_to`
104   to `negotiated`; this option combination is neither implemented
105   nor allowed.
106 * if the web server does not support Content Negotiation, setting
107   `po_link_to` to `negotiated` will produce a unusable website.
108
109 Server support
110 ==============
111
112 Apache
113 ------
114
115 Using Apache `mod_negotiation` makes it really easy to have Apache
116 serve any page in the client's preferred language, if available.
117
118 Add 'Options MultiViews' to the wiki directory's configuration in Apache.
119
120 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
121 the wiki context.
122
123 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
124 language code) for the wiki context can help to ensure
125 `bla/page/index.en.html` is served as `Content-Language: LL`.
126
127 For details, see [Apache's documentation](http://httpd.apache.org/docs/2.2/content-negotiation.html).
128
129 lighttpd
130 --------
131
132 Recent versions of lighttpd should be able to use
133 `$HTTP["language"]` to configure the translated pages to be served.
134
135 See [Lighttpd Issue](http://redmine.lighttpd.net/issues/show/1119)
136
137 TODO: Example
138
139 Usage
140 =====
141
142 Templates
143 ---------
144
145 When `po_link_to` is not set to `negotiated`, one should replace some
146 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
147 the wiki homepage.
148
149 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
150 display things only on translatable or translation pages.
151
152 ### Display page's versions in other languages
153
154 The `OTHERLANGUAGES` loop provides ways to display other languages'
155 versions of the same page, and the translations' status.
156
157 An example of its use can be found in the default
158 `templates/page.tmpl`. In case you want to customize it, the following
159 variables are available inside the loop (for every page in):
160
161 * `URL` - url to the page
162 * `CODE` - two-letters language code
163 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
164 * `MASTER` - is true (1) if, and only if the page is a "master" page
165 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
166
167 ### Display the current translation status
168
169 The `PERCENTTRANSLATED` variable is set to the translation
170 completeness, expressed in percent, on "slave" pages. It is used by
171 the default `templates/page.tmpl`.
172
173 Additional PageSpec tests
174 -------------------------
175
176 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
177 additional tests that are documented [[here|ikiwiki/pagespec/po]].
178
179 Automatic PO file update
180 ------------------------
181
182 Committing changes to a "master" page:
183
184 1. updates the POT file and the PO files for the "slave" languages;
185    the updated PO files are then put under version control;
186 2. triggers a refresh of the corresponding HTML slave pages.
187
188 Also, when the plugin has just been enabled, or when a page has just
189 been declared as being translatable, the needed POT and PO files are
190 created, and the PO files are checked into version control.
191
192 Discussion pages and other sub-pages
193 ------------------------------------
194
195 Discussion should happen in the language in which the pages are
196 written for real, *i.e.* the "master" one. If discussion pages are
197 enabled, "slave" pages therefore link to the "master" page's
198 discussion page.
199
200 Likewise, "slave" pages are not supposed to have sub-pages;
201 [[WikiLinks|wikilink]] that appear on a "slave" page therefore link to
202 the master page's sub-pages.
203
204 Translating
205 -----------
206
207 One can edit the PO files using ikiwiki's CGI (a message-by-message
208 interface could also be implemented at some point).
209
210 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
211 preferred `$EDITOR`, without needing to be online.
212
213 Markup languages support
214 ------------------------
215
216 [[Markdown|mdwn]] and [[html]] are well supported. Some other markup
217 languages supported by ikiwiki mostly work, but some pieces of syntax
218 are not rendered correctly on the slave pages:
219
220 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
221   cross-references
222 * [[wikitext]]: conversion of newlines to paragraphs
223 * [[creole]]: verbatim text is wrapped, tables are broken
224 * LaTeX: not supported yet; the dedicated po4a module
225   could be used to support it, but it would need a security audit
226 * other markup languages have not been tested.
227
228 Security
229 ========
230
231 [[po/discussion]] contains a detailed security analysis of this plugin
232 and its dependencies.
233
234 When using po4a older than 0.35, it is recommended to uninstall
235 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
236 avoid a potential denial of service.
237
238 TODO
239 ====
240
241 Better links
242 ------------
243
244 Once the fix to
245 [[bugs/pagetitle_function_does_not_respect_meta_titles]] from
246 [[intrigeri]]'s `meta` branch is merged into ikiwiki upstream, the
247 generated links' text will be optionally based on the page titles set
248 with the [[meta|plugins/meta]] plugin, and will thus be translatable.
249 It will also allow displaying the translation status in links to slave
250 pages. Both were implemented, and reverted in commit
251 ea753782b222bf4ba2fb4683b6363afdd9055b64, which should be reverted
252 once [[intrigeri]]'s `meta` branch is merged.
253
254 An integration branch, called `meta-po`, merges [[intrigeri]]'s `po`
255 and `meta` branches, and thus has this additional features.
256
257 Language display order
258 ----------------------
259
260 Jonas pointed out that one might want to control the order that links to
261 other languages are listed, for various reasons. Currently, there is no
262 order, as `po_slave_languages` is a hash. It would need to be converted
263 to an array to support this. (If twere done, twere best done quickly.)
264 --[[Joey]] 
265
266 > Done in my po branch, preserving backward compatibility. Please
267 > review :) --[[intrigeri]]
268
269 >> Right, well my immediate concern is that using an array to hold
270 >> hash-like pairs is not very clear to the user. It will be displayed
271 >> in a confusing way by websetup; dumping a setup file will probably
272 >> also cause it to be formatted in a confusing way. And the code
273 >> seems to assume that the array length is even, and probably blows
274 >> up if it is not.. and the value is marked safe so websetup can be
275 >> used to modify it and break that way too. --[[Joey]] 
276
277 >>> I have added a sanity check for the even array problem. This was
278 >>> the easy part.
279 >>>
280 >>> About the hash-like vs. dump and websetup issue,
281 >>> I can think of a few solutions:
282 >>>
283 >>> - keep the current hash-like pairs and unmark this setting as safe
284 >>>   for websetup: this does not solve the dump setup issue, though;
285 >>> - replace the array of pairs with an array of
286 >>>   "LANGUAGECODE|LANGUAGENAME" elements, using a pipe or whatever
287 >>>   separator seems adequate;
288 >>> - add support for ordered hashes to `$config`, websetup and
289 >>>   dumpsetup, using Tie-IxHash or any similar module;
290 >>> - replace the array of hash-like pairs with an array of real
291 >>>   pairs, such as `[ ['de', 'Deutsch'], ['fr', 'Français'] ]`; this
292 >>>   brings once again the need for `$config` to support arrays of
293 >>>   arrays, which I have already implemented in my mirrorlist branch
294 >>>   (see [[todo/mirrorlist_with_per-mirror_usedirs_settings]] for
295 >>>   details).
296 >>>
297 >>> Joey, which of these solutions do you prefer? Or another one?
298 >>> I tend to prefer the last one. --[[intrigeri]]
299
300 >>>> I prefer the pipe separator, I think. I'm concerned that there is 
301 >>>> no way to really sanely represent complex data structures in web
302 >>>> setup. --[[Joey]]
303
304 >>>>> Implemented using the pipe separator, fixed the po.t test suite
305 >>>>> accordingly. Please have a look. --[[intrigeri]]
306
307 >>>>>> Merged. I wonder if "ll: Lang" would be better than pipe? 
308
309 >>>>>>> I've no clear opinion on this one. --[[intrigeri]]
310
311 >>>>>> Also, the compatability code for HASH is not really needed,
312 >>>>>> ikiwiki has not been released using a hash for it. --[[Joey]] 
313
314 >>>>>>> The compatibility code is there to support the
315 >>>>>>> `po_slave_languages => {fr => 'Français'}` format that has
316 >>>>>>> been supported for ages. It's not there to support the
317 >>>>>>> intermediate array of hash-like pairs I proposed in the
318 >>>>>>> meantime.
319 >>>>>>>
320 >>>>>>> By the way, could you please have a look to the rest of my po
321 >>>>>>> branch? (bb22e8c4a..d98296d1db0) --[[intrigeri]]
322
323 >>>>>>>> Thought I'd already merged everything; I've got those in now.
324 >>>>>>>> --[[Joey]]
325
326 Pagespecs
327 ---------
328
329 I was suprised that, when using the map directive, a pagespec of "*"
330 listed all the translated pages as well as regular pages. That can 
331 make a big difference to an existing wiki when po is turned on,
332 and seems generally not wanted.
333 (OTOH, you do want to match translated pages by
334 default when locking pages.) --[[Joey]]
335
336 Edit links on untranslated pages
337 --------------------------------
338
339 If a page is not translated yet, the "translated" version of it
340 displays wikilinks to other, existing (but not yet translated?)
341 pages as edit links, as if those pages do not exist. 
342
343 That's really confusing, especially as clicking such a link
344 brings up an edit form to create a new, english page.
345
346 This is with po_link_to=current or negotiated. With default, it doesn't
347 happen.. 
348
349 Also, this may only happen if the page being linked to is coming from an
350 underlay, and the underlays lack translation to a given language.
351 --[[Joey]] 
352
353 > Any simple testcase to reproduce it, please? I've never seen this
354 > happen yet. --[[intrigeri]]
355
356 >> Sure, go here <http://l10n.ikiwiki.info/smiley/smileys/index.sv.html>
357 >> (Currently 0% translateed) and see the 'WikiLink' link at the bottom,
358 >> which goes to <http://l10n.ikiwiki.info/ikiwiki.cgi?page=ikiwiki/wikilink&from=smiley/smileys&do=create>
359 >> Compare with eg, the 100% translated Dansk version, where
360 >> the WikiLink link links to the English WikiLink page. --[[Joey]] 
361
362 Double commits of po files
363 --------------------------
364
365 When adding a new english page, the po files are created, committed,
366 and then committed again. The second commit makes this change:
367
368         -"Content-Type: text/plain; charset=utf-8\n"
369         -"Content-Transfer-Encoding: ENCODING"
370         +"Content-Type: text/plain; charset=UTF-8\n"
371         +"Content-Transfer-Encoding: ENCODING\n"
372
373 Same thing happens when a change to an existing page triggers a po file
374 update. --[[Joey]] 
375
376 > * The s/utf-8/UTF-8 part has been fixed.
377 > * The ENCODING\n part is due to an inconsistency in po4a, which
378 >   I've just send a patch for. --[[intrigeri]]
379
380 New pages not translatable
381 --------------------------
382
383 Today I added a new English page to l10n.ikiwiki.info. When I saved,
384 the page did not have the translation links at the top. I waited until
385 the po plugin had, in the background, created the po files, and refreshed;
386 still did not see the translation links. Only when I touched the page
387 source and refreshed did it finally add the translation links. 
388 I can reproduce this bug in a test site. --[[Joey]]
389
390 Ugly messages with empty files
391 ------------------------------
392
393 If there are empty .mdwn files, the po plugin displays some ugly messages.
394
395 > This is due to a bug in po4a (not checking definedness of a
396 > variable). One-liner patch sent. --[[intrigeri]]
397
398 Translation of directives
399 -------------------------
400
401 If a translated page contains a directive, it may expand to some english
402 text, or text in whatever single language ikiwiki is configured to "speak".
403
404 Maybe there could be a way to switch ikiwiki to speaking another language
405 when building a non-english page? Then the directives would get translated.
406
407 (We also will need this in order to use translated templates, when they are
408 available.)
409
410 Documentation
411 -------------
412
413 Maybe write separate documentation depending on the people it targets:
414 translators, wiki administrators, hackers. This plugin may be complex
415 enough to deserve this.