Translate Datepicker Field of WP Fluent Forms Plugin

You can translate the date picker fields by adding some custom code in your theme’s functions.php file. To edit the functions.php file log into your WordPress dashboard and hover over “Appearance” and select “Theme Editor” as shown here:

how to add code to functions php WordPress

To change the name of the months of the datepicker just add the code below to your theme’s functions.php file. It is recommended to use a child theme and add the code in the child theme’s functions.php file. You can paste the code at the end.

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')
        ]
    ],
);
return $strings;
});

Change both shorthand and longhand of the months as needed. For example, if you want to translate this into German you might want to change “October” as “Oktober” for the longhand and “Oct” as “Okt” for the shorthand.

Let’s translate the weekday’s shorthand and longhand forms. This is very identical to changing the months above. Add the below code to your child themes function.php file and change the strings into your language.

add_filter('fluentform/date_i18n', function ($strings) {
$strings = array(
    'weekdays'         => [
        'longhand'  => array(
            __('Sunday', 'fluentform'),
            __('Monday', 'fluentform'),
            __('Tuesday', 'fluentform'),
            __('Wednesday', 'fluentform'),
            __('Thursday', 'fluentform'),
            __('Friday', 'fluentform'),
            __('Saturday', 'fluentform')
        ),
        'shorthand' => array(
            __('Sun', 'fluentform'),
            __('Mon', 'fluentform'),
            __('Tue', 'fluentform'),
            __('Wed', 'fluentform'),
            __('Thu', 'fluentform'),
            __('Fri', 'fluentform'),
            __('Sat', 'fluentform')
        )
    ],

);
return $strings;
});

Change both shorthand and longhand of the weekdays as needed. So if you want to translate this to german you might want to change “Thursday” as “Donnerstag” for the longhand and “Sun” as “Don” for the shorthand.

Let’s take a look at the AM, PM translation. It’s also very identical to the months and weekdays translation as described earlier. Add the code below to your child themes functions.php file and save it.

add_filter('fluentform/date_i18n', function ($strings) {
$strings = array(
    'amPM'             => [
    __('AM', 'fluentform'),
    __('PM', 'fluentform')
    ],

);
return $strings;
});

Change the AM, PM into your language as needed. In the case of German translation, you might want to change “AM” to “Uhr morgens” and “PM” as “Uhr”.

You can use the below code for once to translate all of months, weeks and AM-PM without using code for them individually.

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'  => array(
                    __('Sunday', 'fluentform'),
                    __('Monday', 'fluentform'),
                    __('Tuesday', 'fluentform'),
                    __('Wednesday', 'fluentform'),
                    __('Thursday', 'fluentform'),
                    __('Friday', 'fluentform'),
                    __('Saturday', 'fluentform')
                ),
                'shorthand' => array(
                    __('Sun', 'fluentform'),
                    __('Mon', 'fluentform'),
                    __('Tue', 'fluentform'),
                    __('Wed', 'fluentform'),
                    __('Thu', 'fluentform'),
                    __('Fri', 'fluentform'),
                    __('Sat', 'fluentform')
                )
            ],

            'amPM'             => [
                __('AM', 'fluentform'),
                __('PM', 'fluentform')
            ],

        );
    return $strings;
});

You don’t need to write multiple add_filter function and return statement when using the code combined.

Was this article helpful to you?

How can we help?

Please submit a support ticket if you have any question or pre-sale questions. Our Customer support engineers will answer your query as soon as possible

Open a support ticket