diff options
Diffstat (limited to 'plugins/demo_plugin/demo_plugin.php')
-rw-r--r-- | plugins/demo_plugin/demo_plugin.php | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 8fdbf663..b80a2b6d 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php | |||
@@ -14,6 +14,26 @@ | |||
14 | * and check user status with _LOGGEDIN_. | 14 | * and check user status with _LOGGEDIN_. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | use Shaarli\Config\ConfigManager; | ||
18 | |||
19 | /** | ||
20 | * In the footer hook, there is a working example of a translation extension for Shaarli. | ||
21 | * | ||
22 | * The extension must be attached to a new translation domain (i.e. NOT 'shaarli'). | ||
23 | * Use case: any custom theme or non official plugin can use the translation system. | ||
24 | * | ||
25 | * See the documentation for more information. | ||
26 | */ | ||
27 | const EXT_TRANSLATION_DOMAIN = 'demo'; | ||
28 | |||
29 | /* | ||
30 | * This is not necessary, but it's easier if you don't want Poedit to mix up your translations. | ||
31 | */ | ||
32 | function demo_plugin_t($text, $nText = '', $nb = 1) | ||
33 | { | ||
34 | return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN); | ||
35 | } | ||
36 | |||
17 | /** | 37 | /** |
18 | * Initialization function. | 38 | * Initialization function. |
19 | * It will be called when the plugin is loaded. | 39 | * It will be called when the plugin is loaded. |
@@ -27,6 +47,12 @@ function demo_plugin_init($conf) | |||
27 | { | 47 | { |
28 | $conf->get('toto', 'nope'); | 48 | $conf->get('toto', 'nope'); |
29 | 49 | ||
50 | if (! $conf->exists('translation.extensions.demo')) { | ||
51 | // Custom translation with the domain 'demo' | ||
52 | $conf->set('translation.extensions.demo', 'plugins/demo_plugin/languages/'); | ||
53 | $conf->write(true); | ||
54 | } | ||
55 | |||
30 | $errors[] = 'This a demo init error.'; | 56 | $errors[] = 'This a demo init error.'; |
31 | return $errors; | 57 | return $errors; |
32 | } | 58 | } |
@@ -160,7 +186,7 @@ function hook_demo_plugin_render_includes($data) | |||
160 | function hook_demo_plugin_render_footer($data) | 186 | function hook_demo_plugin_render_footer($data) |
161 | { | 187 | { |
162 | // footer text | 188 | // footer text |
163 | $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.'; | 189 | $data['text'][] = '<br>'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); |
164 | 190 | ||
165 | // Free elements at the end of the page. | 191 | // Free elements at the end of the page. |
166 | $data['endofpage'][] = '<marquee id="demo_marquee">' . | 192 | $data['endofpage'][] = '<marquee id="demo_marquee">' . |
@@ -433,3 +459,12 @@ function hook_demo_plugin_render_feed($data) | |||
433 | } | 459 | } |
434 | return $data; | 460 | return $data; |
435 | } | 461 | } |
462 | |||
463 | /** | ||
464 | * This function is never called, but contains translation calls for GNU gettext extraction. | ||
465 | */ | ||
466 | function demo_dummy_translation() | ||
467 | { | ||
468 | // meta | ||
469 | t('A demo plugin covering all use cases for template designers and plugin developers.'); | ||
470 | } | ||