Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r42201 r42343  
    401401 * @return string The translated singular or plural form.
    402402 */
    403 function _nx($single, $plural, $number, $context, $domain = 'default') {
     403function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
    404404    $translations = get_translations_for_domain( $domain );
    405405    $translation  = $translations->translate_plural( $single, $plural, $number, $context );
     
    450450 */
    451451function _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    );
    453460}
    454461
     
    462469 *
    463470 *     $messages = array(
    464  *          'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
    465  *          'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
     471 *          'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
     472 *          'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
    466473 *     );
    467474 *     ...
     
    489496 */
    490497function _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    );
    492507}
    493508
     
    513528 */
    514529function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
    515     if ( $nooped_plural['domain'] )
     530    if ( $nooped_plural['domain'] ) {
    516531        $domain = $nooped_plural['domain'];
    517 
    518     if ( $nooped_plural['context'] )
     532    }
     533
     534    if ( $nooped_plural['context'] ) {
    519535        return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
    520     else
     536    } else {
    521537        return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
     538    }
    522539}
    523540
     
    582599    $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
    583600
    584     if ( !is_readable( $mofile ) ) return false;
     601    if ( ! is_readable( $mofile ) ) {
     602        return false;
     603    }
    585604
    586605    $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    }
    591613
    592614    unset( $l10n_unloaded[ $domain ] );
    593615
    594     $l10n[$domain] = &$mo;
     616    $l10n[ $domain ] = &$mo;
    595617
    596618    return true;
     
    638660    do_action( 'unload_textdomain', $domain );
    639661
    640     if ( isset( $l10n[$domain] ) ) {
    641         unset( $l10n[$domain] );
     662    if ( isset( $l10n[ $domain ] ) ) {
     663        unset( $l10n[ $domain ] );
    642664
    643665        $l10n_unloaded[ $domain ] = true;
     
    672694    $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
    673695
    674     if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists(  WP_LANG_DIR . "/admin-$locale.mo" ) ) {
     696    if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
    675697        load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
    676698        return $return;
     
    681703    }
    682704
    683     if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
     705    if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) {
    684706        load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
     707    }
    685708
    686709    return $return;
     
    817840 */
    818841function load_child_theme_textdomain( $domain, $path = false ) {
    819     if ( ! $path )
     842    if ( ! $path ) {
    820843        $path = get_stylesheet_directory();
     844    }
    821845    return load_theme_textdomain( $domain, $path );
    822846}
     
    9911015 */
    9921016function 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' );
    9941018}
    9951019
     
    10431067 */
    10441068function wp_get_installed_translations( $type ) {
    1045     if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' )
     1069    if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) {
    10461070        return array();
     1071    }
    10471072
    10481073    $dir = 'core' === $type ? '' : "/$type";
    10491074
    1050     if ( ! is_dir( WP_LANG_DIR ) )
     1075    if ( ! is_dir( WP_LANG_DIR ) ) {
    10511076        return array();
    1052 
    1053     if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )
     1077    }
     1078
     1079    if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) {
    10541080        return array();
     1081    }
    10551082
    10561083    $files = scandir( WP_LANG_DIR . $dir );
    1057     if ( ! $files )
     1084    if ( ! $files ) {
    10581085        return array();
     1086    }
    10591087
    10601088    $language_data = array();
     
    10701098            continue;
    10711099        }
    1072         if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) )  {
     1100        if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) {
    10731101            continue;
    10741102        }
     
    10921120 */
    10931121function 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    );
    11001130    foreach ( $headers as $header => $value ) {
    11011131        // Remove possible contextual '\n' and closing double quote.
     
    11341164function wp_dropdown_languages( $args = array() ) {
    11351165
    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    );
    11461178
    11471179    // Bail if no ID or no name.
     
    12111243    );
    12121244
    1213     // List installed languages. 
     1245    // List installed languages.
    12141246    foreach ( $languages as $language ) {
    12151247        $structure[] = sprintf(
Note: See TracChangeset for help on using the changeset viewer.