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.

this.$moment().locale(lang) does not works

See original GitHub issue

Hello, I want to change locale with a user click event on button.

I have the following

// main.js
import Vue from 'vue'
import VueMoment from 'vue-moment'
const moment = require('moment')
require('moment/locale/en-gb')
require('moment/locale/fr')
Vue.use(VueMoment, {
  moment
})

And then, using in component:

// app.vue
<script>
  methods: {
    setLanguage (lang) {
      console.log(lang)
      this.$moment().locale(lang)
      console.log(this.$moment().locale())
    }
  }
}
</script>

When I call the function from the button, I got the following

setLanguage('en')
en
fr
setLanguage('fr')
fr
fr

Is it possible to update the moment locale this way?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
BrockReececommented, Oct 30, 2017

I think this is fixed now

1reaction
pakpingcommented, Jul 26, 2021

nuxt 1 import ‘moment/locale/th’

2
moment(date) { // moment.locale(‘th’); var strdate = moment(“th”).format(“LLLL”); var strdate = moment(date).add(543, “years”); return moment(strdate).format(“Do MMMM YYYY hh:mm”); },

Read more comments on GitHub >

github_iconTop Results From Across the Web

moment.js change locale not working - Stack Overflow
My website is a mutilanguage website, when I change the web language. moment.locale(lang) not working. My code is: const startDate = moment.utc( ...
Read more >
locale changes does'nt work · Issue #2962 · moment ... - GitHub
When I try to change the locale value, nothing happens, not even error. this.$log.log(moment.locale()); // returns 'en' this.
Read more >
Changing locales locally - momentjs.com
If you call moment#locale with no parameters, you get back the locale configuration that would be used for that moment. var fr =...
Read more >
Docs - Moment.js
Moment doesn't work well with modern "tree shaking" algorithms, so it tends to increase the size of web application bundles.
Read more >
Beginning JavaScript I18n with i18next and Moment.js | Phrase
The team is working with React for a view layer. ... Locale output (for say, a language switcher); Fallback to default ... get...
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