Skip to content

feat(vue): add @lingui/vue, Vue 3 bindings with template macros - #2732

Merged
andrii-bodnar merged 6 commits into
lingui:mainfrom
tryriot:vue
Oct 28, 2026
Merged

andrii-bodnar merged 6 commits into
lingui:mainfrom
tryriot:vue

Conversation

@yves-riot

Copy link
Copy Markdown
Contributor

Following #1730

Description

Add @lingui/vue, a Vue 3 binding with the same features as @lingui/react and @lingui/solid:

  • I18nProvider, useLingui, Trans, TransNoContext and a createLingui app plugin
  • @lingui/vue/macro: Trans, Plural, Select, SelectOrdinal and useLingui macros for <script setup> and JSX/TSX
  • @lingui/vue/compiler: a Vue compiler node transform that compiles the macros inside <template> blocks (<Trans>, <Plural>, <Select>, <SelectOrdinal>, and t, plural, select, selectOrdinal, ph in expressions), with named Vue slots as element placeholders
  • @lingui/vue/vite: registers the template transform in @vitejs/plugin-vue and runs the Babel macro on .vue, .js, .ts, .jsx and .tsx modules
  • @lingui/vue/config: defineConfig preset for Vue projects
  • It's running in production in 2 large SPAs since ~1 month

Vue 3.4+ is required.

The package structure, tests and docs follow the Solid integration (#2510), adapted to Vue (shallowRef + triggerRef instead of signals) and VNodes. The template transform is the Vue-specific addition: templates are not Babel input, so the macros need a compiler-level transform to reach them.

Bare Trans renders always produce a Fragment so server-rendered translations hydrate next to sibling text without mismatches.

Changes outside @lingui/vue:

  • @lingui/conf: macro.jsxRuntime accepts "vue".
  • @lingui/babel-plugin-lingui-macro:
    • when jsxRuntime is "vue", non-JSX references of macro components are redirected to the runtime Trans, so @lingui/vue/macro is the single import for templates.
    • useLingui destructuring is resolved at module scope when there is no enclosing function (raw <script setup> code during extraction).
  • @lingui/extractor-vue:
    • applies the template transform so messages in <template> are extracted with the same IDs as at runtime. Template compile errors now fail extraction; previously they were silently ignored and extraction succeeded with a missing or hashed ID.
    • new template and compilerOptions options; lang="tsx" blocks are parsed as TypeScript; template placeholders drop the _ctx./$setup. prefix.
    • reactivityTransform defaults to true when macro.jsxRuntime is "vue", so destructured props get the same message IDs as at runtime.
    • @lingui/vue is an optional peer dependency, needed only for the template macros (which also need @vue/compiler-sfc 3.4+, checked at extraction). Without it, templates are compiled without the transform, so Vue 3.2 and 3.3 projects keep working.
  • @lingui/vite-plugin: the native macroTransform fails early with macro.jsxRuntime: "vue", as it already does for "solid" (fix(vite-plugin): fail early when native transform is used with Solid #2708). Vue projects transform macros with the Babel plugin through @lingui/vue/vite.
  • README.md: mentions @lingui/vue; package.json: size-limit entry for @lingui/vue.

Includes tests, docs and a vite-project-vue example app.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
js-lingui Ready Ready Preview Oct 28, 2026 2:58pm UTC

Request Review

@andrii-bodnar andrii-bodnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yves-riot thanks a lot for this, it’s a big and very complete piece of work, and running it in production for a month is a good sign. We’d like to have Vue support in Lingui itself!

It’s behind main now and has conflicts, so it needs a rebase. Two more minor comments. After that I’ll go through it in more detail.

Comment thread packages/vue/src/format.ts Resolved
Comment thread packages/vite-plugin/src/index.ts Resolved
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.76355% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.05%. Comparing base (6bb8983) to head (0acca63).
⚠️ Report is 463 commits behind head on main.

Files with missing lines Patch % Lines
packages/vue/src/template/index.ts 92.04% 32 Missing and 3 partials ⚠️
packages/vue/src/config.ts 0.00% 9 Missing and 2 partials ⚠️
packages/vue/src/vite.ts 88.13% 7 Missing ⚠️
packages/vue/src/TransNoContext.ts 91.17% 6 Missing ⚠️
packages/vue/src/plugin.ts 64.28% 5 Missing ⚠️
packages/extractor-vue/src/vue-extractor.ts 94.87% 3 Missing and 1 partial ⚠️
packages/vue/src/I18nProvider.ts 92.30% 2 Missing and 1 partial ⚠️
packages/babel-plugin-lingui-macro/src/index.ts 93.10% 2 Missing ⚠️
packages/vue/src/format.ts 96.42% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2732       +/-   ##
===========================================
+ Coverage   77.05%   90.05%   +12.99%     
===========================================
  Files          84      147       +63     
  Lines        2157     5267     +3110     
  Branches      555     1624     +1069     
===========================================
+ Hits         1662     4743     +3081     
- Misses        382      468       +86     
+ Partials      113       56       -57     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@andrii-bodnar andrii-bodnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yves-riot thanks again, I went through the whole package with the first release in mind. The code side looks ready. #2729 just landed, so this needs a rebase first, and a few things in the docs need fixing before we can merge:

  • Conflicts in extractor-vue. Keep both sides: the new extractor option next to template and compilerOptions, and extractTarget should call the configured extractor (Babel by default) instead of the imported one.
  • The docs site fails on broken links.
  • The "equivalent" config under defineConfig in ref/vue.md is missing jsxRuntime: "vue", so anyone copying it gets broken template components.

Thinking out loud: with the new extractor option, someone may pass the SWC extractor in a @lingui/vue project. The native macro doesn't know jsxRuntime: "vue" yet, so that combination will not work today. Not something for this PR, we can handle it on the native-tools side.

Add `@lingui/vue`, a Vue 3 binding with the same features as `@lingui/react`
and `@lingui/solid`:

- `I18nProvider`, `useLingui`, `Trans`, `TransNoContext` and a `createLingui`
  app plugin
- `@lingui/vue/macro`: `Trans`, `Plural`, `Select`, `SelectOrdinal` and
  `useLingui` macros for `<script setup>` and JSX/TSX
- `@lingui/vue/compiler`: a Vue compiler node transform that compiles the
  macros inside `<template>` blocks (`<Trans>`, `<Plural>`, `<Select>`,
  `<SelectOrdinal>`, and `t`, `plural`, `select`, `selectOrdinal`, `ph` in
  expressions), with named Vue slots as element placeholders
- `@lingui/vue/vite`: registers the template transform in
  `@vitejs/plugin-vue` and runs the Babel macro on `.vue`, `.js`, `.ts`,
  `.jsx` and `.tsx` modules
- `@lingui/vue/config`: `defineConfig` preset for Vue projects

Vue 3.4+ is required.

The package structure, tests and docs follow the Solid integration (lingui#2510),
adapted to Vue (`shallowRef` + `triggerRef` instead of signals) and VNodes.
The template transform is the Vue-specific addition: templates are not Babel
input, so the macros need a compiler-level transform to reach them.

Bare `Trans` renders always produce a Fragment so server-rendered
translations hydrate next to sibling text without mismatches.

Changes outside `@lingui/vue`:

- `@lingui/conf`: `macro.jsxRuntime` accepts `"vue"`.
- `@lingui/babel-plugin-lingui-macro`:
  - when `jsxRuntime` is `"vue"`, non-JSX references of macro components are
    redirected to the runtime `Trans`, so `@lingui/vue/macro` is the single
    import for templates.
  - `useLingui` destructuring is resolved at module scope when there is no
    enclosing function (raw `<script setup>` code during extraction).
- `@lingui/extractor-vue`:
  - applies the template transform so messages in `<template>` are extracted
    with the same IDs as at runtime. Template compile errors now fail
    extraction; previously they were silently ignored and extraction
    succeeded with a missing or hashed ID.
  - new `template` and `compilerOptions` options; `lang="tsx"` blocks are
    parsed as TypeScript; template placeholders drop the `_ctx.`/`$setup.`
    prefix.
  - `reactivityTransform` defaults to `true` when `macro.jsxRuntime` is
    `"vue"`, so destructured props get the same message IDs as at runtime.
  - `@lingui/vue` is an optional peer dependency, needed only for the
    template macros (which also need `@vue/compiler-sfc` 3.4+, checked at
    extraction). Without it, templates are compiled without the transform,
    so Vue 3.2 and 3.3 projects keep working.
- `@lingui/vite-plugin`: the native `macroTransform` fails early with
  `macro.jsxRuntime: "vue"`, as it already does for `"solid"` (lingui#2708). Vue
  projects transform macros with the Babel plugin through `@lingui/vue/vite`.
- `README.md`: mentions `@lingui/vue`; `package.json`: size-limit entry for
  `@lingui/vue`.

Includes tests, docs and a `vite-project-vue` example app.
- vite-plugin: only reject macro.jsxRuntime "vue" in the native macro
  transform, Solid is now supported (lingui#2731)
- extractor-vue: keep remapping <script setup> message positions to the
  .vue file (lingui#2728) through the extractTarget helper
- docs: limit the native transform caution to Vue
Use the same placeholder grammar as @lingui/react, which follows the macro
charset since lingui#2676, so `<terms_link>` extracted by the macro also renders.
- Add `jsxRuntime: "vue"` to the manual equivalent of `defineConfig`
- Point the macro plugin link to the Babel setup in Installation
- Fix the `macro.jsxPlaceholder*` and `msg` anchors
- Format the Vue docs, keeping the template examples as written
@yves-riot

Copy link
Copy Markdown
Contributor Author

@andrii-bodnar Thanks! It should be good now

Comment thread website/docs/ref/vue.md Resolved
Comment thread website/docs/ref/vue.md Resolved
Co-authored-by: Andrii Bodnar <29282228+andrii-bodnar@users.noreply.github.com>
@andrii-bodnar

Copy link
Copy Markdown
Contributor

@yves-riot thank you! Could you please also bump the package version to 6.10.1?

@yves-riot

Copy link
Copy Markdown
Contributor Author

@yves-riot thank you! Could you please also bump the package version to 6.10.1?

Done!

@andrii-bodnar andrii-bodnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yves-riot thank you for the contribution! 🚀

@andrii-bodnar
andrii-bodnar merged commit 594308f into lingui:main Oct 28, 2026
13 checks passed
@andrii-bodnar andrii-bodnar mentioned this pull request Oct 28, 2026
23 of 44 tasks
@andrii-bodnar

Copy link
Copy Markdown
Contributor

@yves-riot I just released the package - https://www.npmjs.com/package/@lingui/vue

It does not have provenance yet, but it should work. The next version will be released through the regular pipeline and will have trusted publishing and provenance.

@yves-riot

Copy link
Copy Markdown
Contributor Author

@yves-riot I just released the package - npmjs.com/package/@lingui/vue

It does not have provenance yet, but it should work. The next version will be released through the regular pipeline and will have trusted publishing and provenance.

Thank you!

@MurzNN

MurzNN commented Nov 5, 2026

Copy link
Copy Markdown

Very cool, thank you! Having this feature implemented, I recommended Lingui for Slidev i18n feature: slidevjs/slidev#1125 (comment)

This branch was successfully deployed

1 active deployment
Preview — 0acca631 Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants