Skip to content

Commit 8026e1a

Browse files
committed
lang name & site localized date format as first suggestion
1 parent 867a99f commit 8026e1a

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

classes/suggested-tasks/providers/class-set-date-format.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ public function should_add_task() {
112112
*/
113113
public function print_popover_instructions() {
114114
$detected_date_format = $this->get_date_format_type();
115+
116+
// Get the site default language name.
117+
$available_languages = wp_get_available_translations();
118+
$site_locale = get_locale();
119+
120+
if ( isset( $available_languages[ $site_locale ] ) ) {
121+
$lang_name = $available_languages[ $site_locale ]['english_name'];
122+
} elseif ( function_exists( 'locale_get_display_name' ) ) {
123+
$lang_name = locale_get_display_name( $site_locale, 'en' );
124+
} else {
125+
$lang_name = $site_locale;
126+
}
115127
?>
116128
<?php if ( 'wp_default' === $detected_date_format ) : ?>
117129
<p><?php \esc_html_e( 'Choosing the right date format helps your visitors instantly understand when something was published without confusion or guessing. It also makes your site feel more familiar and trustworthy, especially if your audience is local.', 'progress-planner' ); ?></p>
@@ -124,7 +136,7 @@ public function print_popover_instructions() {
124136
\printf(
125137
/* translators: %s: The date format. */
126138
\esc_html__( 'The date format currently set matches the default format for your site language (%s). Therefore, we expect it\'s set correctly. But can you have a quick look, just to be sure?', 'progress-planner' ),
127-
\esc_html( \get_option( 'date_format' ) )
139+
\esc_html( $lang_name )
128140
);
129141
?>
130142
</p>
@@ -143,12 +155,24 @@ public function print_popover_instructions() {
143155
* @return void
144156
*/
145157
public function print_popover_form_contents() {
158+
159+
// Default date format, based on the user's locale.
160+
$localized_default_date_format = \__( 'F j, Y' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- We want localized date format from WP Core.
161+
162+
// Try to get the localized default date format.
163+
$site_locale = get_locale();
164+
$user_locale = get_user_locale();
165+
if ( $user_locale !== $site_locale && switch_to_locale( $site_locale ) ) {
166+
$localized_default_date_format = \__( 'F j, Y' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- We want localized date format from WP Core.
167+
restore_previous_locale();
168+
}
169+
146170
/**
147171
* Filters the default date formats.
148172
*
149173
* @param string[] $default_date_formats Array of default date formats.
150174
*/
151-
$prpl_date_formats = \array_unique( \apply_filters( 'date_formats', [ \__( 'F j, Y' ), 'F j, Y', 'Y-m-d', 'm/d/Y', 'd/m/Y', 'd.m.Y' ] ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, WordPress.WP.I18n.MissingArgDomain -- WP core filter & we want to add the default date format
175+
$prpl_date_formats = \array_unique( \apply_filters( 'date_formats', [ $localized_default_date_format, 'F j, Y', 'Y-m-d', 'm/d/Y', 'd/m/Y', 'd.m.Y' ] ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, WordPress.WP.I18n.MissingArgDomain -- WP core filter & we want to add the default date format
152176

153177
$prpl_custom = true;
154178
?>

0 commit comments

Comments
 (0)