Skip to content

Conversation

@kshojib
Copy link
Contributor

@kshojib kshojib commented Apr 18, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #34420 .

This PR fixes the store locale language issues when creating default pages.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Set site language to Spanish.
  2. Delete the default pages (if there are any).
  3. Set language for admin user to English-US.
  4. Create WC default pages from Status > Tools menu.
  5. Run wp post list --post_type=page --fields=post_title,post_name
  6. Page titles and names should be created in store locale language (Spanish).

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Apr 18, 2023
@woocommercebot woocommercebot requested review from a team and barryhughes and removed request for a team April 18, 2023 18:09
chihsuan
chihsuan previously approved these changes Apr 19, 2023
Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! @kshojib Tested well and looks good to me. 🚢

If you are interested, welcome to join our Slack channel for Woocommerce Contributor Day!

https://developer.woocommerce.com/2023/03/31/woocommerce-contributor-day/

@chihsuan chihsuan self-requested a review April 19, 2023 01:44
@chihsuan
Copy link
Member

I think the error occurred because the global variable $wp_locale_switcher has not yet been defined or initialized when we call the WC_Install::install(). Let's see if @barryhughes has any suggestions.

@barryhughes
Copy link
Member

barryhughes commented Apr 19, 2023

I think the error occurred because the global variable $wp_locale_switcher has not yet been defined or initialized when we call the WC_Install::install()

Yes, exactly—and this is really only a problem during test suite setup (because our bootstrap code runs before wp-settings.php, which is where the locale switcher is instantiated). So, I think we'd need to change two further functions.

In the case of wp_switch_to_site_locale() let's add some extra safety (note the extra check for $wp_locale_switcher):

/**
 * Switch WooCommerce to site language.
 *
 * @since 3.1.0
 */
function wc_switch_to_site_locale() {
	global $wp_locale_switcher;

	if ( function_exists( 'switch_to_locale' ) && isset( $wp_locale_switcher ) ) {
		switch_to_locale( get_locale() );

		// Filter on plugin_locale so load_plugin_textdomain loads the correct locale.
		add_filter( 'plugin_locale', 'get_locale' );

		// Init WC locale.
		WC()->load_plugin_textdomain();
	}
}

We would also need to do effectively the same thing for wc_restore_locale(). @kshojib does that all make sense and are you happy to add another commit covering those things?

@kshojib
Copy link
Contributor Author

kshojib commented Apr 20, 2023

Hey @chihsuan Thanks for addressing the error. @barryhughes I have added another commit with your suggestions.

Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you for addressing that! Just waiting on our automated checks passing, and then we can go ahead and merge 👍

@barryhughes barryhughes merged commit bf8d19e into woocommerce:trunk Apr 21, 2023
@github-actions github-actions bot added this to the 7.8.0 milestone Apr 21, 2023
@kshojib kshojib deleted the fix/34420 branch April 21, 2023 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default pages titles created in Admin's language instead of site's language

4 participants