]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/po.mdwn
2b0fba628a1842170f8d4d078e3ead86e689c341
[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, and is
16 written in any supported format but PO. It does not have to be named
17 a special way: migration from/to this plugin does not imply heavy
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 `po_master_language` is used to set the master language in
37 `ikiwiki.setup`, such as:
38
39         po_master_language => { 'code' => 'en', 'name' => 'English' }
40
41 `po_slave_languages` is used to set the list of supported "slave"
42 languages, such as:
43
44         po_slave_languages => { 'fr' => { 'name' => 'Français', },
45                                 'es' => { 'name' => 'Castellano', },
46                                 'de' => { 'name' => 'Deutsch', }
47         }
48
49 Decide which pages are translatable
50 -----------------------------------
51
52 The subset of "master" pages subject to translation is configurable:
53
54 - a `[[!translatable ]]` directive, when put on a page, makes it
55   translatable
56 - to set at once a bunch of pages as being translatable, use this
57   [[ikiwiki/directive]] with the `match=PageSpec` argument.
58
59 Internal links
60 --------------
61
62 One can use the `po_link_to_` option in `ikiwiki.setup` to choose how
63 internal links should be generated, depending on web server features
64 and site-specific preferences.
65
66 ### Default linking behavior
67
68 If `po_link_to` is unset, or set to `default`, ikiwiki's default
69 linking behavior is preserved: `[[page]]` links to the master
70 language's page.
71
72 ### Link to negotiated language
73
74 If `po_link_to` is set to `negotiated`, `[[page]]` links to the
75 negotiated preferred language, *i.e.* `foo/page/`.
76
77 (In)compatibility notes:
78
79 - `po_link_to => negotiated` provides no useful behavior if `usedirs`
80   is disabled; this option combination is neither implemented nor
81   allowed
82 - `po_link_to => negotiated` provides no useful behavior if the web
83   server does not support Content Negotiation
84
85 ### Link to current language
86
87 If `po_link_to` is set to `current` and the destination page is either
88 a translatable page or a translation, `[[page]]` links to the current
89 page's language, *i.e.*:
90
91 - `foo/page/index.LL.html` if `usedirs` is enabled
92 - `foo/page.LL.html` if `usedirs` is disabled
93
94
95 Server support
96 ==============
97
98 Apache
99 ------
100
101 Using `mod_negotiation` makes it really easy to have Apache serve the
102 page in the client's preferred language, if available. This is the
103 default Debian Apache configuration.
104
105 When `usedirs` is enabled, one has to set `DirectoryIndex index` for
106 the wiki context.
107
108 Setting `DefaultLanguage LL` (replace `LL` with your default MIME
109 language) for the wiki context can be needed, to ensure
110 `bla/page/index.en.html` is served as `Content-Language: LL`.
111 **FIXME**: is it still needed with the new `.en.html` naming convention?
112
113 lighttpd
114 --------
115
116 lighttpd unfortunately does not support content negotiation.
117
118 **FIXME**: does `mod_magnet` provide the functionality needed to
119  emulate this?
120
121
122 TODO
123 ====
124
125 Optimization
126 ------------
127
128 Move `match_istranslation` and `match_istranslatable` code into helper
129 functions, and pre-compute what can be early in the build process:
130
131 - the list of translatable (master) pages
132 - for every translatable page, the list of slave pages
133
134 Display available translations
135 ------------------------------
136
137 The [[linguas|plugins/contrib/linguas]] plugin has some code that can
138 be used as a basis to display the existing translations, and allow to
139 navigate between them.
140
141 View translation status
142 -----------------------
143
144 One should be able to view some information about the translation
145 completeness, either for a given page or for the whole wiki.
146
147 This should not be too hard using gettext tools. If this is
148 implemented as a
149 [[HTML::Template|http://search.cpan.org/search?mode=dist&query=HTML%3A%3ATemplate]]
150 loop, a page using it should depend on any "master" and "slave" pages
151 whose status is being displayed.
152
153 Automatic PO files update
154 -------------------------
155
156 Committing changes to a "master" page must:
157
158 1. update the POT file and the PO files for the supported languages,
159    before putting them under version control
160 2. trigger a refresh of the corresponding HTML slave pages
161
162 The former is to be done at a time when:
163
164 - we know which "master" page was modified, and thus, which POT/PO
165   files have to be updated: the `needsbuild` hook is the first one to
166   run that provides us with the necessary information
167 - we can modify the list of pages needing a refresh; this is
168   `needsbuild` hook's job
169
170 The latter can be implemented by making any "slave" page depend on the
171 corresponding "master" page. The `add_depends` function can achieve
172 this, if used in a **FIXME** hook.
173
174 The POT files should not be published on the wiki.
175
176 UI consistency: rename "Edit" button on slave pages
177 ---------------------------------------------------
178
179 It may be surprising to some, after having pressed *Edit* on a wiki
180 page, to end up editing a strange looking PO file. The *Edit* button
181 displayed on "slave" pages must therefore be renamed *Improve
182 translation* .
183
184 Pages selection depending on language
185 -------------------------------------
186
187 To improve user navigation in a multi-lingual wiki, site developers
188 must be enabled to write:
189
190         \[[!map pages="dev/* and lang(LL)" feeds="no"]]
191
192         \[[!map pages="dev/* and currentlang()" feeds="no"]]
193
194 Translation quality assurance
195 -----------------------------
196
197 Modifying a PO file via the CGI must only be allowed if the new
198 version is a valid PO file. As a bonus, check that it provides a more
199 complete translation than the existing one.
200
201 A new `cansave` type of hook would be needed to implement this.
202
203 Note: committing to the underlying repository is a way to bypass
204 this check.
205
206 Translating online
207 ------------------
208
209 As PO is a wiki page type, we already have an online PO editor, that
210 is ikiwiki's CGI.
211
212 A message-by-message interface could also be implemented at some
213 point; a nice way to do offline translation work (without VCS access)
214 still has to be offered, though.
215
216 Translating offline without VCS access
217 --------------------------------------
218
219 The following workflow should be made possible for translators without
220 VCS access who need to edit the PO files in another editor than a web
221 browser:
222
223 - download the page's PO file
224 - use any PO editor to update the translation
225 - upload the updated PO file
226
227 Implementation note: a generic mechanism to upload a page's source is
228 needed: it's only an alternative way to allow saving a the modified
229 page's source with the CGI.
230
231 ### Short-term workflow
232
233 A possible workaround is:
234
235 - pretend to edit the PO file online
236 - copy the PO file content from the textarea
237 - cancel the edit
238 - paste the content into a local file.
239 - edit the local file in any PO editor
240 - pretend to edit the PO file online
241 - paste the modified local file's content into the edit textarea
242 - save