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`).
12 A language is chosen as the "master" one, and any other supported
13 language is a "slave" one.
15 A page written in the "master" language is a "master" page. It can be
16 of any page type supported by ikiwiki, but PO. It does not have to be
17 named a special way: migration to this plugin does not imply any page
20 Example: `bla/page.mdwn` is a "master" Markdown page written in
21 English; if `usedirs` is enabled, it is rendered as
22 `bla/page/index.en.html`, else as `bla/page.en.html`.
24 Any translation of a "master" page into a "slave" language is called
25 a "slave" page; it is written in the gettext PO format. PO is now
26 a page type supported by ikiwiki.
28 Example: `bla/page.fr.po` is the PO "message catalog" used to
29 translate `bla/page.mdwn` into French; if `usedirs` is enabled, it is
30 rendered as `bla/page/index.fr.html`, else as `bla/page.fr.html`
39 `po_master_language` is used to set the "master" language in
40 `ikiwiki.setup`, such as:
42 po_master_language => { 'code' => 'en', 'name' => 'English' }
44 `po_slave_languages` is used to set the list of supported "slave"
47 po_slave_languages => { 'fr' => 'Français',
52 Decide which pages are translatable
53 -----------------------------------
55 The `po_translatable_pages` setting configures what pages are
56 translatable. It is a [[ikiwiki/PageSpec]], so you have lots of
57 control over what kind of pages are translatable.
59 The PO translations files are anyway not considered as being
60 translatable, so you don't need to worry about excluding them
61 explicitly from this [[ikiwiki/PageSpec]].
66 The `po_link_to` option in `ikiwiki.setup` is used to decide how
67 internal links should be generated, depending on web server features
68 and site-specific preferences.
70 ### Default linking behavior
72 If `po_link_to` is unset, or set to `default`, ikiwiki's default
73 linking behavior is preserved: `\[[destpage]]` links to the master
76 ### Link to current language
78 If `po_link_to` is set to `current`, `\[[destpage]]` links to the
79 `destpage`'s version written in the current page's language, if
82 - `foo/destpage/index.LL.html` if `usedirs` is enabled
83 - `foo/destpage.LL.html` if `usedirs` is disabled
85 ### Link to negotiated language
87 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
88 negotiated preferred language, *i.e.* `foo/page/`.
90 (In)compatibility notes:
92 - if `usedirs` is disabled, it does not make sense to set `po_link_to`
93 to `negotiated`; this option combination is neither implemented
95 - if the web server does not support Content Negotiation, setting
96 `po_link_to` to `negotiated` will produce a unusable website.
105 Using Apache `mod_negotiation` makes it really easy to have Apache
106 serve any page in the client's preferred language, if available.
107 This is the default Debian Apache configuration.
109 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
112 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
113 language code) for the wiki context can help to ensure
114 `bla/page/index.en.html` is served as `Content-Language: LL`.
119 lighttpd unfortunately does not support content negotiation.
121 **FIXME**: does `mod_magnet` provide the functionality needed to
131 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
132 display things only on translatable or translation pages.
134 ### Display page's versions in other languages
136 The `OTHERLANGUAGES` loop provides ways to display other languages'
137 versions of the same page, and the translations' status.
139 One typically adds the following code to `templates/page.tmpl`:
141 <TMPL_IF NAME="OTHERLANGUAGES">
142 <div id="otherlanguages">
144 <TMPL_LOOP NAME="OTHERLANGUAGES">
146 <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
147 <TMPL_UNLESS NAME="MASTER">
148 (<TMPL_VAR NAME="PERCENT"> %)
156 The following variables are available inside the loop (for every page in):
158 - `URL` - url to the page
159 - `CODE` - two-letters language code
160 - `LANGUAGE` - language name (as defined in `po_slave_languages`)
161 - `MASTER` - is true (1) if, and only if the page is a "master" page
162 - `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
164 ### Display the current translation status
166 The `PERCENTTRANSLATED` variable is set to the translation
167 completeness, expressed in percent, on "slave" pages.
169 One can use it this way:
171 <TMPL_IF NAME="ISTRANSLATION">
172 <div id="percenttranslated">
173 <TMPL_VAR NAME="PERCENTTRANSLATED">
177 Additional PageSpec tests
178 -------------------------
180 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
181 additional tests that are documented [[here|ikiwiki/pagespec/po]].
183 Automatic PO files update
184 -------------------------
186 Committing changes to a "master" page:
188 1. updates the POT file, as well as the PO files for the "slave"
189 languages (this is done in the `needsbuild` hook); the updated PO
190 files are then put under version control;
191 2. triggers a refresh of the corresponding HTML slave pages (this is
192 achieved by making any "slave" page dependent on the corresponding
193 "master" page, in the `needsbuild` hook).
195 Also, when the plugin has just been enabled, or when a page has just
196 been declared as being translatable, the needed POT and PO files are
197 created, and the PO files are checked into version control.
202 Discussion should happen in the language in which the pages are
203 written for real, *i.e.* the "master" one. If discussion pages are
204 enabled, "slave" pages therefore link to the "master" page's
210 One can edit the PO files using ikiwiki's CGI (a message-by-message
211 interface could also be implemented at some point).
213 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in
214 her preferred `$EDITOR`, without needing to be online.
222 - `refreshpofiles` uses `system()`, whose args have to be checked more
223 thoroughly to prevent any security issue (command injection, etc.).
224 - `refreshpofiles` and `refreshpot` create new files; this may need
225 some checks, e.g. using `IkiWiki::prep_writefile()`
227 gettext/po4a rough corners
228 --------------------------
230 - fix infinite loop when synchronizing two ikiwiki (when checkouts
231 live in different directories): say bla.fr.po has been updated in
232 repo2; pulling repo2 from repo1 seems to trigger a PO update, that
233 changes bla.fr.po in repo1; then pushing repo1 to repo2 triggers
234 a PO update, that changes bla.fr.po in repo2; etc.; fixed in
235 `629968fc89bced6727981c0a1138072631751fee`?
236 - new translations created in the web interface must get proper
237 charset/encoding gettext metadata, else the next automatic PO update
238 removes any non-ascii chars; possible solution: put such metadata
239 into the Pot file, and let it propagate; should be fixed in
240 `773de05a7a1ee68d2bed173367cf5e716884945a`, time will tell.
245 ### automatic POT/PO update
247 - Use the `change` hook instead of `needsbuild`?
248 - Fix (apparently harmless) undefined values that pollute logs when
249 saving a master page in the CGI
253 Use nice page titles from meta plugin in links, as inline already
254 does. This is actually a duplicate for
255 [[bugs/pagetitle_function_does_not_respect_meta_titles]], which might
256 be fixed by something like [[todo/using_meta_titles_for_parentlinks]].
260 Which configuration settings are safe enough for websetup?
264 When the wiki home page is translatable, the parentlinks plugin sets
265 `./index.html` as its translations' single parent link. Ideally, the
266 home page's translations should get no parent link at all, just like
267 the version written in the master language.
271 If a given translatable `sourcepage.mdwn` links to \[[destpage]],
272 `sourcepage.LL.po` also link to \[[destpage]], and the latter has the
273 master page *and* all its translations listed in the backlinks.
275 Translation quality assurance
276 -----------------------------
278 Modifying a PO file via the CGI must be forbidden if the new version
279 is not a valid PO file. As a bonus, check that it provides a more
280 complete translation than the existing one.
282 A new `cansave` type of hook would be needed to implement this.
284 Note: committing to the underlying repository is a way to bypass