]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/plugins/po.mdwn
close bug on this branch
[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' => 'Castellano',
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 ### Links appearance
111 When `po_translation_status_in_links` is enabled, the text of a link
112 to a slave pages displays this page's translation status.
114 When the `po_strictly_refresh_backlinks` setting is enabled, a page is
115 refreshed every time a backlinked page is changed. This updates the
116 translation status in links, and helps having a consistent translated
117 wiki. Beware, this make every page depend on every page that links to
118 it, which can slow everything down and bloat the dependency pagespecs.
120 Server support
121 ==============
123 Apache
124 ------
126 Using Apache `mod_negotiation` makes it really easy to have Apache
127 serve any page in the client's preferred language, if available.
128 This is the default Debian Apache configuration.
130 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
131 the wiki context.
133 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
134 language code) for the wiki context can help to ensure
135 `bla/page/index.en.html` is served as `Content-Language: LL`.
137 lighttpd
138 --------
140 lighttpd unfortunately does not support content negotiation.
142 **FIXME**: does `mod_magnet` provide the functionality needed to
143  emulate this?
146 Usage
147 =====
149 Templates
150 ---------
152 When `po_link_to` is not set to `negotiated`, one should replace some
153 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
154 the wiki homepage.
156 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
157 display things only on translatable or translation pages.
159 ### Display page's versions in other languages
161 The `OTHERLANGUAGES` loop provides ways to display other languages'
162 versions of the same page, and the translations' status.
164 One typically adds the following code to `templates/page.tmpl`:
166         <TMPL_IF NAME="OTHERLANGUAGES">
167         <div id="otherlanguages">
168           <ul>
169           <TMPL_LOOP NAME="OTHERLANGUAGES">
170             <li>
171               <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
172               <TMPL_UNLESS NAME="MASTER">
173                 (<TMPL_VAR NAME="PERCENT">&nbsp;%)
174               </TMPL_UNLESS>
175             </li>
176           </TMPL_LOOP>
177           </ul>
178         </div>
179         </TMPL_IF>
181 The following variables are available inside the loop (for every page in):
183 * `URL` - url to the page
184 * `CODE` - two-letters language code
185 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
186 * `MASTER` - is true (1) if, and only if the page is a "master" page
187 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
189 ### Display the current translation status
191 The `PERCENTTRANSLATED` variable is set to the translation
192 completeness, expressed in percent, on "slave" pages.
194 One can use it this way:
196         <TMPL_IF NAME="ISTRANSLATION">
197         <div id="percenttranslated">
198           <TMPL_VAR NAME="PERCENTTRANSLATED">
199         </div>
200         </TMPL_IF>
202 Additional PageSpec tests
203 -------------------------
205 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
206 additional tests that are documented [[here|ikiwiki/pagespec/po]].
208 Automatic PO file update
209 ------------------------
211 Committing changes to a "master" page:
213 1. updates the POT file and the PO files for the "slave" languages;
214    the updated PO files are then put under version control;
215 2. triggers a refresh of the corresponding HTML slave pages.
217 Also, when the plugin has just been enabled, or when a page has just
218 been declared as being translatable, the needed POT and PO files are
219 created, and the PO files are checked into version control.
221 Discussion pages and other sub-pages
222 ------------------------------------
224 Discussion should happen in the language in which the pages are
225 written for real, *i.e.* the "master" one. If discussion pages are
226 enabled, "slave" pages therefore link to the "master" page's
227 discussion page.
229 Likewise, "slave" pages are not supposed to have sub-pages;
230 [[WikiLinks|wikilink]] that appear on a "slave" page therefore link to
231 the master page's sub-pages.
233 Translating
234 -----------
236 One can edit the PO files using ikiwiki's CGI (a message-by-message
237 interface could also be implemented at some point).
239 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
240 preferred `$EDITOR`, without needing to be online.
242 Markup languages support
243 ------------------------
245 Markdown is well supported. Some other markup languages supported by
246 ikiwiki mostly work, but some pieces of syntax are not rendered
247 correctly on the slave pages:
249 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
250   cross-references
251 * [[wikitext]]: conversion of newlines to paragraphs
252 * [[creole]]: verbatim text is wrapped, tables are broken
253 * [[html]] and LaTeX: not supported yet; the dedicated po4a modules
254   could be used to support them, but they would need a security audit
255 * other markup languages have not been tested.
257 Security
258 ========
260 [[./security]] contains a detailed security analysis of this plugin
261 and its dependencies.
263 When using po4a older than 0.35, it is recommended to uninstall
264 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
265 avoid a potential denial of service.
267 TODO
268 ====
270 Better links
271 ------------
273 ### Page title in links
275 Using the fix to
276 [[bugs/pagetitle_function_does_not_respect_meta_titles]] from
277 [[intrigeri]]'s `meta` branch, the generated links' text is based on
278 the page titles set with the [[meta|plugins/meta]] plugin. This has to
279 be merged into ikiwiki upstream, though.
281 Robustness tests
282 ----------------
284 ### Enabling/disabling the plugin
286 * enabling the plugin with `po_translatable_pages` set to blacklist: **OK**
287 * enabling the plugin with `po_translatable_pages` set to whitelist: **OK**
288 * enabling the plugin without `po_translatable_pages` set: **OK**
289 * disabling the plugin: **OK**
291 ### Changing the plugin config
293 * adding existing pages to `po_translatable_pages`: **OK**
294 * removing existing pages from `po_translatable_pages`: **OK**
295 * adding a language to `po_slave_languages`: **OK**
296 * removing a language from `po_slave_languages`: **OK**
297 * changing `po_master_language`: **OK**
298 * replacing `po_master_language` with a language previously part of
299   `po_slave_languages`: needs two rebuilds, but **OK** (this is quite
300   a perverse test actually)
302 ### Creating/deleting/renaming pages
304 All cases of master/slave page creation/deletion/rename, both via RCS
305 and via CGI, have been tested.
307 ### Misc
309 * general test with `usedirs` disabled: **OK**
310 * general test with `indexpages` enabled: **not OK**
311 * general test with `po_link_to=default` with `userdirs` enabled: **OK**
312 * general test with `po_link_to=default` with `userdirs` disabled: **OK**
314 Misc. bugs
315 ----------
317 Documentation
318 -------------
320 Maybe write separate documentation depending on the people it targets:
321 translators, wiki administrators, hackers. This plugin may be complex
322 enough to deserve this.