| @@ -8,33 +8,15 @@ | ||
| 8 | 8 | * |
| 9 | 9 | * @since 1.6 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Admin_Strings { |
| 12 | - /** | |
| 13 | - * Stores the strings to translate. | |
| 14 | - * | |
| 15 | - * @var array { | |
| 16 | - * @type string $name A unique name for the string. | |
| 17 | - * @type string $string The actual string to translate. | |
| 18 | - * @type string $context The group in which the string is registered. | |
| 19 | - * @type bool $multiline Whether the string table should display a multiline textarea or a single line input. | |
| 20 | - * } | |
| 21 | - */ | |
| 22 | - protected static $strings = array(); | |
| 12 | + protected static $strings = array(); // strings to translate | |
| 13 | + protected static $default_strings; // default strings to register | |
| 23 | 14 | |
| 24 | 15 | /** |
| 25 | - * The strings to register by default. | |
| 26 | - * | |
| 27 | - * @var string[] | |
| 28 | - */ | |
| 29 | - protected static $default_strings; | |
| 30 | - | |
| 31 | - /** | |
| 32 | 16 | * Add filters |
| 33 | 17 | * |
| 34 | 18 | * @since 1.6 |
| 35 | - * | |
| 36 | - * @return void | |
| 37 | 19 | */ |
| 38 | 20 | public static function init() { |
| 39 | 21 | // default strings translations sanitization |
| 40 | 22 | add_filter( 'pll_sanitize_string_translation', array( __CLASS__, 'sanitize_string_translation' ), 10, 2 ); |
| @@ -48,11 +30,16 @@ | ||
| 48 | 30 | * @param string $name A unique name for the string |
| 49 | 31 | * @param string $string The string to register |
| 50 | 32 | * @param string $context Optional, the group in which the string is registered, defaults to 'polylang' |
| 51 | 33 | * @param bool $multiline Optional, whether the string table should display a multiline textarea or a single line input, defaults to single line |
| 52 | - * @return void | |
| 53 | 34 | */ |
| 54 | 35 | public static function register_string( $name, $string, $context = 'Polylang', $multiline = false ) { |
| 36 | + // Backward compatibility with Polylang older than 1.1 | |
| 37 | + if ( is_bool( $context ) ) { | |
| 38 | + $multiline = $context; | |
| 39 | + $context = 'Polylang'; | |
| 40 | + } | |
| 41 | + | |
| 55 | 42 | if ( $string && is_scalar( $string ) ) { |
| 56 | 43 | self::$strings[ md5( $string ) ] = compact( 'name', 'string', 'context', 'multiline' ); |
| 57 | 44 | } |
| 58 | 45 | } |
| @@ -65,12 +52,23 @@ | ||
| 65 | 52 | * @return array list of all registered strings |
| 66 | 53 | */ |
| 67 | 54 | public static function &get_strings() { |
| 68 | 55 | self::$default_strings = array( |
| 56 | + 'options' => array( | |
| 57 | + 'blogname' => __( 'Site Title', 'polylang' ), | |
| 58 | + 'blogdescription' => __( 'Tagline', 'polylang' ), | |
| 59 | + 'date_format' => __( 'Date Format', 'polylang' ), | |
| 60 | + 'time_format' => __( 'Time Format', 'polylang' ), | |
| 61 | + ), | |
| 69 | 62 | 'widget_title' => __( 'Widget title', 'polylang' ), |
| 70 | 63 | 'widget_text' => __( 'Widget text', 'polylang' ), |
| 71 | 64 | ); |
| 72 | 65 | |
| 66 | + // WP strings | |
| 67 | + foreach ( self::$default_strings['options'] as $option => $string ) { | |
| 68 | + self::register_string( $string, get_option( $option ), 'WordPress' ); | |
| 69 | + } | |
| 70 | + | |
| 73 | 71 | // Widgets titles |
| 74 | 72 | global $wp_registered_widgets; |
| 75 | 73 | $sidebars = wp_get_sidebars_widgets(); |
| 76 | 74 | foreach ( $sidebars as $sidebar => $widgets ) { |
| @@ -122,8 +120,13 @@ | ||
| 122 | 120 | * @param string $name unique name for the string |
| 123 | 121 | * @return string |
| 124 | 122 | */ |
| 125 | 123 | public static function sanitize_string_translation( $translation, $name ) { |
| 124 | + | |
| 125 | + if ( false !== ( $option = array_search( $name, self::$default_strings['options'], true ) ) ) { | |
| 126 | + $translation = sanitize_option( $option, $translation ); | |
| 127 | + } | |
| 128 | + | |
| 126 | 129 | if ( $name == self::$default_strings['widget_title'] ) { |
| 127 | 130 | $translation = sanitize_text_field( $translation ); |
| 128 | 131 | } |
| 129 | 132 | |