gt-vue 0.1.0-iris.0 → 0.1.0-iris.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/LICENSE.md +18 -102
- package/README.md +125 -25
- package/dist/index.cjs +432 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -23
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +85 -23
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +432 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# gt-vue
|
|
2
2
|
|
|
3
|
+
## 0.1.0-iris.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 95b48df: Add browser SPA initialization and synchronous module-level `t()` translations
|
|
8
|
+
to gt-vue.
|
|
9
|
+
|
|
10
|
+
## 0.1.0-iris.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- f2204b9: Translate statically authored custom-component default slots, preserve authored
|
|
15
|
+
Fragments, and align Branch and Plural wire values, rendering fallbacks, and
|
|
16
|
+
locale selection with React. Add React-compatible `context`, `id`, `maxChars`,
|
|
17
|
+
and `requiresReview` metadata to `<T>`, including compiler-facing `$` aliases.
|
|
18
|
+
- 5d8b78a: Migrate the package license from FSL-1.1-ALv2 to MIT.
|
|
19
|
+
- Updated dependencies [f2204b9]
|
|
20
|
+
- Updated dependencies [b05b470]
|
|
21
|
+
- Updated dependencies [5d8b78a]
|
|
22
|
+
- generaltranslation@9.1.3-iris.0
|
|
23
|
+
- gt-i18n@1.0.13-iris.0
|
|
24
|
+
|
|
3
25
|
## 0.1.0-iris.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,105 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
## Abbreviation
|
|
4
|
-
|
|
5
|
-
FSL-1.1-ALv2
|
|
6
|
-
|
|
7
|
-
## Notice
|
|
1
|
+
MIT License
|
|
8
2
|
|
|
9
3
|
Copyright 2025 General Translation, Inc.
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
-
|
|
30
|
-
### Permitted Purpose
|
|
31
|
-
|
|
32
|
-
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
-
means making the Software available to others in a commercial product or
|
|
34
|
-
service that:
|
|
35
|
-
|
|
36
|
-
1. substitutes for the Software;
|
|
37
|
-
|
|
38
|
-
2. substitutes for any other product or service we offer using the Software
|
|
39
|
-
that exists as of the date we make the Software available; or
|
|
40
|
-
|
|
41
|
-
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
-
|
|
43
|
-
Permitted Purposes specifically include using the Software:
|
|
44
|
-
|
|
45
|
-
1. for your internal use and access;
|
|
46
|
-
|
|
47
|
-
2. for non-commercial education;
|
|
48
|
-
|
|
49
|
-
3. for non-commercial research; and
|
|
50
|
-
|
|
51
|
-
4. in connection with professional services that you provide to a licensee
|
|
52
|
-
using the Software in accordance with these Terms and Conditions.
|
|
53
|
-
|
|
54
|
-
### Patents
|
|
55
|
-
|
|
56
|
-
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
-
patents, the license grant above includes a license under our patents. If you
|
|
58
|
-
make a claim against any party that the Software infringes or contributes to
|
|
59
|
-
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
-
immediately.
|
|
61
|
-
|
|
62
|
-
### Redistribution
|
|
63
|
-
|
|
64
|
-
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
-
the Software.
|
|
66
|
-
|
|
67
|
-
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
-
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
-
remove any copyright notices provided in or with the Software.
|
|
70
|
-
|
|
71
|
-
### Disclaimer
|
|
72
|
-
|
|
73
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
-
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
-
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
-
|
|
77
|
-
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
-
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
-
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
-
|
|
81
|
-
### Trademarks
|
|
82
|
-
|
|
83
|
-
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
-
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
-
trademarks, trade names, service marks or product names.
|
|
86
|
-
|
|
87
|
-
## Grant of Future License
|
|
88
|
-
|
|
89
|
-
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
-
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
-
the date we make the Software available. On or after that date, you may use the
|
|
92
|
-
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
-
will apply:
|
|
94
|
-
|
|
95
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
-
this file except in compliance with the License.
|
|
97
|
-
|
|
98
|
-
You may obtain a copy of the License at
|
|
99
|
-
|
|
100
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
-
|
|
102
|
-
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
-
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
-
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
-
specific language governing permissions and limitations under the License.
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://generaltranslation.com/docs
|
|
2
|
+
<a href="https://generaltranslation.com/docs">
|
|
3
3
|
<picture>
|
|
4
4
|
<source media="(prefers-color-scheme: dark)" srcset="https://generaltranslation.com/brand/gt-logo-dark.svg">
|
|
5
5
|
<img alt="General Translation" src="https://generaltranslation.com/brand/gt-logo-light.svg" width="100" height="100">
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
<a href="https://generaltranslation.com/docs
|
|
11
|
+
<a href="https://generaltranslation.com/docs"><strong>Documentation</strong></a> · <a href="https://github.com/generaltranslation/gt/issues">Report Bug</a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
# gt-vue
|
|
@@ -84,22 +84,113 @@ const setLocale = useSetLocale();
|
|
|
84
84
|
`$context`; braces are literal text and no ICU formatting or interpolation is
|
|
85
85
|
applied.
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
## Module-level translations in a Vite SPA
|
|
88
|
+
|
|
89
|
+
Browser-only SPAs can call `t()` at module scope after `initializeGTSPA()` has
|
|
90
|
+
loaded the active locale. Use a bootstrap module with top-level `await`, and
|
|
91
|
+
dynamically import the rest of the application only after initialization.
|
|
92
|
+
This complements rather than replaces the `gt()` callback from `useGT()`,
|
|
93
|
+
which remains the normal API inside Vue components and for SSR applications.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// src/index.ts
|
|
97
|
+
import { initializeGTSPA } from 'gt-vue';
|
|
98
|
+
import gtConfig from '../gt.config.json';
|
|
99
|
+
import loadTranslations from './loadTranslations';
|
|
100
|
+
|
|
101
|
+
const gt = await initializeGTSPA({ ...gtConfig, loadTranslations });
|
|
102
|
+
const { mount } = await import('./main');
|
|
103
|
+
mount(gt);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Configure the CLI output and the Vite loader to use the same directory:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"defaultLocale": "en",
|
|
111
|
+
"locales": ["fr"],
|
|
112
|
+
"files": {
|
|
113
|
+
"gt": {
|
|
114
|
+
"output": "src/_gt/[locale].json"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// src/loadTranslations.ts
|
|
122
|
+
export default async function loadTranslations(locale: string) {
|
|
123
|
+
const translations = await import(`./_gt/${locale}.json`);
|
|
124
|
+
return translations.default;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Create an empty JSON file for each configured target locale before the first
|
|
129
|
+
translation run (for example, `src/_gt/fr.json` containing `{}`). The default
|
|
130
|
+
locale uses source content and does not need a loader file.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// src/main.ts
|
|
134
|
+
import { createApp } from 'vue';
|
|
135
|
+
import type { GTPlugin } from 'gt-vue';
|
|
136
|
+
import App from './App.vue';
|
|
137
|
+
|
|
138
|
+
export function mount(gt: GTPlugin) {
|
|
139
|
+
createApp(App).use(gt).mount('#app');
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Install the plugin returned by `initializeGTSPA()` rather than creating a
|
|
144
|
+
second plugin. The returned instance is already preloaded and is the exact
|
|
145
|
+
runtime used by `t()`.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
// src/navigation.ts (loaded by the dynamic application import)
|
|
149
|
+
import { t } from 'gt-vue';
|
|
150
|
+
|
|
151
|
+
export const navigation = [
|
|
152
|
+
t('Documentation', { $context: 'primary navigation' }),
|
|
153
|
+
];
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Like `useGT()`, `t()` supports only plain STRING content and static `$context`.
|
|
157
|
+
It does not support ICU syntax, interpolation, tagged templates, `$format`, or
|
|
158
|
+
`$maxChars`. The extractor registers static `t()` calls in the catalog.
|
|
159
|
+
|
|
160
|
+
SPA locale changes write the locale cookie and reload the page. Reloading is
|
|
161
|
+
intentional: it lets every module-level translation execute again after the new
|
|
162
|
+
locale catalog is preloaded. `initializeGTSPA()` and `t()` are not valid in SSR;
|
|
163
|
+
use one request-scoped `createGT({ locale })` instance there.
|
|
164
|
+
|
|
165
|
+
Statically authored default-slot content inside a custom component participates
|
|
166
|
+
in the surrounding translation. The component itself, its props, and its
|
|
167
|
+
listeners are preserved while the translated content replaces its default
|
|
168
|
+
slot:
|
|
169
|
+
|
|
170
|
+
```vue
|
|
171
|
+
<T>
|
|
172
|
+
<DocsLink to="/docs">Read the documentation</DocsLink>
|
|
173
|
+
</T>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Content created inside `DocsLink`'s implementation is not visible to the outer
|
|
177
|
+
`<T>`. Runtime values still belong in `<Var>`, and conditional alternatives
|
|
178
|
+
belong in `<Branch>` or `<Plural>`. Scoped and arbitrary named slots depend on
|
|
179
|
+
the child component's runtime behavior, so place `<T>` inside those slots or
|
|
180
|
+
enclose the dynamic component boundary in `<Var>`. Component tags inside `<T>`
|
|
181
|
+
must resolve at runtime; an unresolved component warning from Vue is a
|
|
182
|
+
configuration error and is not a supported translation source. Use direct
|
|
183
|
+
component tags inside an outer `<T>`: Vue's `<component :is>` and
|
|
184
|
+
`is="vue:..."` selector forms are intentionally rejected by extraction because
|
|
185
|
+
global runtime registration can change their component identity after build.
|
|
186
|
+
|
|
187
|
+
Vue built-ins with statically authored default content follow the same rule.
|
|
188
|
+
`<Suspense>` needs one additional distinction: its default content participates
|
|
189
|
+
in an outer `<T>`, while its fallback slot is preserved but excluded from that
|
|
190
|
+
translation. Prefer literal `<Suspense>` with a single default root. Immutable
|
|
191
|
+
aliases that the extractor can trace directly to `vue` are also supported.
|
|
192
|
+
Re-exported, globally registered, ref/computed-held, and other runtime-wrapped
|
|
193
|
+
Suspense aliases are not supported inside an outer `<T>`. Put `<T>` inside those
|
|
103
194
|
boundaries instead:
|
|
104
195
|
|
|
105
196
|
```vue
|
|
@@ -129,7 +220,10 @@ const m = useMessages();
|
|
|
129
220
|
|
|
130
221
|
## Components
|
|
131
222
|
|
|
132
|
-
- `<T context="...">` translates rich slot
|
|
223
|
+
- `<T context="..." :max-chars="80" requires-review>` translates rich slot
|
|
224
|
+
content and supplies translation metadata. The deprecated `id` prop is
|
|
225
|
+
accepted for React API compatibility but does not replace the content-based
|
|
226
|
+
catalog hash.
|
|
133
227
|
- `<Var>` preserves a dynamic slot value inside `<T>`.
|
|
134
228
|
- `<Num>`, `<DateTime>`, and `<Currency>` require typed runtime values through
|
|
135
229
|
`:value`; formatter slot children are not supported.
|
|
@@ -157,12 +251,18 @@ from `createGT()`, that cookie wins over `defaultLocale`. Use
|
|
|
157
251
|
`localeCookieName` to share a different cookie with your routing or server
|
|
158
252
|
integration.
|
|
159
253
|
|
|
160
|
-
`setLocale()` loads a missing catalog
|
|
161
|
-
consumers. A failed or superseded
|
|
162
|
-
locale unchanged. Direct changes to
|
|
163
|
-
`plugin.getLocale()` and the next Vue render,
|
|
164
|
-
change events, so they do not schedule a render
|
|
165
|
-
setter for reactive locale changes.
|
|
254
|
+
For plugins created with `createGT()`, `setLocale()` loads a missing catalog
|
|
255
|
+
before writing the cookie and rerendering consumers. A failed or superseded
|
|
256
|
+
request leaves both the cookie and rendered locale unchanged. Direct changes to
|
|
257
|
+
`document.cookie` are reflected by `plugin.getLocale()` and the next Vue render,
|
|
258
|
+
but browsers do not emit cookie change events, so they do not schedule a render
|
|
259
|
+
by themselves. Use gt-vue's setter for reactive locale changes.
|
|
260
|
+
|
|
261
|
+
`initializeGTSPA()` instead pins the preloaded locale for the lifetime of the
|
|
262
|
+
page. Its `setLocale()` writes the cookie and reloads the document so
|
|
263
|
+
module-level `t()` calls execute again with the new catalog. Direct cookie
|
|
264
|
+
changes do not change the mounted SPA; they are resolved during the next page
|
|
265
|
+
initialization, and unsupported locales fall back to `defaultLocale`.
|
|
166
266
|
|
|
167
267
|
For SSR, resolve the request locale on the server and pass it as
|
|
168
268
|
`createGT({ locale })`. An explicit locale wins over a stale browser cookie,
|