Changeset 58062
- Timestamp:
- 04/30/2024 08:37:25 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-admin/includes/class-language-pack-upgrader.php (modified) (3 diffs)
-
src/wp-includes/l10n.php (modified) (4 diffs)
-
tests/phpunit/tests/l10n.php (modified) (2 diffs)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-language-pack-upgrader.php
r57381 r58062 333 333 $files = $wp_filesystem->dirlist( $remote_source ); 334 334 335 // Check to see if a .po and .mo exist in the folder. 336 $po = false; 337 $mo = false; 335 // Check to see if the expected files exist in the folder. 336 $po = false; 337 $mo = false; 338 $php = false; 338 339 foreach ( (array) $files as $file => $filedata ) { 339 340 if ( str_ends_with( $file, '.po' ) ) { … … 341 342 } elseif ( str_ends_with( $file, '.mo' ) ) { 342 343 $mo = true; 343 } 344 } elseif ( str_ends_with( $file, '.l10n.php' ) ) { 345 $php = true; 346 } 347 } 348 349 if ( $php ) { 350 return $source; 344 351 } 345 352 … … 349 356 $this->strings['incompatible_archive'], 350 357 sprintf( 351 /* translators: 1: .po, 2: .mo */352 __( 'The language pack is missing either the %1$s or %2$s files.' ),358 /* translators: 1: .po, 2: .mo, 3: .l10n.php */ 359 __( 'The language pack is missing either the %1$s, %2$s, or %3$s files.' ), 353 360 '<code>.po</code>', 354 '<code>.mo</code>' 361 '<code>.mo</code>', 362 '<code>.l10n.php</code>' 355 363 ) 356 364 ); -
trunk/src/wp-includes/l10n.php
r57925 r58062 1506 1506 * @since 3.7.0 1507 1507 * 1508 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 1509 * 1508 1510 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. 1509 1511 * @return array Array of language data. 1510 1512 */ 1511 1513 function wp_get_installed_translations( $type ) { 1514 global $wp_textdomain_registry; 1515 1512 1516 if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) { 1513 1517 return array(); 1514 1518 } 1515 1519 1516 $dir = 'core' === $type ? '' :"/$type";1517 1518 if ( ! is_dir( WP_LANG_DIR) ) {1520 $dir = 'core' === $type ? WP_LANG_DIR : WP_LANG_DIR . "/$type"; 1521 1522 if ( ! is_dir( $dir ) ) { 1519 1523 return array(); 1520 1524 } 1521 1525 1522 if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) { 1523 return array(); 1524 } 1525 1526 $files = scandir( WP_LANG_DIR . $dir ); 1526 $files = $wp_textdomain_registry->get_language_files_from_path( $dir ); 1527 1527 if ( ! $files ) { 1528 1528 return array(); … … 1532 1532 1533 1533 foreach ( $files as $file ) { 1534 if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) { 1535 continue; 1536 } 1537 if ( ! str_ends_with( $file, '.po' ) ) { 1538 continue; 1539 } 1540 if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { 1541 continue; 1542 } 1543 if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files, true ) ) { 1534 if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?)\.(?:mo|l10n\.php)/', basename( $file ), $match ) ) { 1544 1535 continue; 1545 1536 } … … 1549 1540 $textdomain = 'default'; 1550 1541 } 1551 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); 1542 1543 if ( str_ends_with( $file, '.mo' ) ) { 1544 $pofile = substr_replace( $file, '.po', - strlen( '.mo' ) ); 1545 1546 if ( ! file_exists( $pofile ) ) { 1547 continue; 1548 } 1549 1550 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $pofile ); 1551 } else { 1552 $pofile = substr_replace( $file, '.po', - strlen( '.l10n.php' ) ); 1553 1554 // If both a PO and a PHP file exist, prefer the PO file. 1555 if ( file_exists( $pofile ) ) { 1556 continue; 1557 } 1558 1559 $language_data[ $textdomain ][ $language ] = wp_get_l10n_php_file_data( $file ); 1560 } 1552 1561 } 1553 1562 return $language_data; … … 1577 1586 } 1578 1587 return $headers; 1588 } 1589 1590 /** 1591 * Extracts headers from a PHP translation file. 1592 * 1593 * @since 6.6.0 1594 * 1595 * @param string $php_file Path to a `.l10n.php` file. 1596 * @return string[] Array of file header values keyed by header name. 1597 */ 1598 function wp_get_l10n_php_file_data( $php_file ) { 1599 $data = (array) include $php_file; 1600 1601 unset( $data['messages'] ); 1602 $headers = array( 1603 'POT-Creation-Date' => 'pot-creation-date', 1604 'PO-Revision-Date' => 'po-revision-date', 1605 'Project-Id-Version' => 'project-id-version', 1606 'X-Generator' => 'x-generator', 1607 ); 1608 1609 $result = array( 1610 'POT-Creation-Date' => '', 1611 'PO-Revision-Date' => '', 1612 'Project-Id-Version' => '', 1613 'X-Generator' => '', 1614 ); 1615 1616 foreach ( $headers as $po_header => $php_header ) { 1617 if ( isset( $data[ $php_header ] ) ) { 1618 $result[ $po_header ] = $data[ $php_header ]; 1619 } 1620 } 1621 1622 return $result; 1579 1623 } 1580 1624 -
trunk/tests/phpunit/tests/l10n.php
r54365 r58062 71 71 72 72 $array = get_available_languages( DIR_TESTDATA . '/languages/' ); 73 $this->assertSame( array( 'de_DE', 'en_GB', 'es_ES', 'ja_JP' ), $array ); 73 $this->assertEqualSets( 74 array( 75 'de_DE', 76 'en_GB', 77 'es_ES', 78 'ja_JP', 79 'de_CH', 80 ), 81 $array 82 ); 74 83 } 75 84 76 85 /** 77 86 * @ticket 35284 87 * @ticket 60554 78 88 * 79 89 * @covers ::wp_get_installed_translations 90 * @covers ::wp_get_pomo_file_data 91 * @covers ::wp_get_l10n_php_file_data 80 92 */ 81 93 public function test_wp_get_installed_translations_for_core() { … … 96 108 $this->assertSame( 'Administration', $data_es_es['Project-Id-Version'] ); 97 109 $this->assertSame( 'Poedit 1.8.10', $data_es_es['X-Generator'] ); 110 111 $this->assertNotEmpty( $installed_translations['default']['de_CH'] ); 112 $data_en_gb = $installed_translations['default']['de_CH']; 113 $this->assertSame( '2024-01-31 19:08:22+0000', $data_en_gb['PO-Revision-Date'] ); 114 $this->assertSame( 'WordPress - 6.4.x - Development', $data_en_gb['Project-Id-Version'] ); 115 $this->assertSame( 'GlotPress/4.0.0-beta.2', $data_en_gb['X-Generator'] ); 98 116 } 99 117 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r57628 r58062 9231 9231 "en_GB", 9232 9232 "es_ES", 9233 "ja_JP" 9233 "ja_JP", 9234 "de_CH" 9234 9235 ], 9235 9236 "required": false … … 9362 9363 "en_GB", 9363 9364 "es_ES", 9364 "ja_JP" 9365 "ja_JP", 9366 "de_CH" 9365 9367 ], 9366 9368 "required": false … … 9503 9505 "en_GB", 9504 9506 "es_ES", 9505 "ja_JP" 9507 "ja_JP", 9508 "de_CH" 9506 9509 ], 9507 9510 "required": false
Note: See TracChangeset
for help on using the changeset viewer.