]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/plugins/po.mdwn
Merge commit 'schmonz/master' into cvs
[git.ikiwiki.info.git] / doc / plugins / po.mdwn
1 [[!template id=plugin name=po core=0 author="[[intrigeri]]"]]
2 [[!tag type/format]]
4 This plugin adds support for multi-lingual wikis, translated with
5 gettext, using [po4a](http://po4a.alioth.debian.org/).
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.
11 [[!toc levels=2]]
13 Introduction
14 ============
16 A language is chosen as the "master" one, and any other supported
17 language is a "slave" one.
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.
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`.
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.
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`
36 (In)Compatibility
37 =================
39 This plugin does not support the `indexpages` mode. If you don't know
40 what it is, you probably don't care.
43 Configuration
44 =============
46 Supported languages
47 -------------------
49 `po_master_language` is used to set the "master" language in
50 `ikiwiki.setup`, such as:
52         po_master_language => { 'code' => 'en', 'name' => 'English' }
54 `po_slave_languages` is used to set the list of supported "slave"
55 languages, such as:
57         po_slave_languages => { 'fr' => 'Français',
58                                 'es' => 'Español',
59                                 'de' => 'Deutsch',
60         }
62 Decide which pages are translatable
63 -----------------------------------
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.
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]].
72 Internal links
73 --------------
75 ### Links targets
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.
81 #### Default linking behavior
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.
87 #### Link to current language
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.*:
93 * `foo/destpage/index.LL.html` if `usedirs` is enabled
94 * `foo/destpage.LL.html` if `usedirs` is disabled
96 #### Link to negotiated language
98 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
99 negotiated preferred language, *i.e.* `foo/page/`.
101 (In)compatibility notes:
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.
109 Server support
110 ==============
112 Apache
113 ------
115 Using Apache `mod_negotiation` makes it really easy to have Apache
116 serve any page in the client's preferred language, if available.
118 Add 'Options MultiViews' to the wiki directory's configuration in Apache.
120 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
121 the wiki context.
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`.
127 For details, see [Apache's documentation](http://httpd.apache.org/docs/2.2/content-negotiation.html).
129 lighttpd
130 --------
132 lighttpd unfortunately does not support content negotiation.
134 **FIXME**: does `mod_magnet` provide the functionality needed to
135  emulate this?
138 Usage
139 =====
141 Templates
142 ---------
144 When `po_link_to` is not set to `negotiated`, one should replace some
145 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
146 the wiki homepage.
148 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
149 display things only on translatable or translation pages.
151 ### Display page's versions in other languages
153 The `OTHERLANGUAGES` loop provides ways to display other languages'
154 versions of the same page, and the translations' status.
156 An example of its use can be found in the default
157 `templates/page.tmpl`. In case you want to customize it, the following
158 variables are available inside the loop (for every page in):
160 * `URL` - url to the page
161 * `CODE` - two-letters language code
162 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
163 * `MASTER` - is true (1) if, and only if the page is a "master" page
164 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
166 ### Display the current translation status
168 The `PERCENTTRANSLATED` variable is set to the translation
169 completeness, expressed in percent, on "slave" pages. It is used by
170 the default `templates/page.tmpl`.
172 Additional PageSpec tests
173 -------------------------
175 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
176 additional tests that are documented [[here|ikiwiki/pagespec/po]].
178 Automatic PO file update
179 ------------------------
181 Committing changes to a "master" page:
183 1. updates the POT file and the PO files for the "slave" languages;
184    the updated PO files are then put under version control;
185 2. triggers a refresh of the corresponding HTML slave pages.
187 Also, when the plugin has just been enabled, or when a page has just
188 been declared as being translatable, the needed POT and PO files are
189 created, and the PO files are checked into version control.
191 Discussion pages and other sub-pages
192 ------------------------------------
194 Discussion should happen in the language in which the pages are
195 written for real, *i.e.* the "master" one. If discussion pages are
196 enabled, "slave" pages therefore link to the "master" page's
197 discussion page.
199 Likewise, "slave" pages are not supposed to have sub-pages;
200 [[WikiLinks|wikilink]] that appear on a "slave" page therefore link to
201 the master page's sub-pages.
203 Translating
204 -----------
206 One can edit the PO files using ikiwiki's CGI (a message-by-message
207 interface could also be implemented at some point).
209 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
210 preferred `$EDITOR`, without needing to be online.
212 Markup languages support
213 ------------------------
215 [[Markdown|mdwn]] is well supported. Some other markup languages supported
216 by ikiwiki mostly work, but some pieces of syntax are not rendered
217 correctly on the slave pages:
219 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
220   cross-references
221 * [[wikitext]]: conversion of newlines to paragraphs
222 * [[creole]]: verbatim text is wrapped, tables are broken
223 * [[html]] and LaTeX: not supported yet; the dedicated po4a modules
224   could be used to support them, but they would need a security audit
225 * other markup languages have not been tested.
227 Security
228 ========
230 [[po/discussion]] contains a detailed security analysis of this plugin
231 and its dependencies.
233 When using po4a older than 0.35, it is recommended to uninstall
234 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
235 avoid a potential denial of service.
237 TODO
238 ====
240 Better links
241 ------------
243 Once the fix to
244 [[bugs/pagetitle_function_does_not_respect_meta_titles]] from
245 [[intrigeri]]'s `meta` branch is merged into ikiwiki upstream, the
246 generated links' text will be optionally based on the page titles set
247 with the [[meta|plugins/meta]] plugin, and will thus be translatable.
248 It will also allow displaying the translation status in links to slave
249 pages. Both were implemented, and reverted in commit
250 ea753782b222bf4ba2fb4683b6363afdd9055b64, which should be reverted
251 once [[intrigeri]]'s `meta` branch is merged.
253 An integration branch, called `meta-po`, merges [[intrigeri]]'s `po`
254 and `meta` branches, and thus has this additional features.
256 Language display order
257 ----------------------
259 Jonas pointed out that one might want to control the order that links to
260 other languages are listed, for various reasons. Currently, there is no
261 order, as `po_slave_languages` is a hash. It would need to be converted
262 to an array to support this. (If twere done, twere best done quickly.)
263 --[[Joey]] 
265 Pagespecs
266 ---------
268 I was suprised that, when using the map directive, a pagespec of "*"
269 listed all the translated pages as well as regular pages. That can 
270 make a big difference to an existing wiki when po is turned on,
271 and seems generally not wanted.
272 (OTOH, you do want to match translated pages by
273 default when locking pages.) --[[Joey]]
275 Edit links on untranslated pages
276 --------------------------------
278 If a page is not translated yet, the "translated" version of it
279 displays wikilinks to other, existing (but not yet translated?)
280 pages as edit links, as if those pages do not exist. 
282 That's really confusing, especially as clicking such a link
283 brings up an edit form to create a new, english page.
285 This is with po_link_to=current or negotiated. With default, it doesn't
286 happen.. 
288 Also, this may only happen if the page being linked to is coming from an
289 underlay, and the underlays lack translation to a given language.
290 --[[Joey]] 
292 Double commits of po files
293 --------------------------
295 When adding a new english page, the po files are created, committed,
296 and then committed again. The second commit makes this change:
298         -"Content-Type: text/plain; charset=utf-8\n"
299         -"Content-Transfer-Encoding: ENCODING"
300         +"Content-Type: text/plain; charset=UTF-8\n"
301         +"Content-Transfer-Encoding: ENCODING\n"
303 Same thing happens when a change to an existing page triggers a po file
304 update. --[[Joey]] 
306 Ugly messages with empty files
307 ------------------------------
309 If there are empty .mdwn files, the po plugin displays some ugly messages.
311 Translation of directives
312 -------------------------
314 If a translated page contains a directive, it may expand to some english
315 text, or text in whatever single language ikiwiki is configured to "speak".
317 Maybe there could be a way to switch ikiwiki to speaking another language
318 when building a non-english page? Then the directives would get translated.
320 2 test suite failures
321 --------------------
323 t/po is currently failing tests 57 and 59 (and I would like to release
324 soon..) --[[Joey]] 
326 > They are failing because of commit cdc3576c8d1e (po: do not inject
327 > custom bestlink function when `po_link_to` eq `default`). The test
328 > suite changes `$config{po_link_to}`, but the `checkconfig` hook is
329 > not re-run. I could manually run it when needed in the test-suite,
330 > but this would lead to this function being injected several times,
331 > and then `$origsubs{'bestlink'}` to be sometimes set to a wrong
332 > value, which would break other parts of the test-suite. The best
333 > solution I can think of (apart of reverting this commit or disabling
334 > these two tests) is to split the test-suite into 3 parts, depending
335 > on the `$config{po_link_to}` setting, either in 3 different `.t`
336 > files, or inside the existing one and completely reset the IkiWiki
337 > environment at the start of these parts... which I did not manage to
338 > achieve in the last 2 hours :/ --[[intrigeri]]
340 >> I've reverted it. --[[Joey]] 
342 Documentation
343 -------------
345 Maybe write separate documentation depending on the people it targets:
346 translators, wiki administrators, hackers. This plugin may be complex
347 enough to deserve this.