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

Access of $t in vueX action #93

Open
adminbmbc opened this issue Aug 17, 2018 · 2 comments
Open

Access of $t in vueX action #93

adminbmbc opened this issue Aug 17, 2018 · 2 comments

Comments

@adminbmbc
Copy link

hi,

i have tried rootstate.$i18n.t it didn't work.
Any workaround ?

thanks in advance.

@tikiatua
Copy link
Member

Hi @adminbmbc

The translate function is currently only exposed on the Vue instance and inside the components. The vuex-i18n state is actually stored in the vuex module i18n (you should be able to see it in the vue devtools). However, the translate function is not available on the store.

A workaround would be to pass the $t function from the component to the respective action and further on to a mutation if required.

this.$store.dispatch('some-action', { translate: this.$t, data: someday});

// in action
'some-action'({commit}, payload) {
    let translatedContent = payload.translate('some text');

    commit('some-commit', {
        translate: payload.translate,
        content: translatedContent
    });
}

@tikiatua tikiatua added this to To do in Version 2.0.0 Aug 21, 2019
@QADRAX
Copy link

QADRAX commented May 19, 2020

Hi!
We are having exactly same issue... I think in the same way that vuex-i18n registers $t function in Vue and a new vuex module, it could register a kind of $t getter to access translations from other modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Version 2.0.0
  
To do
Development

No branches or pull requests

3 participants