Changeset 58062 for trunk/src/wp-includes/l10n.php
- Timestamp:
- 04/30/2024 08:37:25 AM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.