]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/po.mdwn
license analysis; another possibility
[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 => 'en|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|Español',
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 ### Links targets
76
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.
80
81 #### Default linking behavior
82
83 If `po_link_to` is unset, or set to `default`, ikiwiki's default
84 linking behavior is preserved: `\[[destpage]]` links to the master
85 language's page.
86
87 #### Link to current language
88
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
91 available, *i.e.*:
92
93 * `foo/destpage/index.LL.html` if `usedirs` is enabled
94 * `foo/destpage.LL.html` if `usedirs` is disabled
95
96 #### Link to negotiated language
97
98 If `po_link_to` is set to `negotiated`, `\[[page]]` links to the
99 negotiated preferred language, *i.e.* `foo/page/`.
100
101 (In)compatibility notes:
102
103 * if `usedirs` is disabled, it does not make sense to set `po_link_to`
104   to `negotiated`; this option combination is neither implemented
105   nor allowed.
106 * if the web server does not support Content Negotiation, setting
107   `po_link_to` to `negotiated` will produce a unusable website.
108
109 Server support
110 ==============
111
112 Apache
113 ------
114
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
118 Add 'Options MultiViews' to the wiki directory's configuration in Apache.
119
120 When `usedirs` is enabled, you should also set `DirectoryIndex index`.
121
122 These settings are also recommended, in order to avoid serving up rss files
123 as index pages:
124
125         AddType application/rss+xml;qs=0.8 .rss
126         AddType application/atom+xml;qs=0.8 .atom
127
128 For details, see [Apache's documentation](http://httpd.apache.org/docs/2.2/content-negotiation.html).
129
130 lighttpd
131 --------
132
133 Recent versions of lighttpd should be able to use
134 `$HTTP["language"]` to configure the translated pages to be served.
135
136 See [Lighttpd Issue](http://redmine.lighttpd.net/issues/show/1119)
137
138 TODO: Example
139
140 Usage
141 =====
142
143 Templates
144 ---------
145
146 When `po_link_to` is not set to `negotiated`, one should replace some
147 occurrences of `BASEURL` with `HOMEPAGEURL` to get correct links to
148 the wiki homepage.
149
150 The `ISTRANSLATION` and `ISTRANSLATABLE` variables can be used to
151 display things only on translatable or translation pages.
152
153 The `LANG_CODE` and `LANG_NAME` variables can respectively be used to
154 display the current page's language code and pretty name.
155
156 ### Display page's versions in other languages
157
158 The `OTHERLANGUAGES` loop provides ways to display other languages'
159 versions of the same page, and the translations' status.
160
161 An example of its use can be found in the default
162 `templates/page.tmpl`. In case you want to customize it, the following
163 variables are available inside the loop (for every page in):
164
165 * `URL` - url to the page
166 * `CODE` - two-letters language code
167 * `LANGUAGE` - language name (as defined in `po_slave_languages`)
168 * `MASTER` - is true (1) if, and only if the page is a "master" page
169 * `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
170
171 ### Display the current translation status
172
173 The `PERCENTTRANSLATED` variable is set to the translation
174 completeness, expressed in percent, on "slave" pages. It is used by
175 the default `templates/page.tmpl`.
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 file update
184 ------------------------
185
186 Committing changes to a "master" page:
187
188 1. updates the POT file and the PO files for the "slave" languages;
189    the updated PO files are then put under version control;
190 2. triggers a refresh of the corresponding HTML slave pages.
191
192 Also, when the plugin has just been enabled, or when a page has just
193 been declared as being translatable, the needed POT and PO files are
194 created, and the PO files are checked into version control.
195
196 Discussion pages and other sub-pages
197 ------------------------------------
198
199 Discussion should happen in the language in which the pages are
200 written for real, *i.e.* the "master" one. If discussion pages are
201 enabled, "slave" pages therefore link to the "master" page's
202 discussion page.
203
204 Likewise, "slave" pages are not supposed to have sub-pages;
205 [[WikiLinks|ikiwiki/wikilink]] that appear on a "slave" page therefore link to
206 the master page's sub-pages.
207
208 Translating
209 -----------
210
211 One can edit the PO files using ikiwiki's CGI (a message-by-message
212 interface could also be implemented at some point).
213
214 If [[tips/untrusted_git_push]] is setup, one can edit the PO files in one's
215 preferred `$EDITOR`, without needing to be online.
216
217 Markup languages support
218 ------------------------
219
220 [[Markdown|mdwn]] and [[html]] are well supported. Some other markup
221 languages supported by ikiwiki mostly work, but some pieces of syntax
222 are not rendered correctly on the slave pages:
223
224 * [[reStructuredText|rst]]: anonymous hyperlinks and internal
225   cross-references
226 * [[wikitext]]: conversion of newlines to paragraphs
227 * [[creole]]: verbatim text is wrapped, tables are broken
228 * LaTeX: not supported yet; the dedicated po4a module
229   could be used to support it, but it would need a security audit
230 * other markup languages have not been tested.
231
232 Security
233 ========
234
235 [[po/discussion]] contains a detailed security analysis of this plugin
236 and its dependencies.
237
238 When using po4a older than 0.35, it is recommended to uninstall
239 `Text::WrapI18N` (Debian package `libtext-wrapi18n-perl`), in order to
240 avoid a potential denial of service.
241
242 BUGS
243 ====
244
245 [[!inline pages="bugs/po:* and !bugs/done and !link(bugs/done) and !bugs/*/*"
246 feeds=no actions=no archive=yes show=0]]
247
248 TODO
249 ====
250
251 [[!inline pages="todo/po:* and !todo/done and !link(todo/done) and !todo/*/*"
252 feeds=no actions=no archive=yes show=0]]