| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * @since 1.2 |
| 11 | 11 | */ |
| 12 | 12 | class PLL_OLT_Manager { |
| 13 | - protected static $instance; // For singleton | |
| 13 | + static protected $instance; // For singleton | |
| 14 | 14 | protected $default_locale; |
| 15 | 15 | protected $list_textdomains = array(); // All text domains |
| 16 | 16 | public $labels = array(); // Post types and taxonomies labels to translate |
| 17 | 17 | |
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | add_filter( 'pre_update_option_active_sitewide_plugins', array( $this, 'make_polylang_first' ) ); |
| 27 | 27 | |
| 28 | 28 | // Overriding load text domain only on front since WP 4.7 |
| 29 | 29 | // FIXME test get_user_locale for backward compatibility with WP < 4.7 |
| 30 | - if ( is_admin() && ! Polylang::is_ajax_on_front() && function_exists( 'get_user_locale' ) ) { | |
| 30 | + if ( is_admin() && function_exists( 'get_user_locale' ) ) { | |
| 31 | 31 | return; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // Saves the default locale before we start any language manipulation |
| @@ -41,8 +41,9 @@ | ||
| 41 | 41 | |
| 42 | 42 | // Loads text domains |
| 43 | 43 | add_action( 'pll_language_defined', array( $this, 'load_textdomains' ), 2 ); // After PLL_Frontend::pll_language_defined |
| 44 | 44 | add_action( 'pll_no_language_defined', array( $this, 'load_textdomains' ) ); |
| 45 | + | |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | /** |
| 48 | 49 | * Access to the single instance of the class |
| @@ -50,9 +51,9 @@ | ||
| 50 | 51 | * @since 1.7 |
| 51 | 52 | * |
| 52 | 53 | * @return object |
| 53 | 54 | */ |
| 54 | - public static function instance() { | |
| 55 | + static public function instance() { | |
| 55 | 56 | if ( empty( self::$instance ) ) { |
| 56 | 57 | self::$instance = new self(); |
| 57 | 58 | } |
| 58 | 59 | |
| @@ -70,14 +71,15 @@ | ||
| 70 | 71 | remove_filter( 'gettext', array( $this, 'gettext' ), 10, 3 ); |
| 71 | 72 | remove_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 ); |
| 72 | 73 | $new_locale = get_locale(); |
| 73 | 74 | |
| 75 | + | |
| 74 | 76 | // Don't try to save time for en_US as some users have theme written in another language |
| 75 | - // Now we can load all overridden text domains with the right language | |
| 77 | + // Now we can load all overriden text domains with the right language | |
| 76 | 78 | if ( ! empty( $this->list_textdomains ) ) { |
| 77 | 79 | |
| 78 | 80 | // Since WP 4.7 we need to reset the internal cache of _get_path_to_translation when switching from any locale to en_US |
| 79 | - // See WP_Locale_Switcher::change_locale() | |
| 81 | + // See WP_Locale_Switcher::changle_locale() | |
| 80 | 82 | // FIXME test _get_path_to_translation for backward compatibility with WP < 4.7 |
| 81 | 83 | if ( function_exists( '_get_path_to_translation' ) ) { |
| 82 | 84 | _get_path_to_translation( null, true ); |
| 83 | 85 | } |
| @@ -94,16 +96,16 @@ | ||
| 94 | 96 | } |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | // First remove taxonomies and post_types labels that we don't need to translate |
| 98 | - $taxonomies = get_taxonomies( array( '_pll' => true ) ); | |
| 99 | - $post_types = get_post_types( array( '_pll' => true ) ); | |
| 100 | + $taxonomies = array( 'language', 'term_language', 'term_translations', 'post_translations' ); | |
| 101 | + $post_types = array( 'polylang_mo' ); | |
| 100 | 102 | |
| 101 | 103 | // We don't need to translate core taxonomies and post types labels when setting the language from the url |
| 102 | 104 | // As they will be translated when registered the second time |
| 103 | 105 | if ( ! did_action( 'setup_theme' ) ) { |
| 104 | - $taxonomies = array_merge( get_taxonomies( array( '_builtin' => true ) ), $taxonomies ); | |
| 105 | - $post_types = array_merge( get_post_types( array( '_builtin' => true ) ), $post_types ); | |
| 106 | + $taxonomies = array_merge( array( 'category', 'post_tag', 'nav_menu', 'link_category', 'post_format' ), $taxonomies ); | |
| 107 | + $post_types = array_merge( array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' ), $post_types ); | |
| 106 | 108 | } |
| 107 | 109 | |
| 108 | 110 | // Translate labels of post types and taxonomies |
| 109 | 111 | foreach ( array_diff_key( $GLOBALS['wp_taxonomies'], array_flip( $taxonomies ) ) as $tax ) { |
| @@ -159,14 +161,9 @@ | ||
| 159 | 161 | * @param string $domain text domain name |
| 160 | 162 | * @return bool |
| 161 | 163 | */ |
| 162 | 164 | public function load_textdomain_mofile( $mofile, $domain ) { |
| 163 | - // On multisite, 2 files are sharing the same domain so we need to distinguish them | |
| 164 | - if ( 'default' === $domain && false !== strpos( $mofile, '/ms-' ) ) { | |
| 165 | - $this->list_textdomains['ms-default'] = array( 'mo' => $mofile, 'domain' => $domain ); | |
| 166 | - } else { | |
| 167 | - $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain ); | |
| 168 | - } | |
| 165 | + $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain ); | |
| 169 | 166 | return ''; // Hack to prevent WP loading text domains as we will load them all later |
| 170 | 167 | } |
| 171 | 168 | |
| 172 | 169 | /** |
| @@ -215,13 +212,11 @@ | ||
| 215 | 212 | |
| 216 | 213 | foreach ( $type->labels as $key => $label ) { |
| 217 | 214 | if ( is_string( $label ) && isset( $this->labels[ $label ] ) ) { |
| 218 | 215 | if ( empty( $translated[ $label ] ) ) { |
| 219 | - // PHPCS:disable WordPress.WP.I18n | |
| 220 | 216 | $type->labels->$key = $translated[ $label ] = isset( $this->labels[ $label ]['context'] ) ? |
| 221 | 217 | _x( $label, $this->labels[ $label ]['context'], $this->labels[ $label ]['domain'] ) : |
| 222 | 218 | __( $label, $this->labels[ $label ]['domain'] ); |
| 223 | - // PHPCS:enable | |
| 224 | 219 | } |
| 225 | 220 | else { |
| 226 | 221 | $type->labels->$key = $translated[ $label ]; |
| 227 | 222 | } |