From 6a65bc579810e3688a63a7c3b0e720dc0f5456b0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 19 Aug 2017 10:53:19 +0200 Subject: Translations : Working demo example of translation extension --- plugins/demo_plugin/demo_plugin.php | 28 ++++++++++++++++++++- .../demo_plugin/languages/fr/LC_MESSAGES/demo.mo | Bin 0 -> 652 bytes .../demo_plugin/languages/fr/LC_MESSAGES/demo.po | 21 ++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo create mode 100644 plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po (limited to 'plugins/demo_plugin') diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 3a90ae6a..b80a2b6d 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -14,6 +14,26 @@ * and check user status with _LOGGEDIN_. */ +use Shaarli\Config\ConfigManager; + +/** + * In the footer hook, there is a working example of a translation extension for Shaarli. + * + * The extension must be attached to a new translation domain (i.e. NOT 'shaarli'). + * Use case: any custom theme or non official plugin can use the translation system. + * + * See the documentation for more information. + */ +const EXT_TRANSLATION_DOMAIN = 'demo'; + +/* + * This is not necessary, but it's easier if you don't want Poedit to mix up your translations. + */ +function demo_plugin_t($text, $nText = '', $nb = 1) +{ + return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN); +} + /** * Initialization function. * It will be called when the plugin is loaded. @@ -27,6 +47,12 @@ function demo_plugin_init($conf) { $conf->get('toto', 'nope'); + if (! $conf->exists('translation.extensions.demo')) { + // Custom translation with the domain 'demo' + $conf->set('translation.extensions.demo', 'plugins/demo_plugin/languages/'); + $conf->write(true); + } + $errors[] = 'This a demo init error.'; return $errors; } @@ -160,7 +186,7 @@ function hook_demo_plugin_render_includes($data) function hook_demo_plugin_render_footer($data) { // footer text - $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.'; + $data['text'][] = '
'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); // Free elements at the end of the page. $data['endofpage'][] = '' . diff --git a/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo b/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo new file mode 100644 index 00000000..0f80f6ed Binary files /dev/null and b/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo differ diff --git a/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po b/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po new file mode 100644 index 00000000..921379c0 --- /dev/null +++ b/plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po @@ -0,0 +1,21 @@ +msgid "" +msgstr "" +"Project-Id-Version: Demo plugin\n" +"POT-Creation-Date: 2017-08-19 10:45+0200\n" +"PO-Revision-Date: 2017-08-19 11:28+0200\n" +"Last-Translator: \n" +"Language-Team: demo\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.2\n" +"X-Poedit-Basepath: ../../..\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Poedit-KeywordsList: ;demo_plugin_t:1,2;demo_plugin_t\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-SearchPath-0: .\n" + +#: demo_plugin.php:173 +msgid "Shaarli is now enhanced by the awesome demo_plugin." +msgstr "Shaarli est maintenant amélioré avec le fantastique demo_plugin." -- cgit v1.2.3