2

I asked the same question before but there was some confusion. Actually my question is - I have Reactjs application .The application has a Arabic version and English version. And in the application i am using moment.jsto format the timestamp.when the App renders ,I am storing a language variable in localstorage ,i want what the value of that will be it should apply on moment.locale.

How can I implement this.

useEffect (() => {
    const language = localstorage.getItem ("Lang");
    if(language==="ar")
    {
        moment.locale("ar")
    }
    else
    {
        moment.locale("en")
    }
}, [])
Konrad
  • 21,590
  • 4
  • 28
  • 64
Andaman
  • 295
  • 3
  • 10
  • Does this answer your question? [How do I change the language of moment.js?](https://stackoverflow.com/questions/17493309/how-do-i-change-the-language-of-moment-js) – Konrad Apr 15 '22 at 18:43
  • Hey it seems like your code should work fine, but you also need to import locale. – Konrad Apr 15 '22 at 18:44
  • @KonradLinkowski it's working but after refreshing application – Andaman Apr 15 '22 at 18:45
  • Konrad Linkowski it's working but not intialy , when i refresh application then it works – Andaman Apr 15 '22 at 18:47
  • So probably the locale is set correctly, you just have some dates that depended on moment and you don't update them for some reason – Konrad Apr 15 '22 at 18:55

0 Answers0