]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/plugins/po.mdwn
4e7553a11c43fb053f03026dc53e91c55bfc566e
[git.ikiwiki.info.git] / doc / plugins / po.mdwn
1 [[!template id=plugin name=po core=0 author="[[intrigeri]]"]]
2 [[!tag type/format]]
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`).
9 Introduction
10 ============
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
18 renaming work.
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`
33 Configuration
34 =============
36 Supported languages
37 -------------------
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"
45 languages, such as:
47         po_slave_languages => { 'fr' => 'Français',
48                                 'es' => 'Castellano',
49                                 'de' => 'Deutsch',
50         }
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]].
63 Internal links
64 --------------
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
74 language's page.
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
80 available, *i.e.*:
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
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.
99 Server support
100 ==============
102 Apache
103 ------
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
110 the wiki context.
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`.
116 lighttpd
117 --------
119 lighttpd unfortunately does not support content negotiation.
121 **FIXME**: does `mod_magnet` provide the functionality needed to
122  emulate this?
125 Usage
126 =====
128 Templates
129 ---------
131 ### Display page's versions in other languages
133 The `OTHERLANGUAGES` loop provides ways to display other languages'
134 versions of the same page, and the translations' status.
136 One typically adds the following code to `templates/page.tmpl`:
138         <TMPL_IF NAME="OTHERLANGUAGES">
139         <div id="otherlanguages">
140           <ul>
141           <TMPL_LOOP NAME="OTHERLANGUAGES">
142             <li>
143               <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LANGUAGE"></a>
144               <TMPL_UNLESS NAME="MASTER">
145                 (<TMPL_VAR NAME="PERCENT">&nbsp;%)
146               </TMPL_UNLESS>
147             </li>
148           </TMPL_LOOP>
149           </ul>
150         </div>
151         </TMPL_IF>
153 The following variables are available inside the loop (for every page in):
155 - `URL` - url to the page
156 - `CODE` - two-letters language code
157 - `LANGUAGE` - language name (as defined in `po_slave_languages`)
158 - `MASTER` - is true (1) if, and only if the page is a "master" page
159 - `PERCENT` - for "slave" pages, is set to the translation completeness, in percents
161 ### Display the current translation status
163 The `PERCENTTRANSLATED` variable is set to the translation
164 completeness, expressed in percent, on "slave" pages.
166 Additional PageSpec tests
167 -------------------------
169 This plugin enhances the regular [[ikiwiki/PageSpec]] syntax with some
170 additional tests that are documented [[here|ikiwiki/pagespec/po]].
173 TODO
174 ====
176 OTHERLANGUAGES dependencies
177 ---------------------------
179 Pages using `OTHERLANGUAGES` must depend on any "master" and "slave"
180 pages whose status is being displayed. It will trigger dependency
181 loops; how to sort this out?
183 Should pages using the `OTHERLANGUAGES` template loop be declared as
184 linking to the same page in other versions? To be rigorous, they
185 should, but this may clutter the backlinks.
187 Automatic PO files update
188 -------------------------
190 Committing changes to a "master" page:
192 1. updates the POT file and the PO files for the supported languages;
193    this is done in the `needsbuild` hook; **FIXME**: the updated PO
194    files must then be put under version control
196 2. triggers a refresh of the corresponding HTML slave pages: this is
197    achieved by making any "slave" page dependent on the corresponding
198    "master" page, in the `needsbuild` hook.
200 **FIXME** Also, when the plugin has just been enabled, or when a page
201 has just been declared as being translatable:
203 - all the needed POT and PO files have to be created
204 - the PO files must be checked into version control
206 **FIXME** `refreshpofiles` uses `system()`, whose args have to be
207 checked more thoroughly to prevent any security issue (command
208 injection, etc.).
210 Translation quality assurance
211 -----------------------------
213 Modifying a PO file via the CGI must be forbidden if the new version
214 is not a valid PO file. As a bonus, check that it provides a more
215 complete translation than the existing one.
217 A new `cansave` type of hook would be needed to implement this.
219 Note: committing to the underlying repository is a way to bypass
220 this check.
222 Translating online
223 ------------------
225 As PO is a wiki page type, we already have an online PO editor, that
226 is ikiwiki's CGI.
228 A message-by-message interface could also be implemented at some
229 point; a nice way to do offline translation work (without VCS access)
230 still has to be offered, though.
232 Translating offline without VCS access
233 --------------------------------------
235 The following workflow should be made possible for translators without
236 VCS access who need to edit the PO files in another editor than a web
237 browser:
239 - download the page's PO file
240 - use any PO editor to update the translation
241 - upload the updated PO file
243 Implementation note: a generic mechanism to upload a page's source is
244 needed: it's only an alternative way to allow saving a the modified
245 page's source with the CGI.
247 ### Short-term workflow
249 A possible workaround is:
251 - pretend to edit the PO file online
252 - copy the PO file content from the textarea
253 - cancel the edit
254 - paste the content into a local file.
255 - edit the local file in any PO editor
256 - pretend to edit the PO file online
257 - paste the modified local file's content into the edit textarea
258 - save