From 12266213d098a53c5f005b9afcbbe62771fd580c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 9 May 2017 18:12:15 +0200 Subject: Shaarli's translation * translation system and unit tests * Translations everywhere Dont use translation merge It is not available with PHP builtin gettext, so it would have lead to inconsistency. --- plugins/TODO.md | 28 ---------------------------- plugins/addlink_toolbar/addlink_toolbar.php | 13 +++++++++++-- plugins/archiveorg/archiveorg.html | 6 +++++- plugins/archiveorg/archiveorg.php | 11 ++++++++++- plugins/demo_plugin/demo_plugin.php | 9 +++++++++ plugins/isso/isso.php | 17 ++++++++++++++--- plugins/markdown/help.html | 6 +++--- plugins/markdown/markdown.php | 21 +++++++++++++++++++-- plugins/piwik/piwik.php | 15 +++++++++++++-- plugins/playvideos/playvideos.php | 13 +++++++++++-- plugins/pubsubhubbub/pubsubhubbub.php | 16 +++++++++++++--- plugins/qrcode/qrcode.meta | 2 +- plugins/qrcode/qrcode.php | 9 +++++++++ plugins/wallabag/wallabag.html | 6 +++++- plugins/wallabag/wallabag.php | 20 +++++++++++++++++--- 15 files changed, 140 insertions(+), 52 deletions(-) delete mode 100644 plugins/TODO.md (limited to 'plugins') diff --git a/plugins/TODO.md b/plugins/TODO.md deleted file mode 100644 index e3313d67..00000000 --- a/plugins/TODO.md +++ /dev/null @@ -1,28 +0,0 @@ -https://github.com/shaarli/Shaarli/issues/181 - Add Disqus or Isso comments box on a permalink page - - * http://posativ.org/isso/ - * install debian package https://packages.debian.org/sid/isso - * configure server http://posativ.org/isso/docs/configuration/server/ - * configure client http://posativ.org/isso/docs/configuration/client/ - * http://posativ.org/isso/docs/quickstart/ and add `` to includes.html template; then add `
` in the linklist template where you want the comments (in the linklist_plugins loop for example) - - -Problem: by default, Isso thread ID is guessed from the current url (only one thread per page). -if we want multiple threads on a single page (shaarli linklist), we must use : the `data-isso-id` client config, -with data-isso-id being the permalink of an item. - -`
` -`data-isso-id: Set a custom thread id, defaults to current URI.` - -Problem: feature is currently broken https://github.com/posativ/isso/issues/27 - -Another option, only display isso threads when current URL is a permalink (`\?(A-Z|a-z|0-9|-){7}`) (only show thread -when displaying only this link), and just display a "comments" button on each linklist item. Optionally show the comment -count on each item using the API (http://posativ.org/isso/docs/extras/api/#get-comment-count). API requests can be done -by raintpl `{function` or client-side with js. The former should be faster if isso and shaarli are on ther same server. - -Showing all full isso threads in the linklist would destroy layout - ------------------------------------------------------------ - -http://www.git-attitude.fr/2014/11/04/git-rerere/ for the merge diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php index ddf50aaf..8c05a231 100644 --- a/plugins/addlink_toolbar/addlink_toolbar.php +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -26,11 +26,11 @@ function hook_addlink_toolbar_render_header($data) array( 'type' => 'text', 'name' => 'post', - 'placeholder' => 'URI', + 'placeholder' => t('URI'), ), array( 'type' => 'submit', - 'value' => 'Add link', + 'value' => t('Add link'), 'class' => 'bigbutton', ), ), @@ -40,3 +40,12 @@ function hook_addlink_toolbar_render_header($data) return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function addlink_toolbar_dummy_translation() +{ + // meta + t('Adds the addlink input on the linklist page.'); +} diff --git a/plugins/archiveorg/archiveorg.html b/plugins/archiveorg/archiveorg.html index 0781fe35..ad501f47 100644 --- a/plugins/archiveorg/archiveorg.html +++ b/plugins/archiveorg/archiveorg.html @@ -1 +1,5 @@ -archive.org + + + archive.org + + diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index 03d13d0e..cda35751 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php @@ -20,9 +20,18 @@ function hook_archiveorg_render_linklist($data) if($value['private'] && preg_match('/^\?[a-zA-Z0-9-_@]{6}($|&|#)/', $value['real_url'])) { continue; } - $archive = sprintf($archive_html, $value['url']); + $archive = sprintf($archive_html, $value['url'], t('View on archive.org')); $value['link_plugin'][] = $archive; } return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function archiveorg_dummy_translation() +{ + // meta + t('For each link, add an Archive.org icon.'); +} diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 8fdbf663..3a90ae6a 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -433,3 +433,12 @@ function hook_demo_plugin_render_feed($data) } return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function demo_dummy_translation() +{ + // meta + t('A demo plugin covering all use cases for template designers and plugin developers.'); +} diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index ce16645f..5bc1cce2 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php @@ -4,10 +4,11 @@ * Plugin Isso. */ +use Shaarli\Config\ConfigManager; + /** * Display an error everywhere if the plugin is enabled without configuration. * - * @param $data array List of links * @param $conf ConfigManager instance * * @return mixed - linklist data with Isso plugin. @@ -16,8 +17,8 @@ function isso_init($conf) { $issoUrl = $conf->get('plugins.ISSO_SERVER'); if (empty($issoUrl)) { - $error = 'Isso plugin error: '. - 'Please define the "ISSO_SERVER" setting in the plugin administration page.'; + $error = t('Isso plugin error: '. + 'Please define the "ISSO_SERVER" setting in the plugin administration page.'); return array($error); } } @@ -52,3 +53,13 @@ function hook_isso_render_linklist($data, $conf) return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function isso_dummy_translation() +{ + // meta + t('Let visitor comment your shaares on permalinks with Isso.'); + t('Isso server URL (without \'http://\')'); +} diff --git a/plugins/markdown/help.html b/plugins/markdown/help.html index 9c4e5ae0..ded3d347 100644 --- a/plugins/markdown/help.html +++ b/plugins/markdown/help.html @@ -1,5 +1,5 @@
- Description will be rendered with - - Markdown syntax. + %s + + %s.
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php index 772c56e8..1531549d 100644 --- a/plugins/markdown/markdown.php +++ b/plugins/markdown/markdown.php @@ -154,8 +154,13 @@ function hook_markdown_render_includes($data) function hook_markdown_render_editlink($data) { // Load help HTML into a string - $data['edit_link_plugin'][] = file_get_contents(PluginManager::$PLUGINS_PATH .'/markdown/help.html'); - + $txt = file_get_contents(PluginManager::$PLUGINS_PATH .'/markdown/help.html'); + $translations = [ + t('Description will be rendered with'), + t('Markdown syntax documentation'), + t('Markdown syntax'), + ]; + $data['edit_link_plugin'][] = vsprintf($txt, $translations); // Add no markdown 'meta-tag' in tag list if it was never used, for autocompletion. if (! in_array(NO_MD_TAG, $data['tags'])) { $data['tags'][NO_MD_TAG] = 0; @@ -325,3 +330,15 @@ function process_markdown($description, $escape = true, $allowedProtocols = []) return $processedDescription; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function markdown_dummy_translation() +{ + // meta + t('Render shaare description with Markdown syntax.
Warning: +If your shaared descriptions contained HTML tags before enabling the markdown plugin, +enabling it might break your page. +See the README.'); +} diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php index 4a2b48a1..ca00c2be 100644 --- a/plugins/piwik/piwik.php +++ b/plugins/piwik/piwik.php @@ -18,8 +18,8 @@ function piwik_init($conf) $piwikUrl = $conf->get('plugins.PIWIK_URL'); $piwikSiteid = $conf->get('plugins.PIWIK_SITEID'); if (empty($piwikUrl) || empty($piwikSiteid)) { - $error = 'Piwik plugin error: ' . - 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.'; + $error = t('Piwik plugin error: ' . + 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.'); return array($error); } } @@ -60,3 +60,14 @@ function hook_piwik_render_footer($data, $conf) return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function piwik_dummy_translation() +{ + // meta + t('A plugin that adds Piwik tracking code to Shaarli pages.'); + t('Piwik URL'); + t('Piwik site ID'); +} diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php index 64484504..c6d6b0cc 100644 --- a/plugins/playvideos/playvideos.php +++ b/plugins/playvideos/playvideos.php @@ -19,10 +19,10 @@ function hook_playvideos_render_header($data) $playvideo = array( 'attr' => array( 'href' => '#', - 'title' => 'Video player', + 'title' => t('Video player'), 'id' => 'playvideos', ), - 'html' => '► Play Videos' + 'html' => '► '. t('Play Videos') ); $data['buttons_toolbar'][] = $playvideo; } @@ -46,3 +46,12 @@ function hook_playvideos_render_footer($data) return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function playvideos_dummy_translation() +{ + // meta + t('Add a button in the toolbar allowing to watch all videos.'); +} diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 03b6757b..184b588b 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -10,6 +10,7 @@ */ use pubsubhubbub\publisher\Publisher; +use Shaarli\Config\ConfigManager; /** * Plugin init function - set the hub to the default appspot one. @@ -65,7 +66,7 @@ function hook_pubsubhubbub_save_link($data, $conf) $p = new Publisher($conf->get('plugins.PUBSUBHUB_URL')); $p->publish_update($feeds, $httpPost); } catch (Exception $e) { - error_log('Could not publish to PubSubHubbub: ' . $e->getMessage()); + error_log(sprintf(t('Could not publish to PubSubHubbub: %s'), $e->getMessage())); } return $data; @@ -91,11 +92,20 @@ function nocurl_http_post($url, $postString) { $context = stream_context_create($params); $fp = @fopen($url, 'rb', false, $context); if (!$fp) { - throw new Exception('Could not post to '. $url); + throw new Exception(sprintf(t('Could not post to %s'), $url)); } $response = @stream_get_contents($fp); if ($response === false) { - throw new Exception('Bad response from the hub '. $url); + throw new Exception(sprintf(t('Bad response from the hub %s'), $url)); } return $response; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function pubsubhubbub_dummy_translation() +{ + // meta + t('Enable PubSubHubbub feed publishing.'); +} diff --git a/plugins/qrcode/qrcode.meta b/plugins/qrcode/qrcode.meta index cbf371ea..1812cd21 100644 --- a/plugins/qrcode/qrcode.meta +++ b/plugins/qrcode/qrcode.meta @@ -1 +1 @@ -description="For each link, add a QRCode icon ." +description="For each link, add a QRCode icon." diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 8bc610d1..0f96a106 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -59,3 +59,12 @@ function hook_qrcode_render_includes($data) return $data; } + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function qrcode_dummy_translation() +{ + // meta + t('For each link, add a QRCode icon.'); +} diff --git a/plugins/wallabag/wallabag.html b/plugins/wallabag/wallabag.html index e861536d..4c57691d 100644 --- a/plugins/wallabag/wallabag.html +++ b/plugins/wallabag/wallabag.html @@ -1 +1,5 @@ -wallabag + + + wallabag + + diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index 641e4cc2..9dfd079e 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -5,6 +5,7 @@ */ require_once 'WallabagInstance.php'; +use Shaarli\Config\ConfigManager; /** * Init function, return an error if the server is not set. @@ -17,8 +18,8 @@ function wallabag_init($conf) { $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); if (empty($wallabagUrl)) { - $error = 'Wallabag plugin error: '. - 'Please define the "WALLABAG_URL" setting in the plugin administration page.'; + $error = t('Wallabag plugin error: '. + 'Please define the "WALLABAG_URL" setting in the plugin administration page.'); return array($error); } } @@ -43,12 +44,14 @@ function hook_wallabag_render_linklist($data, $conf) $wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); + $linkTitle = t('Save to wallabag'); foreach ($data['links'] as &$value) { $wallabag = sprintf( $wallabagHtml, $wallabagInstance->getWallabagUrl(), urlencode($value['url']), - PluginManager::$PLUGINS_PATH + PluginManager::$PLUGINS_PATH, + $linkTitle ); $value['link_plugin'][] = $wallabag; } @@ -56,3 +59,14 @@ function hook_wallabag_render_linklist($data, $conf) return $data; } +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function wallabag_dummy_translation() +{ + // meta + t('For each link, add a QRCode icon.'); + t('Wallabag API URL'); + t('Wallabag API version (1 or 2)'); +} + -- cgit v1.2.3