Skip to content

Commit 1da125d

Browse files
committed
feat(vue): add gt-vue package
Vue 3 binding for General Translation, built on the gt-i18n runtime: - <T> component with VNode -> GT JSX serialization and translated-tree reconciliation (matching the shared GT JSX wire format) - Var, Num, Currency, DateTime, RelativeTime variable components - Branch and Plural branching components using named slots - useGT, useMessages, useTranslations, locale composables, LocaleSelector - initializeGTSPA bootstrap and optional GTProvider component - dev hot reload: cache misses trigger runtime translation and reactive re-render
1 parent 31884d2 commit 1da125d

46 files changed

Lines changed: 3229 additions & 6 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Turbo tasks: `build`, `test`, `lint`, `lint:fix`, `format`, `format:fix`, `trans
4848
| `gt-node` | `packages/node` | Node.js backend translation utilities |
4949
| `gt-react-native` | `packages/react-native` | React Native i18n with native module support |
5050
| `gt-tanstack-start` | `packages/tanstack-start` | TanStack Start integration |
51+
| `gt-vue` | `packages/vue` | Vue 3 i18n with `<T>` component, composables, SPA bootstrap |
5152
| `gt-sanity` | `packages/sanity` | Sanity CMS plugin |
5253
| `@generaltranslation/compiler` | `packages/compiler` | Build plugin (webpack, Vite, Rollup, esbuild) via unplugin |
5354
| `gt` | `packages/cli` | Main CLI tool (`npx gt`) |

‎packages/vue/.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
package-lock.json
3+
archived
4+
.rollup.cache

‎packages/vue/.npmignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src
2+
node_modules
3+
package-lock.json

‎packages/vue/README.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# gt-vue
2+
3+
Automatic i18n for Vue 3, powered by [General Translation](https://generaltranslation.com).
4+
5+
`gt-vue` is the Vue binding of the GT libraries: the same `<T>` component, string
6+
translation functions, and translation infrastructure as
7+
[`gt-react`](https://www.npmjs.com/package/gt-react) and
8+
[`gt-next`](https://www.npmjs.com/package/gt-next), built on the framework-agnostic
9+
[`gt-i18n`](https://www.npmjs.com/package/gt-i18n) runtime.
10+
11+
## Quickstart
12+
13+
Initialize GT in a bootstrap entry point before mounting your app:
14+
15+
```ts
16+
// src/index.ts
17+
import { initializeGTSPA } from 'gt-vue';
18+
import gtConfig from '../gt.config.json';
19+
20+
async function loadTranslations(locale: string) {
21+
return (await import(`./_gt/${locale}.json`)).default;
22+
}
23+
24+
await initializeGTSPA({
25+
...gtConfig,
26+
loadTranslations,
27+
});
28+
29+
await import('./main');
30+
```
31+
32+
Then translate JSX-like content with `<T>` and strings with `useGT()`:
33+
34+
```vue
35+
<script setup lang="ts">
36+
import { T, Var, Num, Plural, LocaleSelector, useGT } from 'gt-vue';
37+
38+
const gt = useGT();
39+
</script>
40+
41+
<template>
42+
<LocaleSelector />
43+
<T>
44+
<p>
45+
Hello,
46+
<Var>{{ userName }}</Var>
47+
!
48+
</p>
49+
<Plural :n="count">
50+
<template #one>
51+
<p>
52+
You have
53+
<Num :value="count" />
54+
item.
55+
</p>
56+
</template>
57+
<template #other>
58+
<p>
59+
You have
60+
<Num :value="count" />
61+
items.
62+
</p>
63+
</template>
64+
</Plural>
65+
</T>
66+
<input :placeholder="gt('Enter your email')" />
67+
</template>
68+
```
69+
70+
Alternatively, wrap your app in `<GTProvider>` instead of calling
71+
`initializeGTSPA()` yourself.
72+
73+
In development, set `devApiKey` (e.g. from `import.meta.env.VITE_GT_API_KEY`) to
74+
enable dev hot reload: missing translations are generated on the fly while you
75+
edit.
76+
77+
## Docs
78+
79+
Full documentation, guides, and API references:
80+
[generaltranslation.com/docs](https://generaltranslation.com/docs)

‎packages/vue/package.json‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "gt-vue",
3+
"version": "1.0.0-odysseus.0",
4+
"description": "Automatic i18n for Vue",
5+
"main": "./dist/index.cjs",
6+
"module": "./dist/index.mjs",
7+
"types": "./dist/index.d.cts",
8+
"files": [
9+
"dist",
10+
"CHANGELOG.md"
11+
],
12+
"sideEffects": false,
13+
"peerDependencies": {
14+
"vue": ">=3.4.0"
15+
},
16+
"dependencies": {
17+
"@generaltranslation/format": "workspace:*",
18+
"@generaltranslation/supported-locales": "workspace:*",
19+
"generaltranslation": "workspace:*",
20+
"gt-i18n": "workspace:*"
21+
},
22+
"scripts": {
23+
"build": "tsdown",
24+
"build:clean": "sh ../../scripts/clean.sh && pnpm run build",
25+
"build:release": "pnpm run build:clean",
26+
"release": "pnpm run build:clean && pnpm publish",
27+
"release:alpha": "pnpm run build:clean && pnpm publish --tag alpha",
28+
"release:beta": "pnpm run build:clean && pnpm publish --tag beta",
29+
"release:latest": "pnpm run build:clean && pnpm publish --tag latest",
30+
"test": "vitest run",
31+
"test:watch": "vitest",
32+
"typecheck": "tsc --noEmit"
33+
},
34+
"repository": {
35+
"type": "git",
36+
"url": "git+https://github.com/generaltranslation/gt.git"
37+
},
38+
"author": "General Translation, Inc.",
39+
"license": "FSL-1.1-ALv2",
40+
"bugs": {
41+
"url": "https://github.com/generaltranslation/gt/issues"
42+
},
43+
"homepage": "https://generaltranslation.com/",
44+
"devDependencies": {
45+
"@types/node": "catalog:",
46+
"tsdown": "catalog:",
47+
"typescript": "catalog:",
48+
"vitest": "catalog:",
49+
"vue": "^3.5.13"
50+
},
51+
"exports": {
52+
".": {
53+
"require": {
54+
"types": "./dist/index.d.cts",
55+
"default": "./dist/index.cjs"
56+
},
57+
"import": {
58+
"types": "./dist/index.d.mts",
59+
"default": "./dist/index.mjs"
60+
},
61+
"default": "./dist/index.mjs"
62+
}
63+
},
64+
"keywords": [
65+
"vue",
66+
"translation",
67+
"internationalization",
68+
"localization",
69+
"i18n"
70+
]
71+
}

0 commit comments

Comments
 (0)