Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect users locale #747

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Respect users locale #747

merged 2 commits into from
Aug 1, 2024

Conversation

carstingaxion
Copy link
Collaborator

@carstingaxion carstingaxion commented Jul 31, 2024

Description of the Change

Closes #746

How to test the Change

BEFORE: Steps to reproduce the problem

  1. Have English selected in Settings > General as Site language.
  2. Edit your user profile, choose a different language for your user and save!
  3. See the main admin menu changed into your users language.
  4. Go to Plugins and toggle the activation of the plugin on and off.
    A. Plugin not activated: Admin Bar is translated into your users language
    B. Plugin activated: Admin Bar is NOT translated, shows in English

AFTER (applying this PR): Steps to see working solution

  1. Have English selected in Settings > General as Site language.
  2. Edit your user profile, choose a different language for your user and save!
  3. See the main admin menu changed into your users language.
  4. Go to Plugins and toggle the activation of the plugin on and off.
    A. Plugin not activated: Admin Bar is translated into your users language
    B. Plugin activated: Admin Bar is (now also) translated into your users language

Changelog Entry

Fixed - Do respect the logged-in users locale within the Admin UI.

Credits

Props @carstingaxion

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Copy link

what-the-diff bot commented Jul 31, 2024

PR Summary

  • Localization Enhancement in User Time Zone Selection
    This PR introduces an upgrade in the timezone selection functionality. Previously, the system presumed a standard timezone for all users. With the changes made, it now accommodates the user's locale (which is their geographical location) to provide more accurate timezone options. This can lead to an improved user experience since the application's time settings will align better with the user's local time.

@carstingaxion
Copy link
Collaborator Author

WordPress core (wp-admin/options-general.php L345-L371) is even more accurate and takes timezone offset into account too:

$current_offset = get_option( 'gmt_offset' );
$tzstring       = get_option( 'timezone_string' );

$check_zone_info = true;

// Remove old Etc mappings. Fallback to gmt_offset.
if ( str_contains( $tzstring, 'Etc/GMT' ) ) {
	$tzstring = '';
}

if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
	$check_zone_info = false;
	if ( 0 === (int) $current_offset ) {
		$tzstring = 'UTC+0';
	} elseif ( $current_offset < 0 ) {
		$tzstring = 'UTC' . $current_offset;
	} else {
		$tzstring = 'UTC+' . $current_offset;
	}
}?>
<th scope="row"><label for="timezone_string"><?php _e( 'Timezone' ); ?></label></th>
<td>

<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">
	<?php echo wp_timezone_choice( $tzstring, get_user_locale() ); ?>

where GatherPress just states:

$timezones_raw = explode( PHP_EOL, wp_timezone_choice( 'UTC', get_user_locale() ) );

Maybe a chance for later improvement, maybe essentially needed; I don't know.

@carstingaxion carstingaxion marked this pull request as ready for review August 1, 2024 19:10
@mauteri
Copy link
Contributor

mauteri commented Aug 1, 2024

@carstingaxion tested this and works as you described. merging! nice job on this!

@mauteri mauteri merged commit 2a18dba into GatherPress:main Aug 1, 2024
12 of 13 checks passed
@carstingaxion carstingaxion deleted the fix/746 branch August 13, 2024 20:11
@carstingaxion carstingaxion restored the fix/746 branch August 13, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugin activation switches user-locale partly
2 participants