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