1 [[!template id=plugin name=po core=0 author="[[intrigeri]]"]]
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.
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
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`
39 This plugin does not support the `indexpages` mode. If you don't know
40 what it is, you probably don't care.
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"
57 po_slave_languages => { 'fr' => 'Français',
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]].
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
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
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
106 * if the web server does not support Content Negotiation, setting
107 `po_link_to` to `negotiated` will produce a unusable website.
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 This is the default Debian Apache configuration.
119 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
122 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
123 language code) for the wiki context can help to ensure
124 `bla/page/index.en.html` is served as `Content-Language: LL`.
129 lighttpd unfortunately does not support content negotiation.
131 **FIXME**: does `mod_magnet` provide the functionality needed to
141 When `po_link_to` is not set to `negotiated`, one should replace some
142 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
145 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
146 display things only on translatable or translation pages.
148 ### Display page's versions in other languages
150 The `OTHERLANGUAGES` loop provides ways to display other languages'
151 versions of the same page, and the translations' status.
153 An example of its use can be found in the default
154 `templates/page.tmpl`. In case you want to customize it, the following
155 variables are available inside the loop (for every page in):
157 * `URL` - url to the page
158 * `CODE` - two-letters language code
159 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
160 * `MASTER` - is true (1) if, and only if the page is a "master" page
161 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
163 ### Display the current translation status
165 The `PERCENTTRANSLATED` variable is set to the translation
166 completeness, expressed in percent, on "slave" pages. It is used by
167 the default `templates/page.tmpl`.
169 Additional PageSpec tests
170 -------------------------
172 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
173 additional tests that are documented [[here|ikiwiki/pagespec/po]].
175 Automatic PO file update
176 ------------------------
178 Committing changes to a "master" page:
180 1. updates the POT file and the PO files for the "slave" languages;
181 the updated PO files are then put under version control;
182 2. triggers a refresh of the corresponding HTML slave pages.
184 Also, when the plugin has just been enabled, or when a page has just
185 been declared as being translatable, the needed POT and PO files are
186 created, and the PO files are checked into version control.
188 Discussion pages and other sub-pages
189 ------------------------------------
191 Discussion should happen in the language in which the pages are
192 written for real, *i.e.* the "master" one. If discussion pages are
193 enabled, "slave" pages therefore link to the "master" page's
196 Likewise, "slave" pages are not supposed to have sub-pages;
197 [[WikiLinks|wikilink]] that appear on a "slave" page therefore link to
198 the master page's sub-pages.
203 One can edit the PO files using ikiwiki's CGI (a message-by-message
204 interface could also be implemented at some point).
206 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
207 preferred `$EDITOR`, without needing to be online.
209 Markup languages support
210 ------------------------
212 [[Markdown|mdwn]] is well supported. Some other markup languages supported
213 by ikiwiki mostly work, but some pieces of syntax are not rendered
214 correctly on the slave pages:
216 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
218 * [[wikitext]]: conversion of newlines to paragraphs
219 * [[creole]]: verbatim text is wrapped, tables are broken
220 * [[html]] and LaTeX: not supported yet; the dedicated po4a modules
221 could be used to support them, but they would need a security audit
222 * other markup languages have not been tested.
227 [[po/discussion]] contains a detailed security analysis of this plugin
228 and its dependencies.
230 When using po4a older than 0.35, it is recommended to uninstall
231 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
232 avoid a potential denial of service.
241 [[bugs/pagetitle_function_does_not_respect_meta_titles]] from
242 [[intrigeri]]'s `meta` branch is merged into ikiwiki upstream, the
243 generated links' text will be optionally based on the page titles set
244 with the [[meta|plugins/meta]] plugin, and will thus be translatable.
245 It will also allow displaying the translation status in links to slave
246 pages. Both were implemented, and reverted in commit
247 ea753782b222bf4ba2fb4683b6363afdd9055b64, which should be reverted
248 once [[intrigeri]]'s `meta` branch is merged.
250 An integration branch, called `meta-po`, merges [[intrigeri]]'s `po`
251 and `meta` branches, and thus has thise additional features.
254 Language display order
255 ----------------------
257 Jonas pointed out that one might want to control the order that links to
258 other languages are listed, for various reasons. Currently, there is no
259 order, as `po_slave_languages` is a hash. It would need to be converted
260 to an array to support this. (If twere done, twere best done quickly.)
266 I think this plugin doesn't yet allow po files to be present in an
267 underlay to translate files also from the underlay.
269 In `istranslatablefile`, it specifically checks that
270 the file is present in srcdir.
272 Problem with this is that it precludes using po to translate
273 the basewiki (work which is well under way for Danish BTW),
274 since the translated po files cannot really be used.
276 A further problem comes if one wants to use a non-English language as the
277 `po_master_language`. It would be good to get a translated
278 basewiki, taking po files from the underlay and using them as the primary
279 page sources, but this plugin doesn't yet support that.
281 And, maybe it shouldn't? A user would not expect to see a po file when
282 editing the index page of their wiki, just because they're using a
283 different language. Instead, we might want to build localized .mdwn files
284 for the basewiki, and then ikiwiki would just use that translated underlay.
285 The when the user edits index, they get a nice mdwn file to start from.
287 So, we seem to have two cases, in one po files from the underlay should be
288 used, in the other not. Hmm. Support both?
290 > Update -- I've written po2wiki, which can spit out translated underlays
291 > in markdown format, and made the po plugin enable use of such underlays
292 > when the master language is not `en`.
298 I notice code in the scan hook that seems to assume
299 that %links will accumulate duplicate links for a page.
300 That used to be so, but the bug was fixed. Does this mean
301 that po might be replacing the only link on a page, in error?
307 Maybe write separate documentation depending on the people it targets:
308 translators, wiki administrators, hackers. This plugin may be complex
309 enough to deserve this.