Skip to content

fix(builtins): follow svelte-i18n stores read with get() - #159

Open
erkamyaman wants to merge 2 commits into
x18n-dev:mainfrom
erkamyaman:fix/svelte-i18n-get-store
Open

erkamyaman wants to merge 2 commits into
x18n-dev:mainfrom
erkamyaman:fix/svelte-i18n-get-store

Conversation

@erkamyaman

@erkamyaman erkamyaman commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #155
Fixes #157

get(_)('key'), const translate = get(_) and renamed store imports (import { _ as i18n } with $i18n or get(i18n)) were not counted as usages, so working keys showed up as unused. get(otherStore) is still not treated as a translator.

Changes

  • core: new CallSpec.unwrap option: the functions that read a store callee (['get']). Schema, API snapshot, plan and docs updated.
  • js scanner: resolves get(store)('key'), const tr = get(store), a renamed get import, and $name for a store bound to name.
  • svelte scanner: scans <script> blocks first and shares their bindings with template expressions, so {tr('key')} works when tr is declared in the script.
  • svelte-i18n preset: _, t, format, json are stores read with get; $_, $t, $format, $json stay plain calls.

Tests

  • scanners.test.ts: store reads, aliases, renamed imports, and negatives (get(otherStore), get(_, 'x')).
  • presets.test.ts: the cases from the issue in a .ts file and a .svelte component.

The unwrap row in docs/content/6.references/1.config.md was written by hand; the docs generator couldn't run locally, so generate --check may want a small touch-up.

@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@erkamyaman is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@erkamyaman
erkamyaman requested a review from antfu November 13, 2026 11:14
`get(_)('key')`, `const translate = get(_)` and stores imported under another
name (`import { _ as i18n }` with `$i18n` or `get(i18n)`) were not usages, so
working keys showed up as unused. `get(otherStore)` is still not a translator.

- core: `CallSpec.unwrap` names the functions that read a store callee
- js scanner: resolve `reader(store)` calls and aliases, and `$name` for stores
- svelte scanner: scan scripts first and share their bindings with the template
- svelte-i18n: `_`, `t`, `format`, `json` are stores read with `get`

Refs x18n-dev#155
@erkamyaman
erkamyaman force-pushed the fix/svelte-i18n-get-store branch from cff2c79 to 0505d9c Compare November 13, 2026 11:16
A key held in a constant of a component's `<script>` and used in its markup
(`const key = 'greeting'` with `{$_(key)}`) read as a fully dynamic usage, so
the key showed up as unused. Constants now live in the scope the script and
template scans share, with the offset of the scan that declared them, so the
usage points at the literal in the script.

Fixes x18n-dev#157
@0froq

0froq commented Nov 13, 2026

Copy link
Copy Markdown
Member

Also add Fixes #157 to the body so it closes on merge! ❤️

@erkamyaman

Copy link
Copy Markdown
Member Author

Also add Fixes #157 to the body so it closes on merge! ❤️

thx, i must have missed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[svelte-i18n] Svelte template scans lose variables declared in script blocks [svelte-i18n] Svelte store unwrapping & translator aliases are missed

2 participants