Translations : Working demo example of translation extension
This commit is contained in:
parent
f39580c6fd
commit
6a65bc5798
5 changed files with 86 additions and 35 deletions
plugins/demo_plugin
|
@ -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'][] = '<br>'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.');
|
||||
|
||||
// Free elements at the end of the page.
|
||||
$data['endofpage'][] = '<marquee id="demo_marquee">' .
|
||||
|
|
BIN
plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo
Normal file
BIN
plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.mo
Normal file
Binary file not shown.
21
plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po
Normal file
21
plugins/demo_plugin/languages/fr/LC_MESSAGES/demo.po
Normal file
|
@ -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."
|
Loading…
Add table
Add a link
Reference in a new issue