]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/md/dev/Translations.md
**General rewording, proof-reading, deduplication, shortening, reordering, simplifica...
[github/shaarli/Shaarli.git] / doc / md / dev / Translations.md
CommitLineData
1a47014f
A
1## Translations
2
3Shaarli supports [gettext](https://www.gnu.org/software/gettext/manual/gettext.html) translations
4since `>= v0.9.2`.
5
6Note that only the `default` theme supports translations.
7
8### Contributing
9
91a21c27 10We encourage the community to contribute to Shaarli translations, either by improving existing translations or submitting a new language.
1a47014f 11
91a21c27 12Contributing to the translation does not require software development knowledge.
1a47014f 13
91a21c27 14Please submit a pull request with the `.po` file updated/created. Note that the compiled file (`.mo`) is not stored on the repository, and is generated during the release process.
1a47014f 15
1a47014f 16
91a21c27 17### How to
1a47014f 18
91a21c27 19Install [Poedit](https://poedit.net/) (used to extract strings to translate from the PHP source code, and generate `.po` files).
1a47014f 20
91a21c27 21Due to the usage of a template engine, it's important to generate PHP cache files to extract every translatable string. You can either use [this script](https://gist.github.com/ArthurHoaro/5d0323f758ab2401ef444a53f54e9a07) (recommended) or visit every template page in your browser to generate cache files, while logged in. Here is a list :
1a47014f
A
22
23```
24http://<replace_domain>/
91a21c27 25http://<replace_domain>/login
26http://<replace_domain>/daily
27http://<replace_domain>/tags/cloud
28http://<replace_domain>/tags/list
29http://<replace_domain>/picture-wall
1a47014f 30http://<replace_domain>/?nonope
9c75f877
A
31http://<replace_domain>/admin/add-shaare
32http://<replace_domain>/admin/password
8e9169ce 33http://<replace_domain>/admin/tags
9c75f877
A
34http://<replace_domain>/admin/configure
35http://<replace_domain>/admin/tools
8e9169ce 36http://<replace_domain>/admin/shaare
c70ff64a 37http://<replace_domain>/admin/export
78657347 38http://<replace_domain>/admin/import
1b8620b1 39http://<replace_domain>/admin/plugins
1a47014f
A
40```
41
1a47014f 42
91a21c27 43#### Improve existing translations
1a47014f 44
91a21c27 45- In Poedit, click on "Edit a Translation
46- Open `inc/languages/<lang>/LC_MESSAGES/shaarli.po` under Shaarli's directory
47- The existing list of translatable strings should load
48- Click on the "Update" button.
49- Start editing translations.
1a47014f
A
50
51![poedit-screenshot](images/poedit-1.jpg)
52
53Save when you're done, then you can submit a pull request containing the updated `shaarli.po`.
54
1a47014f 55
91a21c27 56#### Add a new language
1a47014f 57
91a21c27 58- In Poedit select "Create New Translation"
59- Open `inc/languages/<lang>/LC_MESSAGES/shaarli.po` under Shaarli's directory
60- Select the language you want to create.
61- Click on `File > Save as...`, save your file in `<shaarli directory>/inc/language/<new language>/LC_MESSAGES/shaarli.po` (`<new language>` here should be the language code respecting the [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-2) format in lowercase - e.g. `de` for German)
62- Click on the "Update" button
63- Start editing translations.
1a47014f
A
64
65Save when you're done, then you can submit a pull request containing the new `shaarli.po`.
66
91a21c27 67
9e4cc28e 68### Theme translations
68c6afc5 69
91a21c27 70[Theme](Theming) translation extensions are loaded automatically if they're present.
68c6afc5
A
71
72As a theme developer, all you have to do is to add the `.po` and `.mo` compiled file like this:
73
91a21c27 74```
75tpl/<theme name>/language/<lang>/LC_MESSAGES/<theme name>.po
76tpl/<theme name>/language/<lang>/LC_MESSAGES/<theme name>.mo
77```
68c6afc5 78
9e4cc28e 79Where `<lang>` is the ISO 3166-1 alpha-2 language code.
91a21c27 80
68c6afc5
A
81Read the following section "Extend Shaarli's translation" to learn how to generate those files.
82
91a21c27 83
1a47014f
A
84### Extend Shaarli's translation
85
86If you're writing a custom theme, or a non official plugin, you might want to use the translation system,
87but you won't be able to able to override Shaarli's translation.
88
89However, you can add your own translation domain which extends the main translation list.
90
91> Note that you can find a live example of translation extension in the `demo_plugin`.
92
93First, create your translation files tree directory:
94
95```
96<your_module>/languages/<ISO 3166-1 alpha-2 language code>/LC_MESSAGES/
97```
98
99Your `.po` files must be named like your domain. E.g. if your translation domain is `my_theme`, then your file will be
100`my_theme.po`.
101
9e4cc28e 102Users have to register your extension in their configuration with the parameter
1a47014f
A
103`translation.extensions.<domain>: <translation files path>`.
104
105Example:
106
107```php
108if (! $conf->exists('translation.extensions.my_theme')) {
109 $conf->set('translation.extensions.my_theme', '<your_module>/languages/');
110 $conf->write(true);
111}
112```
113
114> Note that the page needs to be reloaded after the registration.
115
116It is then recommended to create a custom translation function which will call the `t()` function with your domain.
117For example :
118
119```php
120function my_theme_t($text, $nText = '', $nb = 1)
121{
122 return t($text, $nText, $nb, 'my_theme'); // the last parameter is your translation domain.
123}
124```
125
126All strings which can be translated should be processed through your function:
127
128```php
129my_theme_t('Comment');
130my_theme_t('Comment', 'Comments', 2);
131```
132
133Or in templates:
134
135```php
136{'Comment'|my_theme_t}
137{function="my_theme_t('Comment', 'Comments', 2)"}
138```
139
140> Note than in template, you need to visit your page at least once to generate a cache file.
141
142When you're done, open Poedit and load translation strings from sources:
143
144 1. `File > New`
145 2. Choose your language
146 3. Save your `PO` file in `<your_module>/languages/<language code>/LC_MESSAGES/my_theme.po`.
9e4cc28e 147 4. Go to `Catalog > Properties...`
1a47014f
A
148 5. Fill the `Translation Properties` tab
149 6. Add your source path in the `Sources Paths` tab
150 7. In the `Sources Keywords` tab uncheck "Also use default keywords" and add the following lines:
9e4cc28e 151
1a47014f
A
152```
153my_theme_t
154my_theme_t:1,2
155```
156
157Click on the "Update" button and you're free to start your translations!