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.

i18n block not working in Vue 3 with options API

See original GitHub issue

Reporting a bug?

The i18n custom block in SFC doesn’t work in Vue 3 when using the “older” options API.

The global translations are working, but the local translations aren’t.

Expected behavior

I expect my local translations to work when using the block

Reproduction

https://stackblitz.com/edit/vitejs-vite-qoza92?file=src/App.vue

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @intlify/vite-plugin-vue-i18n: ^6.0.3 => 6.0.3 
    @vitejs/plugin-vue: ^3.1.0 => 3.1.0 
    @vue/compiler-sfc: ^3.2.39 => 3.2.39 
    vite: ^3.1.3 => 3.1.3 
    vue: ^3.2.39 => 3.2.39 
    vue-i18n: ^9.2.2 => 9.2.2 
    vue-tsc: ^0.40.13 => 0.40.13

Screenshot

No response

Additional context

No response

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
SebastianMelinatcommented, Dec 21, 2022

Can confirm that @Adnan-kreiker 's workaround works, except for translations with substrings (something like Foo {bar}). To get them to work I made the hack a bit hackier:

    beforeCreate () {
      this.customT = function (...input: unknown[]) {
        const { t } = useI18n()
        // Causes error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
        // @ts-ignore
        return t(...input)
      }
      Vue.prototype.$t = this.customT
    }
2reactions
kazuponcommented, Nov 30, 2022

Sorry, I’m currently busy with another developments. Please wait. 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking Changes - Vue I18n
Reason: Vue 3 Global API changes, and Vue 3 API architecture changes related for component instances. Rename to datetimeFormats from ...
Read more >
Issues · intlify/vue-i18n-next - GitHub
Contribute to intlify/vue-i18n-next development by creating an account on ... i18n block not working in Vue 3 with options API ❗ p4-important Priority...
Read more >
How to Load i18n Locales Asynchronously in Vue 3 + Vite
Learn how to load Vue I18n locales lazily in your multi-language Vue 3 + Vite application to decrease initial bundle size- with source...
Read more >
i18n custom block on Vue3 + Vite - Stack Overflow
I have a Laravel + Inertja + Vue 3 project using Vite. I installed i18n plugin to be able to manage UI translation....
Read more >
The Ultimate Vue Localization Guide | Phrase
Note » You'll want v9+ of Vue I18n if you're working with Vue 3. ... All config options for createI18n() are available in...
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