Version Description
- Support for _n() and _nx()
- Support for multi-line strings
Download this release
Release Info
Developer | leewillis77 |
Plugin | Say what? |
Version | 1.7 |
Comparing to | |
See all releases |
Code changes from version 1.6 to 1.7
- html/say-what-admin-addedit.php +2 -2
- readme.txt +9 -5
- say-what-admin.php +8 -0
- say-what-frontend.php +41 -8
- say-what.php +3 -2
html/say-what-admin-addedit.php
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
<?php endif; ?>
|
13 |
<p>
|
14 |
<label for="say_what_orig_string"><?php _e( 'Original string', 'say_what' ); ?></label><br/>
|
15 |
-
<
|
16 |
</p>
|
17 |
<p>
|
18 |
<label for="say_what_domain"><?php _e( 'Text domain', 'say_what' ); ?></label> <a href="http://plugins.leewillis.co.uk/doc_post/adding-string-replacement/"><i class="dashicons dashicons-info"> </i></a><br/>
|
@@ -24,7 +24,7 @@
|
|
24 |
</p>
|
25 |
<p>
|
26 |
<label for="say_what_replacement_string"><?php _e( 'Replacement string', 'say_what' ); ?></label><br/>
|
27 |
-
<
|
28 |
</p>
|
29 |
<p>
|
30 |
<input type="submit" class="button-primary" value="<?php ! empty( $replacement->string_id ) ? _e( 'Update', 'say_what' ) : _e( 'Add', 'say_what' ); ?>">
|
12 |
<?php endif; ?>
|
13 |
<p>
|
14 |
<label for="say_what_orig_string"><?php _e( 'Original string', 'say_what' ); ?></label><br/>
|
15 |
+
<textarea class="say_what_orig_string" name="say_what_orig_string" rows="1" cols="120"><?php echo esc_textarea( htmlspecialchars( $replacement->orig_string ) ); ?></textarea>
|
16 |
</p>
|
17 |
<p>
|
18 |
<label for="say_what_domain"><?php _e( 'Text domain', 'say_what' ); ?></label> <a href="http://plugins.leewillis.co.uk/doc_post/adding-string-replacement/"><i class="dashicons dashicons-info"> </i></a><br/>
|
24 |
</p>
|
25 |
<p>
|
26 |
<label for="say_what_replacement_string"><?php _e( 'Replacement string', 'say_what' ); ?></label><br/>
|
27 |
+
<textarea class="say_what_replacement_string" name="say_what_replacement_string" cols="120" rows="1"><?php echo esc_textarea( htmlspecialchars( $replacement->replacement_string ) ); ?></textarea>
|
28 |
</p>
|
29 |
<p>
|
30 |
<input type="submit" class="button-primary" value="<?php ! empty( $replacement->string_id ) ? _e( 'Update', 'say_what' ) : _e( 'Add', 'say_what' ); ?>">
|
readme.txt
CHANGED
@@ -3,29 +3,29 @@ Contributors: leewillis77
|
|
3 |
Donate link: http://www.leewillis.co.uk/wordpress-plugins/?utm_source=wordpress&utm_medium=www&utm_campaign=say-what
|
4 |
Tags: string, change, translation
|
5 |
Requires at least: 3.5
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
== Description ==
|
10 |
An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!
|
11 |
|
12 |
The plugin's available for forking and contribution over on [GitHub](https://github.com/leewillis77/say-what)
|
13 |
|
|
|
|
|
14 |
== Installation ==
|
15 |
|
16 |
* Install it as you would any other plugin
|
17 |
* Activate it
|
18 |
* Head over to Tools » Text changes and configure some string replacements
|
19 |
|
20 |
-
Note: This plugin may produce performance issues if you use it to configure a *large* number of string translations. I'd be interested in feedback if that's the case.
|
21 |
-
|
22 |
== Frequently Asked Questions ==
|
23 |
|
24 |
= Can I use it to change any string? =
|
25 |
You can only use the plugin to translate strings which are marked for translation.
|
26 |
|
27 |
= How do I find the string to translate? =
|
28 |
-
You can either have a guess, or checkout the plugin in question's source code, translatable strings are generally wrapped in __(), _e(), or _x(), for example:
|
29 |
|
30 |
`$foo = __('This is a translatable string', 'plugin-domain');`
|
31 |
|
@@ -48,6 +48,10 @@ See the [GitHub homepage](https://github.com/leewillis77/say-what) for examples.
|
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
|
|
51 |
= 1.6 =
|
52 |
Introduce filters that allows back compatibility for plugins that change their text-domain. Props Pippin Williamson
|
53 |
|
3 |
Donate link: http://www.leewillis.co.uk/wordpress-plugins/?utm_source=wordpress&utm_medium=www&utm_campaign=say-what
|
4 |
Tags: string, change, translation
|
5 |
Requires at least: 3.5
|
6 |
+
Tested up to: 4.5
|
7 |
+
Stable tag: 1.7
|
8 |
|
9 |
== Description ==
|
10 |
An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!
|
11 |
|
12 |
The plugin's available for forking and contribution over on [GitHub](https://github.com/leewillis77/say-what)
|
13 |
|
14 |
+
*Don't have the time/expertise to find strings in the code - check out [Say What Pro](https://plugins.leewillis.co.uk/downloads/say-what-pro/) which includes String Discovery letting you autocomplete the information you need for quick string replacements.*
|
15 |
+
|
16 |
== Installation ==
|
17 |
|
18 |
* Install it as you would any other plugin
|
19 |
* Activate it
|
20 |
* Head over to Tools » Text changes and configure some string replacements
|
21 |
|
|
|
|
|
22 |
== Frequently Asked Questions ==
|
23 |
|
24 |
= Can I use it to change any string? =
|
25 |
You can only use the plugin to translate strings which are marked for translation.
|
26 |
|
27 |
= How do I find the string to translate? =
|
28 |
+
You can either have a guess, or checkout the plugin in question's source code, translatable strings are generally wrapped in __(), _e(), _n(), or _x(), for example:
|
29 |
|
30 |
`$foo = __('This is a translatable string', 'plugin-domain');`
|
31 |
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 1.7 =
|
52 |
+
* Support for _n() and _nx()
|
53 |
+
* Support for multi-line strings
|
54 |
+
|
55 |
= 1.6 =
|
56 |
Introduce filters that allows back compatibility for plugins that change their text-domain. Props Pippin Williamson
|
57 |
|
say-what-admin.php
CHANGED
@@ -139,6 +139,13 @@ class SayWhatAdmin {
|
|
139 |
require_once('html/say-what-admin-addedit.php');
|
140 |
}
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
/**
|
143 |
* Something on the admin pages needs saved. Handle it here
|
144 |
* Output error/warning messages as required
|
@@ -149,6 +156,7 @@ class SayWhatAdmin {
|
|
149 |
wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
|
150 |
}
|
151 |
$_POST = stripslashes_deep( $_POST );
|
|
|
152 |
if ( isset ( $_POST['say_what_string_id'] ) ) {
|
153 |
$sql = "UPDATE {$table_prefix}say_what_strings
|
154 |
SET orig_string = %s,
|
139 |
require_once('html/say-what-admin-addedit.php');
|
140 |
}
|
141 |
|
142 |
+
/**
|
143 |
+
* Strip CRs out of strings. array_walk() callback.
|
144 |
+
*/
|
145 |
+
private function strip_cr_callback( &$val, $key ) {
|
146 |
+
$val = str_replace("\r\n", "\n", $val);
|
147 |
+
}
|
148 |
+
|
149 |
/**
|
150 |
* Something on the admin pages needs saved. Handle it here
|
151 |
* Output error/warning messages as required
|
156 |
wp_die( __( 'Did you really mean to do that? Please go back and try again.', 'say_what' ) );
|
157 |
}
|
158 |
$_POST = stripslashes_deep( $_POST );
|
159 |
+
array_walk( $_POST, array( $this, 'strip_cr_callback' ) );
|
160 |
if ( isset ( $_POST['say_what_string_id'] ) ) {
|
161 |
$sql = "UPDATE {$table_prefix}say_what_strings
|
162 |
SET orig_string = %s,
|
say-what-frontend.php
CHANGED
@@ -25,31 +25,64 @@ class SayWhatFrontend {
|
|
25 |
$this->replacements[ $value['domain'] ][ $value['orig_string'] ][ $value['context'] ] = $value['replacement_string'];
|
26 |
}
|
27 |
add_filter( 'gettext', array( $this, 'gettext' ), 10, 3 );
|
|
|
28 |
add_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 );
|
|
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
* Perform a string replacement without context.
|
33 |
*/
|
34 |
public function gettext( $translated, $original, $domain ) {
|
35 |
-
return $this->
|
36 |
}
|
37 |
|
38 |
/**
|
39 |
* Perform a string replacement with context.
|
40 |
-
*
|
41 |
-
* Plugins can use the say_what_domain_aliases filter to return an alias for their domain
|
42 |
-
* if for any reason they change their text domain and want existing replacements to continue
|
43 |
-
* working. The filter should return an array keyed on the current text domain with the value
|
44 |
-
* set to an array of alternative domains to search for replacements. E.g
|
45 |
-
* $aliases['easy-digital-downloads'][] = 'edd';
|
46 |
-
* return $aliases;
|
47 |
*/
|
48 |
public function gettext_with_context( $translated, $original, $context, $domain ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
static $domain_aliases = null;
|
50 |
if ( $domain_aliases === null ) {
|
51 |
$domain_aliases = apply_filters( 'say_what_domain_aliases', array() );
|
52 |
}
|
|
|
|
|
|
|
|
|
53 |
if ( isset( $this->replacements[ $domain ][ $original ][ $context ] ) ) {
|
54 |
return $this->replacements[ $domain ][ $original ][ $context ];
|
55 |
} elseif ( isset( $domain_aliases[ $domain ] ) ) {
|
25 |
$this->replacements[ $value['domain'] ][ $value['orig_string'] ][ $value['context'] ] = $value['replacement_string'];
|
26 |
}
|
27 |
add_filter( 'gettext', array( $this, 'gettext' ), 10, 3 );
|
28 |
+
add_filter( 'ngettext', array( $this, 'ngettext' ), 10, 5 );
|
29 |
add_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 );
|
30 |
+
add_filter( 'ngettext_with_context', array( $this, 'ngettext_with_context' ), 10, 6 );
|
31 |
}
|
32 |
|
33 |
/**
|
34 |
* Perform a string replacement without context.
|
35 |
*/
|
36 |
public function gettext( $translated, $original, $domain ) {
|
37 |
+
return $this->ngettext_with_context( $translated, $original, null, null, 'sw-default-context', $domain );
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
* Perform a string replacement with context.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
*/
|
43 |
public function gettext_with_context( $translated, $original, $context, $domain ) {
|
44 |
+
return $this->ngettext_with_context( $translated, $original, null, null, $context, $domain );
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Perform a (possibly) pluralised translation without context.
|
49 |
+
*/
|
50 |
+
public function ngettext( $translated, $single, $plural, $number, $domain ) {
|
51 |
+
return $this->ngettext_with_context( $translated, $single, $plural, $number, 'sw-default-context', $domain );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Perform a (possibly) pluralised translation with context.
|
56 |
+
*
|
57 |
+
* Note: This also handles the main logic for all other replacements.
|
58 |
+
*
|
59 |
+
* @param string $translated The current string.
|
60 |
+
* @param string $single The original (singular) string.
|
61 |
+
* @param string $plural The original (pluralised) string.
|
62 |
+
* [May be NULL for non _n()-type calls]
|
63 |
+
* @param int $number The number used to determine if singular or pluralised should be used.
|
64 |
+
* [May be NULL for non _n()-type calls]
|
65 |
+
* @param [type] $context The context, may be null for non _x()-type calls.
|
66 |
+
* @param [type] $domain The domain.
|
67 |
+
* @return [type] The replaced string.
|
68 |
+
*/
|
69 |
+
public function ngettext_with_context( $translated, $single, $plural, $number, $context, $domain ) {
|
70 |
+
/*
|
71 |
+
* Plugins can use the say_what_domain_aliases filter to return an alias for their domain
|
72 |
+
* if for any reason they change their text domain and want existing replacements to continue
|
73 |
+
* working. The filter should return an array keyed on the current text domain with the value
|
74 |
+
* set to an array of alternative domains to search for replacements. E.g
|
75 |
+
* $aliases['easy-digital-downloads'][] = 'edd';
|
76 |
+
* return $aliases;
|
77 |
+
*/
|
78 |
static $domain_aliases = null;
|
79 |
if ( $domain_aliases === null ) {
|
80 |
$domain_aliases = apply_filters( 'say_what_domain_aliases', array() );
|
81 |
}
|
82 |
+
$original = $single;
|
83 |
+
if ( !is_null( $number ) && $number != 1 ) {
|
84 |
+
$original = $plural;
|
85 |
+
}
|
86 |
if ( isset( $this->replacements[ $domain ][ $original ][ $context ] ) ) {
|
87 |
return $this->replacements[ $domain ][ $original ][ $context ];
|
88 |
} elseif ( isset( $domain_aliases[ $domain ] ) ) {
|
say-what.php
CHANGED
@@ -4,13 +4,14 @@
|
|
4 |
Plugin Name: Say What?
|
5 |
Plugin URI: https://github.com/leewillis77/say-what
|
6 |
Description: An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code
|
7 |
-
Version: 1.
|
8 |
Author: Lee Willis
|
9 |
Author URI: http://www.leewillis.co.uk/
|
|
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
-
* Copyright (c)
|
14 |
*
|
15 |
* Released under the GPL license
|
16 |
* http://www.opensource.org/licenses/gpl-license.php
|
4 |
Plugin Name: Say What?
|
5 |
Plugin URI: https://github.com/leewillis77/say-what
|
6 |
Description: An easy-to-use plugin that allows you to alter strings on your site without editing WordPress core, or plugin code
|
7 |
+
Version: 1.7
|
8 |
Author: Lee Willis
|
9 |
Author URI: http://www.leewillis.co.uk/
|
10 |
+
Text Domain: say_what
|
11 |
*/
|
12 |
|
13 |
/**
|
14 |
+
* Copyright (c) 2016 Ademti Software Ltd. All rights reserved.
|
15 |
*
|
16 |
* Released under the GPL license
|
17 |
* http://www.opensource.org/licenses/gpl-license.php
|