Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem setting global locale in laravel-vue project #109

Open
GabotronES opened this issue Nov 19, 2018 · 3 comments
Open

Problem setting global locale in laravel-vue project #109

GabotronES opened this issue Nov 19, 2018 · 3 comments

Comments

@GabotronES
Copy link

I'm trying to set the global locale to 'es' but it's not taking effect, I'm using this module in a laravel-vue application so I'm doing this in my app.js

window.Vue = require('vue');
Vue.use( require('vue-moment') );
Vue.config.productionTip = false;

//posts
Vue.component('posts-list', require('./components/posts/PostsList.vue'));
Vue.component('posts-card', require('./components/posts/PostsCard.vue'));
Vue.component('posts-header', require('./components/posts/PostsHeader.vue'));
Vue.component('posts-sidebar-list', require('./components/posts/PostsSidebarList.vue'));
Vue.component('posts-bottombar-list', require('./components/posts/PostsBottombarList.vue'));
//reviews
Vue.component('reviews-card', require('./components/reviews/ReviewsCard.vue'));
//others
Vue.component('faq-list', require('./components/others/FaqList.vue'));
Vue.component('details-container', require('./components/others/DetailsContainer.vue'));
//auth
Vue.component('register-form', require('./components/auth/RegisterForm.vue'));
Vue.component('login-form', require('./components/auth/LoginForm.vue'));

import store from './store';
import "./directives"

const app = new Vue({

    el: '#vueapp',
    store,

    created () {
        console.info('******* VUE INSTANCE MOUNTED *******');
        this.$moment.locale('es');
    },

});

@BrockReece
Copy link
Collaborator

I think you need to require the respective locale module too.
Try adding this line to the top of your file.

require('moment/locale/es')

@carlosgeos
Copy link

The components do not auto update, do:

this.$forceUpdate() to update the component after doing $this.$moment.locale('es')

@desmartDev
Copy link

It works like that

import moment from 'moment'

const lang = 'fr'

moment.locale(lang)

Vue.use(require('vue-moment'), {moment})

console.log(Vue.moment().locale()) // fr

export default new Vue({ el: '#app', render: h => h(App), created () { console.log(this.$moment().locale()) // fr } })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants