]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/po.mdwn
plugins/po: talk about the po4a version in the first lines
[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' => 'Castellano',
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 The `po_link_to` option in `ikiwiki.setup` is used to decide how
76 internal links should be generated, depending on web server features
77 and site-specific preferences.
78
79 ### Default linking behavior
80
81 If `po_link_to` is unset, or set to `default`, ikiwiki's default
82 linking behavior is preserved: `\[[destpage]]` links to the master
83 language's page.
84
85 ### Link to current language
86
87 If `po_link_to` is set to `current`, `\[[destpage]]` links to the
88 `destpage`'s version written in the current page's language, if
89 available, *i.e.*:
90
91 * `foo/destpage/index.LL.html` if `usedirs` is enabled
92 * `foo/destpage.LL.html` if `usedirs` is disabled
93
94 ### Link to negotiated language
95
96 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
97 negotiated preferred language, *i.e.* `foo/page/`.
98
99 (In)compatibility notes:
100
101 * if `usedirs` is disabled, it does not make sense to set `po_link_to`
102   to `negotiated`; this option combination is neither implemented
103   nor allowed.
104 * if the web server does not support Content Negotiation, setting
105   `po_link_to` to `negotiated` will produce a unusable website.
106
107
108 Server support
109 ==============
110
111 Apache
112 ------
113
114 Using Apache `mod_negotiation` makes it really easy to have Apache
115 serve any page in the client's preferred language, if available.
116 This is the default Debian Apache configuration.
117
118 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
119 the wiki context.
120
121 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
122 language code) for the wiki context can help to ensure
123 `bla/page/index.en.html` is served as `Content-Language: LL`.
124
125 lighttpd
126 --------
127
128 lighttpd unfortunately does not support content negotiation.
129
130 **FIXME**: does `mod_magnet` provide the functionality needed to
131  emulate this?
132
133
134 Usage
135 =====
136
137 Templates
138 ---------
139
140 When `po_link_to` is not set to `negotiated`, one should replace some
141 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
142 the wiki homepage.
143
144 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
145 display things only on translatable or translation pages.
146
147 ### Display page's versions in other languages
148
149 The `OTHERLANGUAGES` loop provides ways to display other languages'
150 versions of the same page, and the translations' status.
151
152 One typically adds the following code to `templates/page.tmpl`:
153
154         <TMPL_IF NAME="OTHERLANGUAGES">
155         <div id="otherlanguages">
156           <ul>
157           <TMPL_LOOP NAME="OTHERLANGUAGES">
158             <li>
159               <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
160               <TMPL_UNLESS NAME="MASTER">
161                 (<TMPL_VAR NAME="PERCENT">&nbsp;%)
162               </TMPL_UNLESS>
163             </li>
164           </TMPL_LOOP>
165           </ul>
166         </div>
167         </TMPL_IF>
168
169 The following variables are available inside the loop (for every page in):
170
171 * `URL` - url to the page
172 * `CODE` - two-letters language code
173 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
174 * `MASTER` - is true (1) if, and only if the page is a "master" page
175 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
176
177 ### Display the current translation status
178
179 The `PERCENTTRANSLATED` variable is set to the translation
180 completeness, expressed in percent, on "slave" pages.
181
182 One can use it this way:
183
184         <TMPL_IF NAME="ISTRANSLATION">
185         <div id="percenttranslated">
186           <TMPL_VAR NAME="PERCENTTRANSLATED">
187         </div>
188         </TMPL_IF>
189
190 Additional PageSpec tests
191 -------------------------
192
193 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
194 additional tests that are documented [[here|ikiwiki/pagespec/po]].
195
196 Automatic PO file update
197 ------------------------
198
199 Committing changes to a "master" page:
200
201 1. updates the POT file and the PO files for the "slave" languages;
202    the updated PO files are then put under version control;
203 2. triggers a refresh of the corresponding HTML slave pages.
204
205 Also, when the plugin has just been enabled, or when a page has just
206 been declared as being translatable, the needed POT and PO files are
207 created, and the PO files are checked into version control.
208
209 Discussion pages and other sub-pages
210 ------------------------------------
211
212 Discussion should happen in the language in which the pages are
213 written for real, *i.e.* the "master" one. If discussion pages are
214 enabled, "slave" pages therefore link to the "master" page's
215 discussion page.
216
217 Likewise, "slave" pages are not supposed to have sub-pages;
218 [[WikiLinks|wikilink]] that appear on a "slave" page therefore link to
219 the master page's sub-pages.
220
221 Translating
222 -----------
223
224 One can edit the PO files using ikiwiki's CGI (a message-by-message
225 interface could also be implemented at some point).
226
227 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
228 preferred `$EDITOR`, without needing to be online.
229
230 Markup languages support
231 ------------------------
232
233 Markdown is well supported. Some other markup languages supported by
234 ikiwiki mostly work, but some pieces of syntax are not rendered
235 correctly on the slave pages:
236
237 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
238   cross-references
239 * [[wikitext]]: conversion of newlines to paragraphs
240 * [[creole]]: verbatim text is wrapped, tables are broken
241 * [[html]] and LaTeX: not supported yet; the dedicated po4a modules
242   could be used to support them, but they would need a security audit
243 * other markup languages have not been tested.
244
245 Security
246 ========
247
248 [[./security]] contains a detailed security analysis of this plugin
249 and its dependencies.
250
251 When using po4a older than 0.35, it is recommended to uninstall
252 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
253 avoid a potential denial of service.
254
255 TODO
256 ====
257
258 Better links
259 ------------
260
261 ### Page title in links
262
263 Using the fix to
264 [[bugs/pagetitle_function_does_not_respect_meta_titles]] from
265 [[intrigeri]]'s `meta` branch, the generated links' text is based on
266 the page titles set with the [[meta|plugins/meta]] plugin. This has to
267 be merged into ikiwiki upstream, though.
268
269 Robustness tests
270 ----------------
271
272 ### Enabling/disabling the plugin
273
274 * enabling the plugin with `po_translatable_pages` set to blacklist: **OK**
275 * enabling the plugin with `po_translatable_pages` set to whitelist: **OK**
276 * enabling the plugin without `po_translatable_pages` set: **OK**
277 * disabling the plugin: **OK**
278
279 ### Changing the plugin config
280
281 * adding existing pages to `po_translatable_pages`: **OK**
282 * removing existing pages from `po_translatable_pages`: **OK**
283 * adding a language to `po_slave_languages`: **OK**
284 * removing a language from `po_slave_languages`: **OK**
285 * changing `po_master_language`: **OK**
286 * replacing `po_master_language` with a language previously part of
287   `po_slave_languages`: needs two rebuilds, but **OK** (this is quite
288   a perverse test actually)
289
290 ### Creating/deleting/renaming pages
291
292 All cases of master/slave page creation/deletion/rename, both via RCS
293 and via CGI, have been tested.
294
295 ### Misc
296
297 * general test with `usedirs` disabled: **OK**
298 * general test with `indexpages` enabled: **not OK**
299 * general test with `po_link_to=default` with `userdirs` enabled: **OK**
300 * general test with `po_link_to=default` with `userdirs` disabled: **OK**
301
302 Misc. bugs
303 ----------
304
305 Documentation
306 -------------
307
308 Maybe write separate documentation depending on the people it targets:
309 translators, wiki administrators, hackers. This plugin may be complex
310 enough to deserve this.