-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental auto declare/import translation functions (#2858)
* feat: experimental auto import translation functions * docs: add `autoImportTranslationFunctions` to experimental options description * feat: add transformation to insert translation functions when needed * refactor: replace auto import implementation using `globalThis` * feat: auto import more translation functions * fix: strip types before parsing script * fix: add global types for inserted functions * docs: change description for `autoImportTranslationFunctions` * fix: only transform script setup sfc * refactor: reorder definitions * refactor: reorder imports * fix: skip sourcemap when parsing for scriptSetup * fix: type `te` should be `tm` Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com> * fix: reuse parsed information to replace script content * chore: revert playground and fixture experimentation * docs: add warning explaining auto-import requirement * chore: revert playground and fixture experimentation --------- Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com>
- Loading branch information
1 parent
f57e208
commit a586929
Showing
11 changed files
with
387 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
specs/experimental/auto_import_translation_functions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup } from '../utils' | ||
import { gotoPath, renderPage } from '../helper' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/basic_usage`, import.meta.url)), | ||
browser: true, | ||
// prerender: true, | ||
// overrides | ||
nuxtConfig: { | ||
runtimeConfig: { | ||
public: { | ||
i18n: { | ||
baseUrl: '' | ||
} | ||
} | ||
}, | ||
i18n: { | ||
experimental: { | ||
autoImportTranslationFunctions: true | ||
} | ||
} | ||
} | ||
}) | ||
|
||
describe('experimental.autoImportTranslationFunctions', async () => { | ||
test('can use `$t` in `<template>`', async () => { | ||
const { page, consoleLogs } = await renderPage('/') | ||
|
||
await gotoPath(page, '/') | ||
|
||
const logStrings = consoleLogs.map(x => x.text) | ||
expect(logStrings).toContain('[autoImportTranslationFunctions][default]: Welcome') | ||
expect(logStrings).toContain('[autoImportTranslationFunctions][fr]: Bienvenue') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.