Changeset 42343 for trunk/src/wp-includes/l10n.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r42201 r42343 401 401 * @return string The translated singular or plural form. 402 402 */ 403 function _nx( $single, $plural, $number, $context, $domain = 'default') {403 function _nx( $single, $plural, $number, $context, $domain = 'default' ) { 404 404 $translations = get_translations_for_domain( $domain ); 405 405 $translation = $translations->translate_plural( $single, $plural, $number, $context ); … … 450 450 */ 451 451 function _n_noop( $singular, $plural, $domain = null ) { 452 return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); 452 return array( 453 0 => $singular, 454 1 => $plural, 455 'singular' => $singular, 456 'plural' => $plural, 457 'context' => null, 458 'domain' => $domain, 459 ); 453 460 } 454 461 … … 462 469 * 463 470 * $messages = array( 464 * 465 * 471 * 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ), 472 * 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ), 466 473 * ); 467 474 * ... … … 489 496 */ 490 497 function _nx_noop( $singular, $plural, $context, $domain = null ) { 491 return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); 498 return array( 499 0 => $singular, 500 1 => $plural, 501 2 => $context, 502 'singular' => $singular, 503 'plural' => $plural, 504 'context' => $context, 505 'domain' => $domain, 506 ); 492 507 } 493 508 … … 513 528 */ 514 529 function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { 515 if ( $nooped_plural['domain'] ) 530 if ( $nooped_plural['domain'] ) { 516 531 $domain = $nooped_plural['domain']; 517 518 if ( $nooped_plural['context'] ) 532 } 533 534 if ( $nooped_plural['context'] ) { 519 535 return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); 520 else536 } else { 521 537 return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain ); 538 } 522 539 } 523 540 … … 582 599 $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); 583 600 584 if ( !is_readable( $mofile ) ) return false; 601 if ( ! is_readable( $mofile ) ) { 602 return false; 603 } 585 604 586 605 $mo = new MO(); 587 if ( !$mo->import_from_file( $mofile ) ) return false; 588 589 if ( isset( $l10n[$domain] ) ) 590 $mo->merge_with( $l10n[$domain] ); 606 if ( ! $mo->import_from_file( $mofile ) ) { 607 return false; 608 } 609 610 if ( isset( $l10n[ $domain ] ) ) { 611 $mo->merge_with( $l10n[ $domain ] ); 612 } 591 613 592 614 unset( $l10n_unloaded[ $domain ] ); 593 615 594 $l10n[ $domain] = &$mo;616 $l10n[ $domain ] = &$mo; 595 617 596 618 return true; … … 638 660 do_action( 'unload_textdomain', $domain ); 639 661 640 if ( isset( $l10n[ $domain] ) ) {641 unset( $l10n[ $domain] );662 if ( isset( $l10n[ $domain ] ) ) { 663 unset( $l10n[ $domain ] ); 642 664 643 665 $l10n_unloaded[ $domain ] = true; … … 672 694 $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); 673 695 674 if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( 696 if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { 675 697 load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); 676 698 return $return; … … 681 703 } 682 704 683 if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) 705 if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) { 684 706 load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); 707 } 685 708 686 709 return $return; … … 817 840 */ 818 841 function load_child_theme_textdomain( $domain, $path = false ) { 819 if ( ! $path ) 842 if ( ! $path ) { 820 843 $path = get_stylesheet_directory(); 844 } 821 845 return load_theme_textdomain( $domain, $path ); 822 846 } … … 991 1015 */ 992 1016 function translate_user_role( $name ) { 993 return translate_with_gettext_context( before_last_bar( $name), 'User role' );1017 return translate_with_gettext_context( before_last_bar( $name ), 'User role' ); 994 1018 } 995 1019 … … 1043 1067 */ 1044 1068 function wp_get_installed_translations( $type ) { 1045 if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) 1069 if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) { 1046 1070 return array(); 1071 } 1047 1072 1048 1073 $dir = 'core' === $type ? '' : "/$type"; 1049 1074 1050 if ( ! is_dir( WP_LANG_DIR ) ) 1075 if ( ! is_dir( WP_LANG_DIR ) ) { 1051 1076 return array(); 1052 1053 if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) 1077 } 1078 1079 if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) { 1054 1080 return array(); 1081 } 1055 1082 1056 1083 $files = scandir( WP_LANG_DIR . $dir ); 1057 if ( ! $files ) 1084 if ( ! $files ) { 1058 1085 return array(); 1086 } 1059 1087 1060 1088 $language_data = array(); … … 1070 1098 continue; 1071 1099 } 1072 if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) 1100 if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) { 1073 1101 continue; 1074 1102 } … … 1092 1120 */ 1093 1121 function wp_get_pomo_file_data( $po_file ) { 1094 $headers = get_file_data( $po_file, array( 1095 'POT-Creation-Date' => '"POT-Creation-Date', 1096 'PO-Revision-Date' => '"PO-Revision-Date', 1097 'Project-Id-Version' => '"Project-Id-Version', 1098 'X-Generator' => '"X-Generator', 1099 ) ); 1122 $headers = get_file_data( 1123 $po_file, array( 1124 'POT-Creation-Date' => '"POT-Creation-Date', 1125 'PO-Revision-Date' => '"PO-Revision-Date', 1126 'Project-Id-Version' => '"Project-Id-Version', 1127 'X-Generator' => '"X-Generator', 1128 ) 1129 ); 1100 1130 foreach ( $headers as $header => $value ) { 1101 1131 // Remove possible contextual '\n' and closing double quote. … … 1134 1164 function wp_dropdown_languages( $args = array() ) { 1135 1165 1136 $parsed_args = wp_parse_args( $args, array( 1137 'id' => 'locale', 1138 'name' => 'locale', 1139 'languages' => array(), 1140 'translations' => array(), 1141 'selected' => '', 1142 'echo' => 1, 1143 'show_available_translations' => true, 1144 'show_option_site_default' => false, 1145 ) ); 1166 $parsed_args = wp_parse_args( 1167 $args, array( 1168 'id' => 'locale', 1169 'name' => 'locale', 1170 'languages' => array(), 1171 'translations' => array(), 1172 'selected' => '', 1173 'echo' => 1, 1174 'show_available_translations' => true, 1175 'show_option_site_default' => false, 1176 ) 1177 ); 1146 1178 1147 1179 // Bail if no ID or no name. … … 1211 1243 ); 1212 1244 1213 // List installed languages. 1245 // List installed languages. 1214 1246 foreach ( $languages as $language ) { 1215 1247 $structure[] = sprintf(
Note: See TracChangeset
for help on using the changeset viewer.