]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/po.mdwn
fixed one security problem, two more need review
[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
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, except `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` files are not considered as being translatable, so you don't need to
60 worry about excluding them explicitly from this [[ikiwiki/PageSpec]].
61
62 Internal links
63 --------------
64
65 The `po_link_to` option in `ikiwiki.setup` is used to decide how
66 internal links should be generated, depending on web server features
67 and site-specific preferences.
68
69 ### Default linking behavior
70
71 If `po_link_to` is unset, or set to `default`, ikiwiki's default
72 linking behavior is preserved: `\[[destpage]]` links to the master
73 language's page.
74
75 ### Link to current language
76
77 If `po_link_to` is set to `current`, `\[[destpage]]` links to the
78 `destpage`'s version written in the current page's language, if
79 available, *i.e.*:
80
81 - `foo/destpage/index.LL.html` if `usedirs` is enabled
82 - `foo/destpage.LL.html` if `usedirs` is disabled
83
84 ### Link to negotiated language
85
86 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
87 negotiated preferred language, *i.e.* `foo/page/`.
88
89 (In)compatibility notes:
90
91 - if `usedirs` is disabled, it does not make sense to set `po_link_to`
92   to `negotiated`; this option combination is neither implemented
93   nor allowed.
94 - if the web server does not support Content Negotiation, setting
95   `po_link_to` to `negotiated` will produce a unusable website.
96
97
98 Server support
99 ==============
100
101 Apache
102 ------
103
104 Using Apache `mod_negotiation` makes it really easy to have Apache
105 serve any page in the client's preferred language, if available.
106 This is the default Debian Apache configuration.
107
108 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
109 the wiki context.
110
111 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
112 language code) for the wiki context can help to ensure
113 `bla/page/index.en.html` is served as `Content-Language: LL`.
114
115 lighttpd
116 --------
117
118 lighttpd unfortunately does not support content negotiation.
119
120 **FIXME**: does `mod_magnet` provide the functionality needed to
121  emulate this?
122
123
124 Usage
125 =====
126
127 Templates
128 ---------
129
130 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
131 display things only on translatable or translation pages.
132
133 ### Display page's versions in other languages
134
135 The `OTHERLANGUAGES` loop provides ways to display other languages'
136 versions of the same page, and the translations' status.
137
138 One typically adds the following code to `templates/page.tmpl`:
139
140         <TMPL_IF NAME="OTHERLANGUAGES">
141         <div id="otherlanguages">
142           <ul>
143           <TMPL_LOOP NAME="OTHERLANGUAGES">
144             <li>
145               <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
146               <TMPL_UNLESS NAME="MASTER">
147                 (<TMPL_VAR NAME="PERCENT">&nbsp;%)
148               </TMPL_UNLESS>
149             </li>
150           </TMPL_LOOP>
151           </ul>
152         </div>
153         </TMPL_IF>
154
155 The following variables are available inside the loop (for every page in):
156
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
162
163 ### Display the current translation status
164
165 The `PERCENTTRANSLATED` variable is set to the translation
166 completeness, expressed in percent, on "slave" pages.
167
168 One can use it this way:
169
170         <TMPL_IF NAME="ISTRANSLATION">
171         <div id="percenttranslated">
172           <TMPL_VAR NAME="PERCENTTRANSLATED">
173         </div>
174         </TMPL_IF>
175
176 Additional PageSpec tests
177 -------------------------
178
179 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
180 additional tests that are documented [[here|ikiwiki/pagespec/po]].
181
182 Automatic PO file update
183 ------------------------
184
185 Committing changes to a "master" page:
186
187 1. updates the POT file and the PO files for the supported languages;
188    the updated PO files are then put under version control
189 2. triggers a refresh of the corresponding HTML slave pages
190
191 Also, when the plugin has just been enabled, or when a page has just
192 been declared as being translatable, the needed POT and PO files are
193 created, and the PO files are checked into version control.
194
195 Discussion pages
196 ----------------
197
198 Discussion should happen in the language in which the pages are written for
199 real, *i.e.* the "master" one. If discussion pages are enabled, "slave" pages
200 therefore link to the "master" page's discussion page.
201
202 Translating
203 -----------
204
205 One can edit the PO files using ikiwiki's CGI (a message-by-message interface
206 could also be implemented at some point).
207
208 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
209 preferred `$EDITOR`, without needing to be online.
210
211 TODO
212 ====
213
214 OTHERLANGUAGES dependencies
215 ---------------------------
216
217 Pages using `OTHERLANGUAGES` depend on any "master" and "slave" pages
218 whose status is being displayed. It is supposed to trigger dependency
219 loops, but no practical bugs were noticed yet.
220
221 Should pages using the `OTHERLANGUAGES` template loop be declared as
222 linking to the same page in other versions? To be rigorous, they
223 should, but this may clutter the backlinks.
224
225 Security checks
226 ---------------
227
228 - `refreshpofiles` uses `system()`, whose args have to be checked more
229   thoroughly to prevent any security issue (command injection, etc.).
230   > Always pass `system()` a list of parameters to avoid the shell.
231   > I've checked in a change fixing that. --[[Joey]]
232 - `refreshpofiles` and `refreshpot` create new files; this may need
233   some checks, e.g. using `IkiWiki::prep_writefile()`
234 - Can any sort of directives be put in po files that will
235   cause mischief (ie, include other files, run commands, crash gettext,
236   whatever).
237 - Any security issues on running po4a on untrusted content?
238
239 gettext/po4a rough corners
240 --------------------------
241
242 - fix infinite loop when synchronizing two ikiwiki (when checkouts
243   live in different directories): say bla.fr.po has been updated in
244   repo2; pulling repo2 from repo1 seems to trigger a PO update, that
245   changes bla.fr.po in repo1; then pushing repo1 to repo2 triggers
246   a PO update, that changes bla.fr.po in repo2; etc.; fixed in
247   `629968fc89bced6727981c0a1138072631751fee`?
248 - new translations created in the web interface must get proper charset/encoding
249   gettext metadata, else the next automatic PO update removes any non-ascii
250   chars; possible solution: put such metadata into the Pot file, and let it
251   propagate; should be fixed in `773de05a7a1ee68d2bed173367cf5e716884945a`, time
252   will tell.
253
254 Misc. improvements
255 ------------------
256
257 ### preview
258
259 preview does not work for PO files.
260
261 ### automatic POT/PO update
262
263 Use the `change` hook instead of `needsbuild`?
264
265 ### page titles
266
267 Use nice page titles from meta plugin in links, as inline already does. This is
268 actually a duplicate for
269 [[bugs/pagetitle_function_does_not_respect_meta_titles]], which might be fixed
270 by something like [[todo/using_meta_titles_for_parentlinks]].
271
272 ### websetup
273
274 Which configuration settings are safe enough for websetup?
275
276 > I see no problems with `po_master_language` and `po_slave_languages`
277 > (assuming websetup handles the hashes correctly). Would not hurt to check
278 > that the values of these are legal language codes, in `checkconfig`. 
279 > `po_translatable_pages` seems entirely safe. `po_link_to` w/o usedirs
280 > causes ikiwiki to error out. If it were changed to fall back to a safe
281 > setting in this case rather than error, it would be safe.
282 > --[[Joey]]
283
284 ### parentlinks
285
286 When the wiki home page is translatable, the parentlinks plugin sets
287 `./index.html` as its translations' single parent link. Ideally, the home page's
288 translations should get no parent link at all, just like the version written in
289 the master language.
290
291 ### backlinks
292
293 If a given translatable `sourcepage.mdwn` links to \[[destpage]],
294 `sourcepage.LL.po` also link to \[[destpage]], and the latter has the master
295 page *and* all its translations listed in the backlinks.
296
297 Translation quality assurance
298 -----------------------------
299
300 Modifying a PO file via the CGI must be forbidden if the new version
301 is not a valid PO file. As a bonus, check that it provides a more
302 complete translation than the existing one.
303
304 A new `cansave` type of hook would be needed to implement this.
305
306 Note: committing to the underlying repository is a way to bypass
307 this check.