-
Notifications
You must be signed in to change notification settings - Fork 422
feat: add full support of Vue.js #1925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
JSteunou
wants to merge
25
commits into
lingui:next
Choose a base branch
from
JSteunou:add_new_lingui_vue
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
078e564
feat: add @lingui/vue
JSteunouSteeple d382f31
chore: add publishConfig for CI
JSteunou a3d42ca
Merge branch 'refs/heads/next' into add_new_lingui_vue
timofei-iatsenko ab300de
refactor js macro
timofei-iatsenko 41dc5f6
use lingui core internals for vue vt and trans macro
timofei-iatsenko a67c1ed
support vt transformation in interpolation
timofei-iatsenko a2a03da
WIP: Plural Element support
timofei-iatsenko aba8de6
remove Plural Element, implement support for inline ICU expression
timofei-iatsenko a21222a
a bit better code lens style in the function comments
timofei-iatsenko 8a58e5f
fix: remove some comments & fix some TS errors
JSteunou 1a6284a
feat(react): fix macro export conditions for NodeNext and Bundler res…
timofei-iatsenko 22f22e1
fix(experimental-extractor): fix various bugs (#1958)
timofei-iatsenko 5a6abff
Merge branch 'next' into add_new_lingui_vue
JSteunou 3a0d8bd
fix: typescript expected error on predicate call
JSteunou 68c190e
fix: macroJst.test needed to follow refacto from previous commit
JSteunou 1d98e19
fix ts errors and tests
timofei-iatsenko b87b64e
prettier
timofei-iatsenko 8ddc0b1
remove runtime vt function
timofei-iatsenko effd2c0
add vue-vite-plugin
timofei-iatsenko 9a49f8f
fix: remove default export
JSteunou f0b1689
fix: transformer signature has changed
JSteunou bf54052
chore: go from 4.8.0-next.1 to 5.0.0-next.0
JSteunou 10810dd
Merge branch 'next' into add_new_lingui_vue
timofei-iatsenko 0b55212
fix issue after merge with `next`
timofei-iatsenko bd50953
Merge branch 'next' into add_new_lingui_vue
timofei-iatsenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,34 @@ | ||
| [![License][badge-license]][license] | ||
| [![Version][badge-version]][package] | ||
| [![Downloads][badge-downloads]][package] | ||
|
|
||
| # @lingui/vue | ||
|
|
||
| > vue components for internationalization | ||
|
|
||
| `@lingui/vue` is part of [LinguiJS][linguijs]. See the [documentation][documentation] for all information, tutorials and examples. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```sh | ||
| npm install --save @lingui/vue | ||
| # yarn add @lingui/vue | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| See the [tutorial][tutorial] or [reference][reference] documentation. | ||
|
|
||
| ## License | ||
|
|
||
| [MIT][license] | ||
|
|
||
| [license]: https://github.com/lingui/js-lingui/blob/main/LICENSE | ||
| [linguijs]: https://github.com/lingui/js-lingui | ||
| [documentation]: https://lingui.dev | ||
| [tutorial]: https://lingui.dev/tutorials/vue | ||
| [reference]: https://lingui.dev/ref/vue | ||
| [package]: https://www.npmjs.com/package/@lingui/vue | ||
| [badge-downloads]: https://img.shields.io/npm/dw/@lingui/vue.svg | ||
| [badge-version]: https://img.shields.io/npm/v/@lingui/vue.svg | ||
| [badge-license]: https://img.shields.io/npm/l/@lingui/vue.svg |
This file contains hidden or 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,91 @@ | ||
| { | ||
| "name": "@lingui/vue", | ||
| "version": "4.8.0-next.1", | ||
| "sideEffects": false, | ||
| "description": "Vue components & tools for translations", | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "author": { | ||
| "name": "Jérôme Steunou", | ||
| "email": "[email protected]" | ||
| }, | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "vue", | ||
| "component", | ||
| "i18n", | ||
| "internationalization", | ||
| "i9n", | ||
| "translation", | ||
| "icu", | ||
| "messageformat", | ||
| "multilingual", | ||
| "localization", | ||
| "l10n" | ||
| ], | ||
| "scripts": { | ||
| "build": "rimraf ./dist && unbuild", | ||
| "stub": "unbuild --stub" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/lingui/js-lingui.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/lingui/js-lingui/issues" | ||
| }, | ||
| "engines": { | ||
| "node": ">=16.0.0" | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| }, | ||
| "import": { | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| } | ||
| }, | ||
| "./compiler": { | ||
| "require": { | ||
| "types": "./dist/compiler/index.d.cts", | ||
| "default": "./dist/compiler/index.cjs" | ||
| }, | ||
| "import": { | ||
| "types": "./dist/compiler/index.d.mts", | ||
| "default": "./dist/compiler/index.mjs" | ||
| } | ||
| }, | ||
| "./extractor": { | ||
| "require": { | ||
| "types": "./dist/extractor/index.d.cts", | ||
| "default": "./dist/extractor/index.cjs" | ||
| }, | ||
| "import": { | ||
| "types": "./dist/extractor/index.d.mts", | ||
| "default": "./dist/extractor/index.mjs" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "files": [ | ||
| "LICENSE", | ||
| "README.md", | ||
| "dist/" | ||
| ], | ||
| "dependencies": { | ||
| "@lingui/cli": "4.8.0-next.1", | ||
| "@lingui/core": "4.8.0-next.1", | ||
| "@lingui/message-utils": "4.8.0-next.1", | ||
| "@vue/compiler-core": "^3.3.4", | ||
| "@vue/compiler-sfc": "^3.3.4", | ||
| "vue": "^3.3.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/babel__core": "^7.20.5", | ||
| "unbuild": "2.0.0" | ||
| } | ||
| } | ||
This file contains hidden or 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,219 @@ | ||
| import { getContent, getContext, getId } from "./Trans" | ||
| import { run } from "../test/utils" | ||
| import { generateMessageId } from "@lingui/message-utils/generateMessageId" | ||
|
|
||
| // | ||
|
|
||
| describe("getContext", () => { | ||
| it("should get the context", () => { | ||
| run( | ||
| ` | ||
| <Trans context="direction">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContext(node)).toEqual("direction") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return undefined when context is empty", () => { | ||
| run( | ||
| ` | ||
| <Trans context="">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContext(node)).toEqual(undefined) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return undefined when context is a directive", () => { | ||
| run( | ||
| ` | ||
| <Trans :context="direction">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContext(node)).toEqual(undefined) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return undefined when no context", () => { | ||
| run( | ||
| ` | ||
| <Trans>right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContext(node)).toEqual(undefined) | ||
| } | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe("getId", () => { | ||
| it("should return the given id when set", () => { | ||
| run( | ||
| ` | ||
| <Trans id="direction.right">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual("direction.right") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the generated id when not set", () => { | ||
| run( | ||
| ` | ||
| <Trans>right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual(generateMessageId("right")) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the generated id when not set but with context", () => { | ||
| run( | ||
| ` | ||
| <Trans context="direction">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual( | ||
| generateMessageId("right", "direction") | ||
| ) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the generated id when id is empty but with context", () => { | ||
| run( | ||
| ` | ||
| <Trans id="" context="direction">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual( | ||
| generateMessageId("right", "direction") | ||
| ) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the generated id when id is empty and context empty", () => { | ||
| run( | ||
| ` | ||
| <Trans id="" context="">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual(generateMessageId("right")) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the generated id when id is a directive", () => { | ||
| run( | ||
| ` | ||
| <Trans :id="direction.right">right</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getId(node, "right")).toEqual(generateMessageId("right")) | ||
| } | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe("getContent", () => { | ||
| it("should return the content of a Trans component", () => { | ||
| run( | ||
| ` | ||
| <Trans>This is some random content</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("This is some random content") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content without blank", () => { | ||
| run( | ||
| ` | ||
| <Trans> This is some random content </Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("This is some random content") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content without line break", () => { | ||
| run( | ||
| ` | ||
| <Trans> | ||
| This is some random content | ||
| </Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("This is some random content") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content with named placeholder when var", () => { | ||
| run( | ||
| ` | ||
| <Trans>Hello {{ name }}</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("Hello {name}") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content with all named placeholder when var", () => { | ||
| run( | ||
| ` | ||
| <Trans>Hello {{ name }} welcome to {{ town }} you are now a {{ persona }}!</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual( | ||
| "Hello {name} welcome to {town} you are now a {persona}!" | ||
| ) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content with placeholder when inner tag", () => { | ||
| run( | ||
| ` | ||
| <Trans>Hello <em>{{ name }}</em> welcome to {{ town }} <br /> <span>you are now <em><i>a {{ persona }}</i></em></span>!</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual( | ||
| "Hello <0>{name}</0> welcome to {town} <1/> <2>you are now <3><4>a {persona}</4></3></2>!" | ||
| ) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content with placeholder when contains complex interpolation", () => { | ||
| run( | ||
| ` | ||
| <Trans>Hello {{ user.name }}</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("Hello {0}") | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("should return the content with placeholders sequentially when contains multiple complex interpolation", () => { | ||
| run( | ||
| ` | ||
| <Trans>Hello {{ user ? user : "John" }} and {{ guest.name }}</Trans> | ||
| `, | ||
| (node) => { | ||
| expect(getContent(node).content).toEqual("Hello {0} and {1}") | ||
| } | ||
| ) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.