Skip to content

Commit 237978b

Browse files
authored
Merge pull request #11 from Beee4life/master
Internationalization
2 parents b3401c4 + 2d99f7c commit 237978b

File tree

5 files changed

+111
-48
lines changed

5 files changed

+111
-48
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Supports ACF 5
44

5-
Adds a counter to all text and textarea fields with character limits
5+
Adds a counter to all text and textarea fields with character limits.
66

77
This is a simple plugin that will add a counter below all ACF text and text area fields to show how many
88
characters have been added and what the limit is. The display will look something like this:
@@ -32,7 +32,7 @@ function my_input_counter_filter($classes=array()) {
3232
return $classes;
3333
}
3434
```
35-
fields that have one of the classes or ids will include a counter.
35+
Fields that have one of the classes or ids will include a counter.
3636

3737
**Filter by ID**
3838
```
@@ -45,11 +45,15 @@ function my_input_counter_filter($ids=array()) {
4545
```
4646

4747
### Filter the Display
48-
To filter the display add a filter wherever you would add a filter
48+
To filter the display add a filter wherever you would add a filter.
4949
```
5050
add_filter('acf-input-counter/display', 'my_acf_counter_filter');
5151
function my_acf_counter_filter($display) {
52-
$display = 'Characters = %%len%% of %%max%%';
52+
$display = sprintf(
53+
__('Characters = %1$s of %2$s', 'acf-counter'),
54+
'%%len%%',
55+
'%%max%%'
56+
);
5357
return $display;
5458
}
5559
```
@@ -73,3 +77,8 @@ add the following filter to your functions.php file.
7377
```
7478
add_filter('remove_hube2_nag', '__return_true');
7579
```
80+
81+
### i18n
82+
The plugin is now also internationalized and it has a .pot file. Also included is a Dutch translation by [Beee][1].
83+
84+
[1]: https://github.com/Beee4life/

acf-input-counter.php

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<?php
1+
<?php
22

33
/*
44
Plugin Name: ACF Input Counter
55
Plugin URI: https://github.com/Hube2/acf-input-counter/
66
Description: Show character count for limited text and textarea fields
7-
Version: 1.3.1
7+
Version: 1.4.0
88
Author: John A. Huebner II
99
Author URI: https://github.com/Hube2/
10+
Text-domain: acf-counter
11+
Domain-path: languages
1012
GitHub Plugin URI: https://github.com/Hube2/acf-input-counter/
1113
License: GPL
1214
*/
@@ -18,24 +20,29 @@
1820

1921
class acf_input_counter {
2022

21-
private $version = '1.2.0';
23+
private $version = '1.4.0';
2224

2325
public function __construct() {
24-
add_action('acf/render_field/type=text', array($this, 'render_field'), 20, 1);
25-
add_action('acf/render_field/type=textarea', array($this, 'render_field'), 20, 1);
26-
add_action('acf/input/admin_enqueue_scripts', array($this, 'scripts'));
27-
add_filter('jh_plugins_list', array($this, 'meta_box_data'));
26+
add_action('plugins_loaded', array($this, 'acf_counter_load_plugin_textdomain'));
27+
add_action('acf/render_field/type=text', array($this, 'render_field'), 20, 1);
28+
add_action('acf/render_field/type=textarea', array($this, 'render_field'), 20, 1);
29+
add_action('acf/input/admin_enqueue_scripts', array($this, 'scripts'));
30+
add_filter('jh_plugins_list', array($this, 'meta_box_data'));
2831
} // end public function __construct
29-
32+
33+
public function acf_counter_load_plugin_textdomain() {
34+
load_plugin_textdomain( 'acf-counter', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
35+
}
36+
3037
function meta_box_data($plugins=array()) {
31-
38+
3239
$plugins[] = array(
33-
'title' => 'ACF Input Counter',
34-
'screens' => array('acf-field-group', 'edit-acf-field-group'),
35-
'doc' => 'https://github.com/Hube2/acf-input-counter'
40+
'title' => 'ACF Input Counter',
41+
'screens' => array('acf-field-group', 'edit-acf-field-group'),
42+
'doc' => 'https://github.com/Hube2/acf-input-counter'
3643
);
3744
return $plugins;
38-
45+
3946
} // end function meta_box
4047

4148
private function run() {
@@ -54,11 +61,11 @@ public function scripts() {
5461
return;
5562
}
5663
// wp_enqueue_script
57-
$handle = 'acf-input-counter';
58-
$src = plugin_dir_url(__FILE__).'acf-input-counter.js';
59-
$deps = array('acf-input');
60-
$ver = $this->version;
61-
$in_footer = false;
64+
$handle = 'acf-input-counter';
65+
$src = plugin_dir_url(__FILE__).'acf-input-counter.js';
66+
$deps = array('acf-input');
67+
$ver = $this->version;
68+
$in_footer = false;
6269
wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);
6370
wp_enqueue_style('acf-counter', plugins_url( 'acf-counter.css' , __FILE__ ));
6471
} // end public function scripts
@@ -73,20 +80,20 @@ public function render_field($field) {
7380
}
7481
$len = strlen($field['value']);
7582
$max = $field['maxlength'];
76-
77-
$classes = apply_filters('acf-input-counter/classes', array());
78-
$ids = apply_filters('acf-input-counter/ids', array());
79-
83+
84+
$classes = apply_filters('acf-input-counter/classes', array());
85+
$ids = apply_filters('acf-input-counter/ids', array());
86+
8087
$insert = true;
8188
if (count($classes) || count($ids)) {
8289
$insert = false;
83-
90+
8491
$exist = array();
8592
if ($field['wrapper']['class']) {
8693
$exist = explode(' ', $field['wrapper']['class']);
8794
}
8895
$insert = $this->check($classes, $exist);
89-
96+
9097
if (!$insert && $field['wrapper']['id']) {
9198
$exist = array();
9299
if ($field['wrapper']['id']) {
@@ -95,23 +102,27 @@ public function render_field($field) {
95102
$insert = $this->check($ids, $exist);
96103
}
97104
} // end if filter classes or ids
98-
105+
99106
if (!$insert) {
100107
return;
101108
}
102-
$display = 'chars: %%len%% of %%max%%';
109+
$display = sprintf(
110+
__('chars: %1$s of %2$s', 'acf-counter'),
111+
'%%len%%',
112+
'%%max%%'
113+
);
103114
$display = apply_filters('acf-input-counter/display', $display);
104115
$display = str_replace('%%len%%', '<span class="count">'.$len.'</span>', $display);
105116
$display = str_replace('%%max%%', $max, $display);
106117
?>
107118
<span class="char-count">
108-
<?php
119+
<?php
109120
echo $display;
110121
?>
111122
</span>
112123
<?php
113124
} // end public function render_field
114-
125+
115126
private function check($allow, $exist) {
116127
// if there is anything in $allow
117128
// see if any of those values are in $exist
@@ -123,50 +134,50 @@ private function check($allow, $exist) {
123134
} // end private function check
124135

125136
} // end class acf_input_counter
126-
137+
127138
if (!function_exists('jh_plugins_list_meta_box')) {
128139
function jh_plugins_list_meta_box() {
129140
if (apply_filters('remove_hube2_nag', false)) {
130141
return;
131142
}
132143
$plugins = apply_filters('jh_plugins_list', array());
133-
134-
$id = 'plugins-by-john-huebner';
135-
$title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a>';
136-
$callback = 'show_blunt_plugins_list_meta_box';
137-
$screens = array();
144+
145+
$id = 'plugins-by-john-huebner';
146+
$title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a>';
147+
$callback = 'show_blunt_plugins_list_meta_box';
148+
$screens = array();
138149
foreach ($plugins as $plugin) {
139150
$screens = array_merge($screens, $plugin['screens']);
140151
}
141-
$context = 'side';
142-
$priority = 'low';
152+
$context = 'side';
153+
$priority = 'low';
143154
add_meta_box($id, $title, $callback, $screens, $context, $priority);
144-
145-
155+
156+
146157
} // end function jh_plugins_list_meta_box
147158
add_action('add_meta_boxes', 'jh_plugins_list_meta_box');
148-
159+
149160
function show_blunt_plugins_list_meta_box() {
150161
$plugins = apply_filters('jh_plugins_list', array());
151162
?>
152163
<p style="margin-bottom: 0;">Thank you for using my plugins</p>
153164
<ul style="margin-top: 0; margin-left: 1em;">
154-
<?php
165+
<?php
155166
foreach ($plugins as $plugin) {
156167
?>
157168
<li style="list-style-type: disc; list-style-position:">
158-
<?php
169+
<?php
159170
echo $plugin['title'];
160171
if ($plugin['doc']) {
161-
?> <a href="<?php echo $plugin['doc']; ?>" target="_blank">Documentation</a><?php
172+
?> <a href="<?php echo $plugin['doc']; ?>" target="_blank">Documentation</a><?php
162173
}
163174
?>
164175
</li>
165-
<?php
176+
<?php
166177
}
167178
?>
168179
</ul>
169-
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
180+
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
170181
}
171182
} // end if !function_exists
172183

languages/acf-counter-nl_NL.mo

529 Bytes
Binary file not shown.

languages/acf-counter-nl_NL.po

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: ACF-counter v1.0\n"
4+
"POT-Creation-Date: 2016-11-20 03:04+0100\n"
5+
"PO-Revision-Date: 2016-11-20 03:07+0100\n"
6+
"Language-Team: \n"
7+
"MIME-Version: 1.0\n"
8+
"Content-Type: text/plain; charset=UTF-8\n"
9+
"Content-Transfer-Encoding: 8bit\n"
10+
"X-Generator: Poedit 1.8.11\n"
11+
"X-Poedit-Basepath: ..\n"
12+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
13+
"X-Poedit-KeywordsList: __;_e\n"
14+
"Last-Translator: Beee\n"
15+
"Language: nl\n"
16+
"X-Poedit-SearchPath-0: .\n"
17+
18+
#: acf-input-counter.php:110
19+
#, php-format
20+
msgid "chars: %1$s of %2$s"
21+
msgstr "tekens: %1$s van %2$s"

languages/acf-counter.pot

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#, fuzzy
2+
msgid ""
3+
msgstr ""
4+
"Project-Id-Version: ACF-counter v1.0\n"
5+
"POT-Creation-Date: 2016-11-20 03:04+0100\n"
6+
"PO-Revision-Date: 2016-11-20 02:48+0100\n"
7+
"Last-Translator: Beee\n"
8+
"Language-Team: \n"
9+
"Language: en_US\n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"X-Generator: Poedit 1.8.11\n"
14+
"X-Poedit-Basepath: ..\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"X-Poedit-KeywordsList: __;_e\n"
17+
"X-Poedit-SearchPath-0: .\n"
18+
19+
#: acf-input-counter.php:110
20+
#, php-format
21+
msgid "chars: %1$s of %2$s"
22+
msgstr ""

0 commit comments

Comments
 (0)