Translate Datepicker Field of Fluent Forms Plugin

You can translate the date picker fields by adding custom code to 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.

Datepicker function for Fluent Form.png
  • 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 to 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” to “Oktober” for the longhand and “Oct” to “Okt” for the shorthand.
  • Let’s translate the weekday 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 on the weekdays as needed. So if you want to translate this to german, you might want to change “Thursday” to “Donnerstag” for the longhand and “Sun” as “Don” for the shorthand.
  • Let’s take a look at the AM and PM translations. It’s also identical to the months and weekdays translation 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 and PM into your language as needed. In the case of the German translation, you might want to change “AM” to “Uhr morgens” and “PM” to “Uhr.”
  • You can use the below code once to translate all of the months, weeks, and AM-PM without using the 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;
});
  • When using combined code, you don’t need to write multiple add_filter functions and return statements.

Was this article helpful to you?

6 5

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