Make WordPress Core

Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#36859 closed enhancement (wontfix)

Patch to allow the current locale to be changed on the fly including fetching missing language files

Reported by: pbearne Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-unit-tests
Focuses: Cc:


We are trying to write unit tests that need to have different locales set the current WP_locale constructor doesn't allow a setting of the language.

So we have added an optional parameter to the constructor to allow us to swap at will the current locale loaded.

As the language files may not be preloaded we fetch them if need.

Attachments (1)

wp_locale.patch (2.3 KB) - added by pbearne 21 months ago.
wp_local and unit_test patch

Download all attachments as: .zip

Change History (7)

21 months ago

wp_local and unit_test patch

#1 @pbearne
21 months ago

  • Keywords has-patch dev-feedback has-unit-tests added

#3 @ocean90
21 months ago

  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
  • Version trunk deleted

Hello @pbearne, thanks for your patch.

Putting wp_download_language_pack() into WP_Locale is interesting but that doesn't work pretty well. It doesn't work if DISALLOW_FILE_MODS is set or a download fails. Doing an external HTTP request for a locale switch isn't really performant either.

I'm going to close this ticket as a wontfix but you should definitely take a look at #35585 and #26511.

#4 follow-up: @pbearne
21 months ago

@ocean90 I was just reading the trac

I hear you about DISALLOW_FILE_MODS and I wonder if we can still build in some effort to fetch the files and handle the fail.

What happens when the patch in #26511 switches and the language is not installed?

Yes I know is not performant but it only every happens once.

I am not sure want we should end up with. But been able to switch the Locale is useful what you take a patch without the download that just switches the language? maybe with a "do it wrong error" if the language is missing?

What to do yu feel is the right way do this?


#5 @pbearne
21 months ago

the reason we wrote this was we were trying to write Unit test like this

        function test_number_format_i18n_custom_separator() {
                global $wp_locale;
                $wp_locale->number_format['decimal_point'] = '@';
                $wp_locale->number_format['thousands_sep'] = '^';

                $this->assertEquals( '1^000@00', number_format_i18n( 1000.00, 2 ) );
                $this->assertEquals( '1^000@00', number_format_i18n( (int)1000, 2 ) );
                $this->assertEquals( '1^234^567^890@00000', number_format_i18n( 1234567890.00, 5 ) );
                $this->assertEquals( '1^234^567^890@99999', number_format_i18n( 1234567890.99999, 5 ) );
                $this->assertEquals( '1^234^567^890@50000', number_format_i18n( 1234567890.5, 5 ) );
                // clear $wp_locale
                $wp_locale = null;

and have no way to swap the locale other than just setting it which feels wrong

#6 in reply to: ↑ 4 @ocean90
21 months ago

Replying to pbearne:

What happens when the patch in #26511 switches and the language is not installed?

This would only allow to switch to existing locales. Language downloading and locale switching are two separate processes.

Note: See TracTickets for help on using tickets.