Changeset 57287
- Timestamp:
- 01/15/2024 07:03:27 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-textdomain-registry.php
r56178 r57287 52 52 * 53 53 * @since 6.1.0 54 54 55 * 55 56 * @var array 57 58 56 59 */ 57 60 protected $cached_mo_files = array(); … … 65 68 */ 66 69 protected $domains_with_translations = array(); 70 71 72 73 74 75 76 77 78 79 80 81 67 82 68 83 /** … … 136 151 137 152 /** 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 138 253 * Returns possible language directory paths for a given text domain. 139 254 * … … 157 272 158 273 /** 159 * Gets the path to the language directory for the current locale.274 * Gets the path to the language directory for the current locale. 160 275 * 161 276 * Checks the plugins and themes language directories as well as any … … 176 291 177 292 foreach ( $locations as $location ) { 178 if ( ! isset( $this->cached_mo_files[ $location ] ) ) { 179 $this->set_cached_mo_files( $location ); 180 } 293 $files = $this->get_language_files_from_path( $location ); 181 294 182 295 $path = "$location/$domain-$locale.mo"; 183 296 184 foreach ( $ this->cached_mo_files[ $location ]as $mo_path ) {297 foreach ( $ as $mo_path ) { 185 298 if ( 186 299 ! in_array( $domain, $this->domains_with_translations, true ) && … … 216 329 return false; 217 330 } 218 219 /**220 * Reads and caches all available MO files from a given directory.221 *222 * @since 6.1.0223 *224 * @param string $path Language directory path.225 */226 private function set_cached_mo_files( $path ) {227 $this->cached_mo_files[ $path ] = array();228 229 $mo_files = glob( $path . '/*.mo' );230 231 if ( $mo_files ) {232 $this->cached_mo_files[ $path ] = $mo_files;233 }234 }235 331 } -
trunk/src/wp-includes/l10n.php
r57286 r57287 1399 1399 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter. 1400 1400 * 1401 1402 1401 1403 * @param string $dir A directory to search for language files. 1402 1404 * Default WP_LANG_DIR. … … 1405 1407 */ 1406 1408 function get_available_languages( $dir = null ) { 1409 1410 1407 1411 $languages = array(); 1408 1412 1409 $lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' ); 1413 $path = is_null( $dir ) ? WP_LANG_DIR : $dir; 1414 $lang_files = $wp_textdomain_registry->get_language_files_from_path( $path ); 1415 1410 1416 if ( $lang_files ) { 1411 1417 foreach ( $lang_files as $lang_file ) { -
trunk/src/wp-settings.php
r57269 r57287 381 381 */ 382 382 $GLOBALS['wp_textdomain_registry'] = new WP_Textdomain_Registry(); 383 383 384 384 385 // Load multisite-specific files. -
trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php
r55010 r57287 19 19 } 20 20 21 22 23 24 25 26 27 28 29 21 30 /** 22 31 * @covers ::has … … 25 34 */ 26 35 public function test_set_custom_path() { 27 $reflection = new ReflectionClass( $this->instance );28 $reflection_property = $reflection->getProperty( 'cached_mo_files' );29 $reflection_property->setAccessible( true );30 31 $this->assertEmpty(32 $reflection_property->getValue( $this->instance ),33 'Cache not empty by default'34 );35 36 36 $this->instance->set_custom_path( 'foo', WP_LANG_DIR . '/bar' ); 37 37 … … 49 49 'Custom path for textdomain not returned' 50 50 ); 51 $this->assertArrayHasKey( 52 WP_LANG_DIR . '/bar', 53 $reflection_property->getValue( $this->instance ), 54 'Custom path missing from cache' 51 $this->assertNotFalse( 52 wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . 'bar/' ), 'translations' ), 53 'List of files in custom path not cached' 55 54 ); 56 55 } … … 61 60 */ 62 61 public function test_get( $domain, $locale, $expected ) { 63 $reflection = new ReflectionClass( $this->instance );64 $reflection_property = $reflection->getProperty( 'cached_mo_files' );65 $reflection_property->setAccessible( true );66 67 62 $actual = $this->instance->get( $domain, $locale ); 68 63 $this->assertSame( … … 70 65 $actual, 71 66 'Expected languages directory path not matching actual one' 72 );73 74 $this->assertArrayHasKey(75 WP_LANG_DIR . '/plugins',76 $reflection_property->getValue( $this->instance ),77 'Default plugins path missing from cache'78 67 ); 79 68 } … … 90 79 $this->instance->get( 'foo-plugin', 'de_DE' ) 91 80 ); 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 92 150 } 93 151
Note: See TracChangeset
for help on using the changeset viewer.