po plugin: slave pages link to the master's discussion page
[ikiwiki] / 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
9 Introduction
10 ============
11
12 A language is chosen as the "master" one, and any other supported
13 language is a "slave" one.
14
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
18 renaming work.
19
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`.
23
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.
27
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`
31
32
33 Configuration
34 =============
35
36 Supported languages
37 -------------------
38
39 `po_master_language` is used to set the "master" language in
40 `ikiwiki.setup`, such as:
41
42         po_master_language => { 'code' => 'en', 'name' => 'English' }
43
44 `po_slave_languages` is used to set the list of supported "slave"
45 languages, such as:
46
47         po_slave_languages => { 'fr' => 'Français',
48                                 'es' => 'Castellano',
49                                 'de' => 'Deutsch',
50         }
51
52 Decide which pages are translatable
53 -----------------------------------
54
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.
58
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]].
62
63 Internal links
64 --------------
65
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.
69
70 ### Default linking behavior
71
72 If `po_link_to` is unset, or set to `default`, ikiwiki's default
73 linking behavior is preserved: `\[[destpage]]` links to the master
74 language's page.
75
76 ### Link to current language
77
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
80 available, *i.e.*:
81
82 - `foo/destpage/index.LL.html` if `usedirs` is enabled
83 - `foo/destpage.LL.html` if `usedirs` is disabled
84
85 ### Link to negotiated language
86
87 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
88 negotiated preferred language, *i.e.* `foo/page/`.
89
90 (In)compatibility notes:
91
92 - if `usedirs` is disabled, it does not make sense to set `po_link_to`
93   to `negotiated`; this option combination is neither implemented
94   nor allowed.
95 - if the web server does not support Content Negotiation, setting
96   `po_link_to` to `negotiated` will produce a unusable website.
97
98
99 Server support
100 ==============
101
102 Apache
103 ------
104
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.
108
109 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
110 the wiki context.
111
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`.
115
116 lighttpd
117 --------
118
119 lighttpd unfortunately does not support content negotiation.
120
121 **FIXME**: does `mod_magnet` provide the functionality needed to
122  emulate this?
123
124
125 Usage
126 =====
127
128 Templates
129 ---------
130
131 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
132 display things only on translatable or translation pages.
133
134 ### Display page's versions in other languages
135
136 The `OTHERLANGUAGES` loop provides ways to display other languages'
137 versions of the same page, and the translations' status.
138
139 One typically adds the following code to `templates/page.tmpl`:
140
141         <TMPL_IF NAME="OTHERLANGUAGES">
142         <div id="otherlanguages">
143           <ul>
144           <TMPL_LOOP NAME="OTHERLANGUAGES">
145             <li>
146               <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
147               <TMPL_UNLESS NAME="MASTER">
148                 (<TMPL_VAR NAME="PERCENT">&nbsp;%)
149               </TMPL_UNLESS>
150             </li>
151           </TMPL_LOOP>
152           </ul>
153         </div>
154         </TMPL_IF>
155
156 The following variables are available inside the loop (for every page in):
157
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
163
164 ### Display the current translation status
165
166 The `PERCENTTRANSLATED` variable is set to the translation
167 completeness, expressed in percent, on "slave" pages.
168
169 One can use it this way:
170
171         <TMPL_IF NAME="ISTRANSLATION">
172         <div id="percenttranslated">
173           <TMPL_VAR NAME="PERCENTTRANSLATED">
174         </div>
175         </TMPL_IF>
176
177 Additional PageSpec tests
178 -------------------------
179
180 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
181 additional tests that are documented [[here|ikiwiki/pagespec/po]].
182
183 Automatic PO files update
184 -------------------------
185
186 Committing changes to a "master" page:
187
188 1. updates the POT file and the PO files for the supported languages
189    (this is done in the `needsbuild` hook); the updated PO files are
190    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)
194
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.
198
199 Discussion pages
200 ----------------
201
202 Discussion should happen in the language in which the pages are written for
203 real, *i.e.* the "master" one. If discussion pages are enabled, "slave" pages
204 therefore link to the "master" page's discussion page.
205
206 TODO
207 ====
208
209 OTHERLANGUAGES dependencies
210 ---------------------------
211
212 Pages using `OTHERLANGUAGES` depend on any "master" and "slave" pages
213 whose status is being displayed. It is supposed to trigger dependency
214 loops, but no practical bugs were noticed yet.
215
216 Should pages using the `OTHERLANGUAGES` template loop be declared as
217 linking to the same page in other versions? To be rigorous, they
218 should, but this may clutter the backlinks.
219
220 Security checks
221 ---------------
222
223 - `refreshpofiles` uses `system()`, whose args have to be checked more
224   thoroughly to prevent any security issue (command injection, etc.).
225 - `refreshpofiles` and `refreshpot` create new files; this may need
226   some checks, e.g. using `IkiWiki::prep_writefile()`
227
228 gettext/po4a rough corners
229 --------------------------
230
231 - fix infinite loop when synchronizing two ikiwiki (when checkouts
232   live in different directories): say bla.fr.po has been updated in
233   repo2; pulling repo2 from repo1 seems to trigger a PO update, that
234   changes bla.fr.po in repo1; then pushing repo1 to repo2 triggers
235   a PO update, that changes bla.fr.po in repo2; etc.; fixed in
236   `629968fc89bced6727981c0a1138072631751fee`?
237 - new translations created in the web interface must get proper charset/encoding
238   gettext metadata, else the next automatic PO update removes any non-ascii
239   chars; possible solution: put such metadata into the Pot file, and let it
240   propagate; should be fixed in `773de05a7a1ee68d2bed173367cf5e716884945a`, time
241   will tell.
242
243 Misc. improvements
244 ------------------
245
246 ### automatic POT/PO update
247
248 Use the `change` hook instead of `needsbuild`?
249
250 ### page titles
251
252 Use nice page titles from meta plugin in links, as inline already does.
253
254 ### websetup
255
256 Which configuration settings are safe enough for websetup?
257
258 ### parentlinks
259
260 When the wiki home page is translatable, the parentlinks plugin sets
261 `./index.html` as its translations' single parent link. Ideally, the home page's
262 translations should get no parent link at all, just like the version written in
263 the master language.
264
265 ### backlinks
266
267 If a given translatable `sourcepage.mdwn` links to \[[destpage]],
268 `sourcepage.LL.po` also link to \[[destpage]], and the latter has the master
269 page *and* all its translations listed in the backlinks.
270
271 Translation quality assurance
272 -----------------------------
273
274 Modifying a PO file via the CGI must be forbidden if the new version
275 is not a valid PO file. As a bonus, check that it provides a more
276 complete translation than the existing one.
277
278 A new `cansave` type of hook would be needed to implement this.
279
280 Note: committing to the underlying repository is a way to bypass
281 this check.
282
283 Translating online
284 ------------------
285
286 As PO is a wiki page type, we already have an online PO editor, that
287 is ikiwiki's CGI.
288
289 **FIXME** preview does not work for PO files.
290
291 A message-by-message interface could also be implemented at some
292 point; a nice way to do offline translation work (without VCS access)
293 still has to be offered, though.
294
295 Translating offline without VCS access
296 --------------------------------------
297
298 The following workflow should be made possible for translators without
299 VCS access who need to edit the PO files in another editor than a web
300 browser:
301
302 - download the page's PO file
303 - use any PO editor to update the translation
304 - upload the updated PO file
305
306 Implementation note: a generic mechanism to upload a page's source is
307 needed: it's only an alternative way to allow saving a the modified
308 page's source with the CGI.
309
310 ### Short-term workflow
311
312 A possible workaround is:
313
314 - pretend to edit the PO file online
315 - copy the PO file content from the textarea
316 - cancel the edit
317 - paste the content into a local file.
318 - edit the local file in any PO editor
319 - pretend to edit the PO file online
320 - paste the modified local file's content into the edit textarea
321 - save