DEV Community

d4g0
d4g0

Posted on • Updated on

How to access localized messages of nuxt-i18n inside the setup function

Quick snippet, log inside a client check if to avoid server logs get forwarded to browser console, it works server side too.
Im mostly writing this to rember it, i allways forget how to doit 😅️.

Tested in @nuxt-i18n 7.X on a nuxt 2 project

setup(props,  ctx ) {

   const { root } = ctx;
   // all the stuff is in the root, who would imagine that ha

   if (process.client) {
      // ctx.root.$i18n.t
      console.log(ctx.root.$i18n.t('my.message.path'))
    }

}
Enter fullscreen mode Exit fullscreen mode

And that's how to use $t is nuxt-i18n inside setup function folks.

Top comments (1)

Collapse
 
silvesterwali profile image
silvesterwali

const { t: $t } = useI18n()

console.log($('message'))