Skip to content

Commit

Permalink
Internationalize plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kudlav committed Jun 11, 2020
1 parent f8c19d4 commit 0cbe7cf
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 57 deletions.
65 changes: 36 additions & 29 deletions anti-spam-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ function antispamrel_admin_notice() {
$blocked_total = 0; // show 0 by default
$antispam_stats = get_option('antispamrel_stats', array());
if (isset($antispam_stats['blocked_total'])) {
$blocked_total = esc_html($antispam_stats['blocked_total']);
$blocked_total = $antispam_stats['blocked_total'];
}
?>
<div class="notice notice-info">
<p>
<?php echo $blocked_total; ?> spam comments were blocked by <a href="http://wordpress.org/plugins/anti-spam-reloaded/">Anti-spam Reloaded</a> plugin so far.
</p>
</div>
<?php

esc_html(printf(
'<div class="notice notice-info"><p>' .
/* translators: 1: number of blocked comments, 2: plugin name. */
_n(
'%1$s spam comment was blocked by %2$s plugin so far',
'%1$s spam comments were blocked by %2$s plugin so far',
$blocked_total,
'anti-spam-reloaded'
) .
'</p></div>',
number_format_i18n($blocked_total),
'<a href="https://wordpress.org/plugins/anti-spam-reloaded" target="_blank" rel="noreferrer">Anti-spam Reloaded</a>'
));
}
}
}
Expand All @@ -40,28 +47,28 @@ function antispamrel_display_screen_option() {
$checked = checked(($antispam_info_visibility == 1 || $antispam_info_visibility == ''), true, false);
$nonce = esc_textarea(wp_create_nonce('antispamrel_info_nonce'));

?>
<form method="post" id="antispamrel_screen_options_group">
<fieldset>
<legend>Anti-spam Reloaded</legend>
<input type="hidden" name="antispamrel_info_nonce" value="<?php echo $nonce; ?>" />
<label>
<input name="antispamrel_info_visibility" type="checkbox" value="1" <?php echo $checked; ?> />
Show number of blocked comments
</label>
<input type="submit" class="button" value="<?php _e('Apply'); ?>" />
</fieldset>
</form>
<script>
document.onreadystatechange = function () {
if (document.readyState === "complete") {
const antspmrl_advsett = document.getElementById('screen-options-wrap');
const antspmrl_advopts = document.getElementById('antispamrel_screen_options_group');
antspmrl_advsett.appendChild(antspmrl_advopts);
echo '
<form method="post" id="antispamrel_screen_options_group">
<fieldset>
<legend>Anti-spam Reloaded</legend>
<input type="hidden" name="antispamrel_info_nonce" value="', $nonce, '" />
<label>
<input name="antispamrel_info_visibility" type="checkbox" value="1" ', $checked, ' />
', esc_html__('Show number of blocked comments', 'anti-spam-reloaded'), '
</label>
<input type="submit" class="button" value="', esc_attr__('Apply', 'anti-spam-reloaded'), '" />
</fieldset>
</form>
<script>
document.onreadystatechange = function () {
if (document.readyState === "complete") {
const antspmrl_advsett = document.getElementById(\'screen-options-wrap\');
const antspmrl_advopts = document.getElementById(\'antispamrel_screen_options_group\');
antspmrl_advsett.appendChild(antspmrl_advopts);
}
}
}
</script>
<?php
</script>
';
}
}

Expand Down
59 changes: 40 additions & 19 deletions anti-spam-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function antispamrel_admin_init() {

add_settings_section('antispamrel_settings_automatic_section', '', 'antispamrel_section_callback', 'antispamrel_automatic_page');

add_settings_field('save_spam_comments', 'Save spam comments', 'antispamrel_field_save_spam_comments_callback', 'antispamrel_automatic_page', 'antispamrel_settings_automatic_section');
add_settings_field('save_spam_comments', __('Save spam comments', 'anti-spam-reloaded'), 'antispamrel_field_save_spam_comments_callback', 'antispamrel_automatic_page', 'antispamrel_settings_automatic_section');

}
add_action('admin_init', 'antispamrel_admin_init');
Expand All @@ -39,32 +39,53 @@ function antispamrel_section_callback() { // Anti-spam settings description

function antispamrel_field_save_spam_comments_callback() {
$settings = antispamrel_get_settings();
echo '<label><input type="checkbox" name="antispamrel_settings[save_spam_comments]" ', checked(1, $settings['save_spam_comments'], false), ' value="1" />',
' Save spam comments into spam section</label>',
'<p class="description">Useful for testing how the plugin works. <a href="', admin_url( 'edit-comments.php?comment_status=spam' ), '">View spam section</a>.</p>';
$checked = checked(1, $settings['save_spam_comments'], false);
echo '
<label>
<input type="checkbox" name="antispamrel_settings[save_spam_comments]" ', $checked, ' value="1" /> ',
esc_html__('Save spam comments into spam section', 'anti-spam-reloaded'),
'</label>',
'<p class="description">', esc_html__('Useful for testing how the plugin works', 'anti-spam-reloaded'), '. ',
'<a href="', admin_url( 'edit-comments.php?comment_status=spam' ), '">',
esc_html__('View spam section', 'anti-spam-reloaded'),
'</a>.
</p>';
}


function antispamrel_settings() {
$blocked_total = 0; // show 0 by default
$antispam_stats = get_option('antispamrel_stats', array());
if (isset($antispam_stats['blocked_total'])) {
$blocked_total = esc_html($antispam_stats['blocked_total']);
$blocked_total = $antispam_stats['blocked_total'];
}

?>
<div class="wrap">
<h2><span class="dashicons dashicons-admin-generic"></span> Anti-spam Reloaded</h2>
<p>
<span class="dashicons dashicons-chart-bar"></span>
<strong><?php echo $blocked_total; ?></strong> spam comments were blocked by <a href="https://wordpress.org/plugins/anti-spam-reloaded/" target="_blank" rel="noreferrer">Anti-spam Reloaded</a>
</p>
<form method="post" action="options.php">
<?php
settings_fields('antispamrel_settings_group');
do_settings_sections('antispamrel_automatic_page');
submit_button();
?>
</form>
</div>
<div class="wrap">
<h2><span class="dashicons dashicons-admin-generic"></span> Anti-spam Reloaded</h2>
<p>
<span class="dashicons dashicons-chart-bar"></span>
<?php
esc_html(printf(
/* translators: 1: number of blocked comments, 2: plugin name. */
_n(
'%1$s spam comment was blocked by %2$s plugin so far',
'%1$s spam comments were blocked by %2$s plugin so far',
$blocked_total,
'anti-spam-reloaded'
),
number_format_i18n($blocked_total),
'<a href="https://wordpress.org/plugins/anti-spam-reloaded" target="_blank" rel="noreferrer">Anti-spam Reloaded</a>'
));
?>
</p>
<form method="post" action="options.php">
<?php
settings_fields('antispamrel_settings_group');
do_settings_sections('antispamrel_automatic_page');
submit_button()
?>
</form>
</div>
<?php
}
26 changes: 17 additions & 9 deletions anti-spam.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
include('anti-spam-settings.php');
include('anti-spam-info.php');

function antispamrel_load_plugin_textdomain() {
load_plugin_textdomain('anti-spam-reloaded', false, basename(dirname(__FILE__)) . '/languages/');
}
add_action('plugins_loaded', 'antispamrel_load_plugin_textdomain');

function antispamrel_enqueue_script() {
global $withcomments; // WP flag to show comments on all pages
Expand All @@ -38,18 +42,22 @@ function antispamrel_enqueue_script() {

function antispamrel_form_part() {
if ( ! is_user_logged_in()) { // add anti-spam fields only for not logged in users
echo '
printf( '
<!-- Anti-spam Reloaded plugin wordpress.org/plugins/anti-spam-reloaded/ -->
<p class="antispamrel-group" style="clear: both;">
<label>Current ye@r <span class="required">*</span></label>
<input type="hidden" name="antspmrl-a" class="antispamrel-control-a" value="', date('Y'), '" />
<input type="text" name="antspmrl-q" class="antispamrel-control-q" value="', rand(0, 99), '" autocomplete="off" />
<label>' . /*translators:1:invisible text will be inserted here*/
esc_html__('Current ye%s@r', 'anti-spam-reloaded') .
'<span class="required">*</span>
</label>
<input type="hidden" name="antspmrl-a" class="antispamrel-control-a" value="' . date('Y') . '" />
<input type="text" name="antspmrl-q" class="antispamrel-control-q" value="' . rand(0, 99) . '" autocomplete="off" />
</p>
<p class="antispamrel-group" style="display: none;">
<label>'. __('Leave this field empty', 'anti-spam-reloaded') .'</label>
<label>' . esc_html__('Leave this field empty', 'anti-spam-reloaded') . '</label>
<input type="text" name="antspmrl-e-email-url-website" class="antispamrel-control-e" value="" autocomplete="off" />
</p>
'; // empty field (hidden with css); trap for spammers because many bots will try to put email or url here
', '<span style="display: none;">ignore me</span>');
// empty field (hidden with css): trap for spammers because many bots will try to put email or url here
}
}
add_action('comment_form', 'antispamrel_form_part'); // add anti-spam inputs to the comment form
Expand All @@ -63,10 +71,10 @@ function antispamrel_check_comment($commentdata) {
switch ($commentdata['comment_type']) {
case '': // comment
if(!is_user_logged_in() && antispamrel_check_for_spam()) // logged in user is not a spammer
$flag = 'Comment is a spam.';
$flag = __('Comment is a spam.', 'anti-spam-reloaded');
break;
case 'trackback':
$flag = 'Trackbacks are disabled.';
$flag = __('Trackbacks are disabled.', 'anti-spam-reloaded');
}

if ($flag !== null) {
Expand All @@ -87,7 +95,7 @@ function antispamrel_check_comment($commentdata) {
function antispamrel_plugin_meta($links, $file) { // add some links to plugin meta row
if ( $file == plugin_basename( __FILE__ ) ) {
$row_meta = array(
'github' => '<a href="https://github.com/kudlav/anti-spam/" target="_blank" rel="noreferrer">' . __( 'Github', 'github' ) . '</a>'
'github' => '<a href="https://github.com/kudlav/anti-spam/" target="_blank" rel="noreferrer">GitHub</a>'
);
$links = array_merge( $links, $row_meta );
}
Expand Down
Binary file added languages/anti-spam-reloaded-cs_CZ.mo
Binary file not shown.
80 changes: 80 additions & 0 deletions languages/anti-spam-reloaded-cs_CZ.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Translation of Plugins - Anti-spam Reloaded - Development (trunk) in Czech
# This file is distributed under the same license as the Plugins - Anti-spam Reloaded - Development (trunk) package.
msgid ""
msgstr ""
"PO-Revision-Date: +0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2);\n"
"X-Generator: GlotPress/3.0.0-alpha\n"
"Language: cs_CZ\n"
"Project-Id-Version: Plugins - Anti-spam Reloaded - Development (trunk)\n"

#: anti-spam-info.php:59
msgid "Apply"
msgstr "Použít"

#: anti-spam-info.php:57
msgid "Show number of blocked comments"
msgstr "Zobrazit počet zablokovaných komentářů"

#. translators: 1: number of blocked comments, 2: plugin name.
#: anti-spam-settings.php:71 anti-spam-info.php:25
msgid "%1$s spam comment was blocked by %2$s plugin so far"
msgid_plural "%1$s spam comments were blocked by %2$s plugin so far"
msgstr[0] "%1$s komentář byl dosud zablokován pluginem %2$s"
msgstr[1] "%1$s komentáře byl dosud zablokovány pluginem %2$s"
msgstr[2] "%1$s komentářů bylo dosud zablokováno pluginem %2$s"

#: anti-spam-settings.php:50
msgid "View spam section"
msgstr "Přejít na sekci Spam"

#: anti-spam-settings.php:48
msgid "Useful for testing how the plugin works"
msgstr "Užitečné pro vyzkoušení, jak plugin funguje"

#: anti-spam-settings.php:46
msgid "Save spam comments into spam section"
msgstr "Uložit zablokované komentáře do sekce Spam"

#: anti-spam-settings.php:23
msgid "Save spam comments"
msgstr "Uložit zablokované komentáře"

#: anti-spam.php:74
msgid "Trackbacks are disabled."
msgstr "Trackbacky jsou zakázané."

#: anti-spam.php:71
msgid "Comment is a spam."
msgstr "Komentář je spam."

#: anti-spam.php:53
msgid "Leave this field empty"
msgstr "Ponechte toto pole prázdné"

#: anti-spam.php:48
msgid "Current ye%s@r"
msgstr "Aktuální ro%sk"

#. Author URI of the plugin
msgid "https://kudlav.github.io/"
msgstr "https://kudlav.github.io/"

#. Author of the plugin
msgid "kudlav, webvitaly"
msgstr "kudlav, webvitaly"

#. Description of the plugin
msgid "No spam in comments. No captcha."
msgstr "Žádný spam v komentářích. Žádná captcha."

#. Plugin URI of the plugin
msgid "http://wordpress.org/plugins/anti-spam-reloaded/"
msgstr "https://cs.wordpress.org/plugins/anti-spam-reloaded/"

#. Plugin Name of the plugin
msgid "Anti-spam Reloaded"
msgstr "Anti-spam Reloaded"
77 changes: 77 additions & 0 deletions languages/anti-spam-reloaded.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (C) 2020 kudlav, webvitaly
# This file is distributed under the same license as the Anti-spam Reloaded plugin.
msgid ""
msgstr ""
"PO-Revision-Date: +0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: GlotPress/3.0.0-alpha\n"
"Project-Id-Version: Plugins - Anti-spam Reloaded - Development (trunk)\n"

#: anti-spam-info.php:59
msgid "Apply"
msgstr ""

#: anti-spam-info.php:57
msgid "Show number of blocked comments"
msgstr ""

#. translators: 1: number of blocked comments, 2: plugin name.
#: anti-spam-settings.php:71 anti-spam-info.php:25
msgid "%1$s spam comment was blocked by %2$s plugin so far"
msgid_plural "%1$s spam comments were blocked by %2$s plugin so far"
msgstr[0] ""
msgstr[1] ""

#: anti-spam-settings.php:50
msgid "View spam section"
msgstr ""

#: anti-spam-settings.php:48
msgid "Useful for testing how the plugin works"
msgstr ""

#: anti-spam-settings.php:46
msgid "Save spam comments into spam section"
msgstr ""

#: anti-spam-settings.php:23
msgid "Save spam comments"
msgstr ""

#: anti-spam.php:74
msgid "Trackbacks are disabled."
msgstr ""

#: anti-spam.php:71
msgid "Comment is a spam."
msgstr ""

#: anti-spam.php:53
msgid "Leave this field empty"
msgstr ""

#: anti-spam.php:48
msgid "Current ye%s@r"
msgstr ""

#. Author URI of the plugin
msgid "https://kudlav.github.io/"
msgstr ""

#. Author of the plugin
msgid "kudlav, webvitaly"
msgstr ""

#. Description of the plugin
msgid "No spam in comments. No captcha."
msgstr ""

#. Plugin URI of the plugin
msgid "http://wordpress.org/plugins/anti-spam-reloaded/"
msgstr ""

#. Plugin Name of the plugin
msgid "Anti-spam Reloaded"
msgstr ""

0 comments on commit 0cbe7cf

Please sign in to comment.