Skip Navigation

[Resolved] Front end search date picker not showing in Danish when WordPress set to Danish

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user has a view datepicker filter that is not localized to the website language.

Solution:
The problem here is on WordPress: in v. 4.6 they decided to include the datepicker localization just in time when the datepicker script is enqueued. All works fine, as long as this datepicker script is loaded in the header.

In Views, we avoid loading scripts by default: we load them only when needed. That means that we include the datepicker script only if we have a date frontend filter. Unfortunately, that means that the script is enqueued in the footer, and the mechanism to load the localization automatically is not fired.

We have opened a new ticket for WordPress here https://core.trac.wordpress.org/ticket/50040

And we can force WordPress to localize the datepicker with the following code:

add_action( 'wp_print_footer_scripts', 'prefix_localize_jquery_ui_datepicker', 9 );
 
function prefix_localize_jquery_ui_datepicker() {
    if ( ! function_exists( 'wp_localize_jquery_ui_datepicker' ) ) {
        return;
    }
     
    wp_localize_jquery_ui_datepicker();
}

You can add this code in a new plugin, your (child)theme or in Toolset->Settings->Custom code.

Another workaround is to copy the localization(of datepicker) code inside the Javascript section of the view.

100% of people find this useful.

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 10 replies, has 2 voices.

Last updated by bobA-2 4 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#1600431
Untitled-1.jpg

I have a test site new danish language WordPress install and only WP View and Types plugins installed. I cannot get front end search datepicker to show localized Danish day and month names. Only English. Using Display the results using a custom search View

Should it not use the data in wp-content\plugins\wp-views\embedded\res\js\i18n\jquery.ui.datepicker-da.js ?

#1600905

Hello and thank you for contacting the Toolset support.

I am not sure If Toolset should enqueue the translation for the date-picker by default. I'll check this with the team and get back to you.

In the meanwhile, you can add the content of the translation script to the Javascript section of the view. I tested it on your test view and it worked.

#1600907

Thanks for your reply. I belive it has worked before and according to this https://toolset.com/forums/topic/wrong-translation-of-the-views-datepicker-in-the-frontend/ it seems it should work without needing to do anything. Since the test site uses no other plugins and default WordPress theme I cannot figure out what is preventing it working.

#1604043

Yes, that's what I also think. Toolset should load the correct language file for the date picker. I'll wait for our 2nd Tier for another opinion before checking with our developers.

I just want to confirm that the workaround works for you? copying the content of the translation script to the Javascript section of the view. It is important for us, at support, to find a workaround when an issue is not yet resolved.

#1604153

Yes I can use the workaround. Thanks.

#1604563

Our 2nd Tier was not able to reproduce the issue, so, I run another test on a clean installation with the following plugins without reproducing the issue:
- Toolset Types.
- Toolset Blocks.
- Toolset Forms.
Every time I change the site language the date-picker was correctly localized. This might be a compatibility issue with another plugin or the theme. Please check if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Fourteen. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at the time to track where the incompatibility is produced.

If the problem persists, it is probably because of an exception caused by your site data, I'll need to take a Duplicator copy of your website for further analysis.

#1604609

Hi the test site is WordPress with Twenty Theme and only Types and WP-Views installed. So cannot see any plugins or the theme being the issue. I just tried to remove your workaround JS in the view and set theme to Twenty Fourteen same issue showing date picker in English.

I set the test site up because I saw it on my production site. I could do a Duplicator for you if you want but I think you got login details already?

#1605447

I took a copy of your website for further investigation. I'll get back to you as soon as we found something.

#1605883

The issue was not reproduced on my last installation because I have Toolset Forms activated. The issue seems to appear when only Views is active.

I escalated this ticket to our 2nd Tier for further debugging. I'll get back to you as soon as possible.

#1608075

Our developers have found the cause of this issue. The problem here is on WordPress: in v. 4.6 they decided to include the datepicker localization just in time when the datepicker script is enqueued. All works fine, as long as this datepicker script is loaded in the header.

In Views, we avoid loading scripts by default: we load them only when needed. That means that we include the datepicker script only if we have a date frontend filter. Unfortunately, that means that the script is enqueued in the footer, and the mechanism to load the localization automatically is not fired.

We have opened a new ticket for WordPress here https://core.trac.wordpress.org/ticket/50040

And we can force WordPress to localize the datepicker with the following code:

add_action( 'wp_print_footer_scripts', 'prefix_localize_jquery_ui_datepicker', 9 );

function prefix_localize_jquery_ui_datepicker() {
	if ( ! function_exists( 'wp_localize_jquery_ui_datepicker' ) ) {
		return;
	}
	
	wp_localize_jquery_ui_datepicker();
}

You can add this code in a new plugin, your (child)theme or in Toolset->Settings->Custom code.

I hope this helps. Let me know your feedback.

#1608205

Ok thanks for the detailed explanation and workaround.