can't access i18n translation inside vuex state.js file



  • Interestingly, (and although it does not throw an error) when I console.log(i18n) I get undefined



  • And if I try to use const i18n = require('src/boot/i18n') instead of import, console.log(i18n) gives me:

    Module {__esModule: true, Symbol(Symbol.toStringTag): "Module", default: ƒ}
    default: ƒ (_ref)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:1:142)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:1:142)]
    length: 1
    name: ""
    prototype:
    constructor: ƒ (_ref)
    __proto__: Object
    __proto__: ƒ ()
    [[FunctionLocation]]: i18n.js?8847:6
    [[Scopes]]: Scopes[3]
    i18n: (...)
    Symbol(Symbol.toStringTag): "Module"
    __esModule: true
    get i18n: ƒ ()
    __proto__: Object
    


  • Aren’t the boot files supposed to be loaded before anything else? It feels like i18n is not being loaded in time and that is why it comes back undefined?



  • @ssuess your import seems to be wrong, should be with curly braces import { i18n } from 'src/boot/i18n'.



  • This post is deleted!


  • @metalsadman Thanks, I already tried it both ways, made no difference alas.



  • I think the problem is that the store is initialized before boot files, which is quite logical since boot files can access the store.

    So, a solution may be to defer translations. You may use a getter for that, with a map on your menu array that will replace fields by their translation.



  • Hmm you arr using this in your state. Remove thatt as well.



  • @metalsadman definitely not that, see above for all the variations I have tried.



  • @tof06 this sounds logical to me, do you have any example code you could point me to? Where exactly would this code go? in the state.js file or somewhere else?


Log in to reply