question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Demo Site] A locale object was not found for the provided string ["en-GB"].

See original GitHub issue

Describe the bug The locale example on the demo site is not working correctly. It is using my locale (en-US) instead of the stated locale (en-GB). It is also produces an error. Error reproduced below

To Reproduce Steps to reproduce the behavior:

  1. Go to ‘https://reactdatepicker.com/#example-locale
  2. Open Dev Tools, (I am using chrome in this instance. However issue is also present in FireFox)
  3. Click on the date field
  4. View console.

Scroll up or down to reproduce the.

See error in Additional Context

Expected behavior Expected date popup with correct local (en-GB in this instance).

Screenshots image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome, Firefox
  • Version 76.0.3809.100, 68.0.2 respectivly

Additional context Error procuced from console

backend.js:6 A locale object was not found for the provided string ["en-GB"].
r @ backend.js:6
we @ index.js:403
(anonymous) @ index.js:552
(anonymous) @ index.js:2459
(anonymous) @ index.js:2445
(anonymous) @ index.js:2442
(anonymous) @ index.js:2654
(anonymous) @ index.js:2708
value @ index.js:2836
yi @ react-dom.production.min.js:3880
mi @ react-dom.production.min.js:3871
Jo @ react-dom.production.min.js:6116
Wo @ react-dom.production.min.js:5101
Ho @ react-dom.production.min.js:4958
Fo @ react-dom.production.min.js:4817
(anonymous) @ react-dom.production.min.js:2543
a.unstable_runWithPriority @ scheduler.production.min.js:338
cr @ react-dom.production.min.js:2513
Rr @ react-dom.production.min.js:2538
hr @ react-dom.production.min.js:2528
Ie @ react-dom.production.min.js:6706
Bn @ react-dom.production.min.js:1817
Ln @ react-dom.production.min.js:1790

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
Snazziecommented, Jan 31, 2020

This isnt fixed, even on your demo site with “en-GB” your input is still “en-US”. i also get this console warning with “en-US” as locale.

11reactions
wviveirocommented, Dec 2, 2020

From his commit on issue #1872 I checked he did 2 things:

  1. Import the locale from date-fns to the code
import enGB from "date-fns/locale/en-GB";
  1. Register the locale using react-datepicker function when component is mounted
registerLocale('gn-GB', enGB);

So, in order to make it work in my code, I did the following:


import React, { useEffect } from "react";
import DatePicker, { registerLocale } from "react-datepicker";
import enGB from "date-fns/locale/en-GB";


// REACT HOOK
const MyDatePicker = () => {
    useEffect(() => {
        registerLocale("en-GB", enGB);
    }, []);

    return (
        <DatePicker
            locale={'en-GB'}
        />
    );
};

// React Component
class MyDatePickerComponent extends React.Component {
    componentDidMount() {
        registerLocale("en-GB", enGB);
    }
    render() {
        return (
            <DatePicker
                locale={'en-GB'}
            />
        );
    }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the react-datepicker.registerLocale function in ...
To help you get started, we've selected a few react-datepicker.registerLocale examples, based on popular ways it is used in public projects.
Read more >
Creating a Locale (The Java™ Tutorials > Internationalization ...
This internationalization Java tutorial describes setting locale, isolating locale-specific data, formatting data, internationalized domain name and ...
Read more >
Change locale in react-datepicker - Stack Overflow
First of all make sure you are using the latest version of the plugin (2.0.0). Then you need to also install the date-fns...
Read more >
Globalization and localization in ASP.NET Core
A multilingual website allows the site to reach a wider audience. ASP. ... RootNamespace is a build-time value which is not available to...
Read more >
Supported Locales and Fallback Chain - SAPUI5 SDK
Available properties files for a resource bundle and the locales you specify ... tag or a JDK-compatible locale string (e.g. "en-GB" , "en_GB"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found