How to change language in datepicker?

How to change language in datepicker?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to change language in datepicker?

Modifying the default text of a jQuery UI Datepicker often feels like searching for a needle in a haystack, specifically when trying to localize month names versus day headers. The frustration stems from how the library separates its data structures. As you likely discovered, editing datepicker.src.js directly is a fragile approach because the file contains both the raw data and the logic that renders it. This dual nature makes manual string replacement inefficient and prone to breaking upon future updates.

The core issue lies in understanding where day headers originate compared to month names. Month names are typically stored in a simple JavaScript array within the localization object, whereas week day labels often come from a separate configuration block or are derived dynamically based on that same language setting. If you manually edit datepicker.src.js to change "January" but miss the source of "Mon", "Tue", etc., your calendar will remain partially localized.

To achieve a consistent language switch without hacking the core library, you should leverage the built-in localization mechanism provided by jQuery UI. The standard approach involves defining a new locale object that contains both the month and day arrays, then applying this to your instance.

Here is how you define a custom locale structure in vanilla JavaScript:

$.datepicker.setDefaults({
    firstDay: 0, // Sunday is first day of week
    showMonthAfterYear: true,
    dateFormat: 'dd-mm-yy',
    monthNames: [
        "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"
    ],
    monthNamesShort: [
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    ],
    dayNames: [
        "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
    ],
    dayNamesShort: [
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    ]
});

// Initialize the widget with your custom settings
$("#datepicker").datepicker();

The dayNames array is the specific source for the week headers. By defining it here, you ensure that both the month drop-down and the grid headers share the same language context. If you are using a minified version or an older build where these arrays were hardcoded differently, you might need to inspect the library's internal _defaults object.

However, editing datepicker.src.js directly is generally discouraged for production environments. The primary pitfall of this method is version drift. When jQuery UI releases a new patch, your manual edits to datepicker.src.js will be overwritten, reverting your language changes and causing bugs to reappear. A more robust strategy is to fork the library, or better yet, use a dedicated localization plugin if you need to support multiple languages dynamically based on user session settings.

In modern web applications, particularly those built with frameworks like Laravel, relying on external JSON files for translations is often superior to modifying the JavaScript source. You can register your custom locale in the public/assets/js directory and include it before initializing the widget. This keeps your application logic separate from the library's internal implementation details.

If you are maintaining a legacy project where you absolutely must edit the source file, ensure you search for all occurrences of dayNames and monthNames. There may be multiple instances where these arrays are referenced, including within the formatDate function or other utility methods inside the script. Missing even one reference will result in mixed-language output, which degrades the user experience significantly.

For developers working with Laravel, integrating localized datepickers can be streamlined by placing the modified scripts in your assets folder and referencing them in your layout files rather than altering vendor libraries directly. This practice aligns with standard separation of concerns, making your application easier to maintain and deploy.

Our network