Make WordPress Core

Ticket #36859: wp_locale.patch

File wp_locale.patch, 2.3 KB (added by pbearne, 9 years ago)

wp_local and unit_test patch

  • src/wp-includes/locale.php

     
    359359         * Constructor which calls helper methods to set up object variables
    360360         *
    361361         * @since 2.1.0
     362         * @param null $lang to change the current locale
    362363         */
    363         public function __construct() {
     364        public function __construct( $lang = null ) {
     365                if ( null !== $lang ) {
     366                        require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     367                        global $locale;
     368
     369                        if( ! in_array( $lang, get_available_languages() ) ) {
     370                                if ( array_key_exists( $lang, wp_get_available_translations() ) ) {
     371                                        $language = wp_download_language_pack( $lang );
     372                                        if ( $language ) {
     373                                                load_default_textdomain( $language );
     374                                                $locale = $language;
     375                                        }
     376                                }
     377                        } else{
     378                                load_default_textdomain( $lang );
     379                                $locale = $lang;
     380                        }
     381                }
     382
    364383                $this->init();
    365384                $this->register_globals();
    366385        }
  • tests/phpunit/tests/locale/test-locale.php

     
     1<?php
     2/**
     3 * wordpress-develop.
     4 * User: Paul
     5 * Date: 2016-05-16
     6 *
     7 */
     8
     9if ( !defined( 'WPINC' ) ) {
     10        die;
     11}
     12
     13class test_Locale extends WP_UnitTestCase {
     14
     15        static $fr_lanf_files = array(
     16                'admin-fr_FR.mo',
     17                'admin-fr_FR.po',
     18                'admin-network-fr_FR.mo',
     19                'admin-network-fr_FR.po',
     20                'continents-cities-fr_FR.mo',
     21                'continents-cities-fr_FR.po',
     22                'fr_FR.mo',
     23                'fr_FR.po',
     24        );
     25
     26
     27        /**
     28         * pass a new locale into WP_locale and reset current locale
     29         */
     30        function test_WP_locale(){
     31
     32                global $GLOBALS;
     33
     34                $GLOBALS['wp_locale'] = new WP_Locale( 'fr_FR' );
     35
     36                $this->assertEquals( 'fr_FR', get_locale() );
     37
     38                $this->assertEquals( 'dimanche', $GLOBALS['wp_locale']->weekday[0] );
     39
     40                foreach ( self::$fr_lanf_files as $file ) {
     41                        $this->assertEquals( true, file_exists( WP_LANG_DIR . '/' . $file ) );
     42                }
     43
     44                // remove any fr lang files
     45                $this->remove_lang_files();
     46        }
     47
     48        function remove_lang_files() {
     49                foreach ( self::$fr_lanf_files as $file ) {
     50                        $this->unlink( WP_LANG_DIR . '/' . $file );
     51                }
     52        }
     53}