Aleš Sýkora / October 27, 2020 / 2 comments

Translate fluent forms datepicker

Post summary: Need to translate fluent forms datepicker to your language? No problem. The Fluent Forms plugin is a versatile tool for creating customizable forms on WordPress websites. When working with the Datepicker field in Fluent Forms, you may need to translate the months, weekdays, and AM/PM labels to match the desired language. In this article, we…

Need to translate fluent forms datepicker to your language? No problem.

The Fluent Forms plugin is a versatile tool for creating customizable forms on WordPress websites. When working with the Datepicker field in Fluent Forms, you may need to translate the months, weekdays, and AM/PM labels to match the desired language. In this article, we will explore how to achieve this translation using the add_filter function in PHP.

The add_filter function allows us to modify the behavior or output of a specific feature in WordPress by hooking into its existing functionality. In the case of Fluent Forms, we can use this function to modify the date-related strings.

To begin, open the functions.php file of your WordPress theme or create a child theme if you haven’t already. Then, add the following code snippet:

English

add_filter('fluentform/date_i18n', function ($strings) {
    $strings = array(
        'months'   => [
            'shorthand' => [
                __('Jan', 'fluentform'),
                __('Feb', 'fluentform'),
                __('Mar', 'fluentform'),
                __('Apr', 'fluentform'),
                __('May', 'fluentform'),
                __('Jun', 'fluentform'),
                __('Jul', 'fluentform'),
                __('Aug', 'fluentform'),
                __('Sep', 'fluentform'),
                __('Oct', 'fluentform'),
                __('Nov', 'fluentform'),
                __('Dec', 'fluentform')
            ],
            'longhand'  => [
                __('January', 'fluentform'),
                __('February', 'fluentform'),
                __('March', 'fluentform'),
                __('April', 'fluentform'),
                __('May', 'fluentform'),
                __('June', 'fluentform'),
                __('July', 'fluentform'),
                __('August', 'fluentform'),
                __('September', 'fluentform'),
                __('October', 'fluentform'),
                __('November', 'fluentform'),
                __('December', 'fluentform')
            ]
        ],
        'weekdays' => [
            'longhand'  => [
                __('Sunday', 'fluentform'),
                __('Monday', 'fluentform'),
                __('Tuesday', 'fluentform'),
                __('Wednesday', 'fluentform'),
                __('Thursday', 'fluentform'),
                __('Friday', 'fluentform'),
                __('Saturday', 'fluentform')
            ],
            'shorthand' => [
                __('Sun', 'fluentform'),
                __('Mon', 'fluentform'),
                __('Tue', 'fluentform'),
                __('Wed', 'fluentform'),
                __('Thu', 'fluentform'),
                __('Fri', 'fluentform'),
                __('Sat', 'fluentform')
            ]
        ],
        'amPM'     => [
            __('AM', 'fluentform'),
            __('PM', 'fluentform')
        ],
    );

    return $strings;
});

Czech

add_filter('fluentform/date_i18n', function ($strings) {​​​​
     $strings = array(
            'months'           => [
                'shorthand' => [
                    __('Led', 'fluentform'),
                    __('Úno', 'fluentform'),
                    __('Bře', 'fluentform'),
                    __('Dub', 'fluentform'),
                    __('Kvě', 'fluentform'),
                    __('Čen', 'fluentform'),
                    __('Čer', 'fluentform'),
                    __('Srp', 'fluentform'),
                    __('Zář', 'fluentform'),
                    __('Říj', 'fluentform'),
                    __('Lis', 'fluentform'),
                    __('Pro', 'fluentform')
                ],
                'longhand'  => [
                    __('Leden', 'fluentform'),
                    __('Únor', 'fluentform'),
                    __('Březen', 'fluentform'),
                    __('Duben', 'fluentform'),
                    __('Květen', 'fluentform'),
                    __('Červen', 'fluentform'),
                    __('Červenec', 'fluentform'),
                    __('Srpen', 'fluentform'),
                    __('Září', 'fluentform'),
                    __('Říjen', 'fluentform'),
                    __('Listopad', 'fluentform'),
                    __('Prosinec', 'fluentform')
                ]
            ],
            'weekdays'         => [
                'longhand'  => array(
                    __('Neděle', 'fluentform'),
                    __('Pondělí', 'fluentform'),
                    __('Úterý', 'fluentform'),
                    __('Středa', 'fluentform'),
                    __('Čtvrtek', 'fluentform'),
                    __('Pátek', 'fluentform'),
                    __('Sobota', 'fluentform')
                ),
                'shorthand' => array(
                    __('Ne', 'fluentform'),
                    __('Po', 'fluentform'),
                    __('Út', 'fluentform'),
                    __('St', 'fluentform'),
                    __('Čt', 'fluentform'),
                    __('Pá', 'fluentform'),
                    __('So', 'fluentform')
                )
            ],
 
            'amPM'             => [
                __('AM', 'fluentform'),
                __('PM', 'fluentform')
            ],
 
        );
    return $strings;
}​​​​);

In the provided code, we define an anonymous function that takes the $strings parameter. This parameter holds the default English labels for months, weekdays, and AM/PM. We then proceed to redefine these strings using the __('text', 'domain') function, which allows for language translation.

For example, this code snippet replaces the English month labels with their translated counterparts. The __() function wraps each label and ensures that it can be translated using language files or plugins.

Once you have added the code to the functions.php file or in code snippets plugin like advanced scripts, save it. The Datepicker field in Fluent Forms will now display the translated labels based on the provided strings.

Remember, this method targets the Fluent Forms plugin specifically, allowing you to customize the translation of the Datepicker field. By utilizing the add_filter function and modifying the $strings array, you can achieve accurate translations for the months, weekdays, and AM/PM labels within your forms.

In conclusion, the ability to translate the Datepicker field using PHP and the add_filter function in the Fluent Forms plugin ensures a seamless user experience for multilingual websites. By tailoring the labels to the user’s language, you can provide a localized and intuitive form-filling process.

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

2 comments

  • Marian

    Thanks for the great tip! Is there a way to have Monday as the first day of the week in the calendar without the necessity to buy Fluent Forms Pro?

  • A

    I am not sure. I never used Fluent Forms without Pro extension. Maybe ask their pre sales support.

Share Your Thoughts