gt-vue 0.1.0-iris.2 → 0.1.1

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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # gt-vue
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2130](https://github.com/generaltranslation/gt/pull/2130) [`b25c1d8`](https://github.com/generaltranslation/gt/commit/b25c1d87def728352d3dc089d954ef48bb3bd40e) Thanks [@eoinest](https://github.com/eoinest)! - Support custom locale mappings in request-scoped `createGT()` plugins.
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#2012](https://github.com/generaltranslation/gt/pull/2012) [`8d376e2`](https://github.com/generaltranslation/gt/commit/8d376e23c80828dfd8756e2f0fbf0f7725e0f178) Thanks [@eoinest](https://github.com/eoinest)! - Add a lightweight Vue 3 runtime with catalog-backed string and rich-content
14
+ translation, cookie-backed reactive locale switching, child-only variables,
15
+ and typed value props for number, currency, and date formatting. Browser SPAs
16
+ restore the locale from a configurable cookie, while an explicit server locale
17
+ wins during SSR hydration.
18
+
19
+ ### Patch Changes
20
+
21
+ - [#2068](https://github.com/generaltranslation/gt/pull/2068) [`f2204b9`](https://github.com/generaltranslation/gt/commit/f2204b990278865c54d14d337392930ea1ec31bf) Thanks [@eoinest](https://github.com/eoinest)! - Translate statically authored custom-component default slots, preserve authored
22
+ Fragments, and align Branch and Plural wire values, rendering fallbacks, and
23
+ locale selection with React. Add React-compatible `context`, `id`, `maxChars`,
24
+ and `requiresReview` metadata to `<T>`, including compiler-facing `$` aliases.
25
+
26
+ - [#2080](https://github.com/generaltranslation/gt/pull/2080) [`5d8b78a`](https://github.com/generaltranslation/gt/commit/5d8b78a1085d5dadc5bdc7435b3c6addf8981c38) Thanks [@eoinest](https://github.com/eoinest)! - Migrate the package license from FSL-1.1-ALv2 to MIT.
27
+
28
+ - [#2090](https://github.com/generaltranslation/gt/pull/2090) [`95b48df`](https://github.com/generaltranslation/gt/commit/95b48df677d27f41a336f13e01ae7aa9aa484c73) Thanks [@eoinest](https://github.com/eoinest)! - Add browser SPA initialization and synchronous module-level `t()` translations
29
+ to gt-vue.
30
+ - Updated dependencies [[`f2204b9`](https://github.com/generaltranslation/gt/commit/f2204b990278865c54d14d337392930ea1ec31bf), [`b05b470`](https://github.com/generaltranslation/gt/commit/b05b4703fbbfd34a3cbee335c786e2e606346167), [`8d376e2`](https://github.com/generaltranslation/gt/commit/8d376e23c80828dfd8756e2f0fbf0f7725e0f178)]:
31
+ - @generaltranslation/format@0.1.8
32
+ - generaltranslation@9.1.7
33
+ - gt-i18n@1.0.17
34
+
3
35
  ## 0.1.0-iris.2
4
36
 
5
37
  ### Patch Changes
package/README.md CHANGED
@@ -87,8 +87,8 @@ applied.
87
87
  ## Module-level translations in a Vite SPA
88
88
 
89
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.
90
+ loaded the active locale. Use an async bootstrap function, and dynamically
91
+ import the rest of the application only after initialization.
92
92
  This complements rather than replaces the `gt()` callback from `useGT()`,
93
93
  which remains the normal API inside Vue components and for SSR applications.
94
94
 
@@ -98,9 +98,15 @@ import { initializeGTSPA } from 'gt-vue';
98
98
  import gtConfig from '../gt.config.json';
99
99
  import loadTranslations from './loadTranslations';
100
100
 
101
- const gt = await initializeGTSPA({ ...gtConfig, loadTranslations });
102
- const { mount } = await import('./main');
103
- mount(gt);
101
+ async function bootstrap() {
102
+ const gt = await initializeGTSPA({ ...gtConfig, loadTranslations });
103
+ const { mount } = await import('./main');
104
+ mount(gt);
105
+ }
106
+
107
+ void bootstrap().catch((error: unknown) => {
108
+ console.error(error);
109
+ });
104
110
  ```
105
111
 
106
112
  Configure the CLI output and the Vite loader to use the same directory:
@@ -245,6 +251,19 @@ and then the default locale. Inside `<T>`, the rich translation pipeline owns
245
251
  formatting locales: source fallbacks use the default locale, while translated
246
252
  content uses the active locale followed by the default.
247
253
 
254
+ Pass `customMapping` to `createGT()` when a catalog uses a locale alias that
255
+ should format with a canonical locale. The alias remains the catalog loader,
256
+ cache, and cookie value; only formatters and plural rules use the mapped code.
257
+
258
+ ```ts
259
+ const gt = createGT({
260
+ defaultLocale: 'en-US',
261
+ locale: 'pirate',
262
+ customMapping: { pirate: { code: 'fr-FR' } },
263
+ loadTranslations,
264
+ });
265
+ ```
266
+
248
267
  In a browser, gt-vue persists the active locale in the
249
268
  `generaltranslation.locale` path-wide session cookie. When `locale` is omitted
250
269
  from `createGT()`, that cookie wins over `defaultLocale`. Use
package/dist/index.cjs CHANGED
@@ -33,7 +33,7 @@ const gtContextKey = Symbol.for("generaltranslation.gt-vue.context");
33
33
  function createGT(options = {}) {
34
34
  return createGTRuntime(options).plugin;
35
35
  }
36
- function createGTRuntime({ defaultLocale = generaltranslation_internal.libraryDefaultLocale, loadTranslations, locale: explicitLocale, localeCookieName = gt_i18n_internal_cookies.defaultLocaleCookieName } = {}, runtimeOptions = {}) {
36
+ function createGTRuntime({ customMapping, defaultLocale = generaltranslation_internal.libraryDefaultLocale, loadTranslations, locale: explicitLocale, localeCookieName = gt_i18n_internal_cookies.defaultLocaleCookieName } = {}, runtimeOptions = {}) {
37
37
  const localeAccessor = createCookieBackedLocale({
38
38
  defaultLocale,
39
39
  locale: explicitLocale,
@@ -45,6 +45,7 @@ function createGTRuntime({ defaultLocale = generaltranslation_internal.libraryDe
45
45
  const pending = /* @__PURE__ */ new Map();
46
46
  const initialLocale = localeAccessor.getLocale();
47
47
  const getLocale = runtimeOptions.pinLocale ? () => initialLocale : () => localeAccessor.getLocale();
48
+ const resolveFormattingLocale = runtimeOptions.resolveFormattingLocale ?? createFormattingLocaleResolver(customMapping);
48
49
  let localeRequest = 0;
49
50
  const load = async (locale) => {
50
51
  const targetLocale = runtimeOptions.resolveLocale?.(locale) ?? locale;
@@ -92,7 +93,7 @@ function createGTRuntime({ defaultLocale = generaltranslation_internal.libraryDe
92
93
  return getLocale();
93
94
  },
94
95
  loadTranslations: load,
95
- resolveFormattingLocale: runtimeOptions.resolveFormattingLocale,
96
+ resolveFormattingLocale,
96
97
  revision,
97
98
  setLocale
98
99
  };
@@ -109,6 +110,18 @@ function createGTRuntime({ defaultLocale = generaltranslation_internal.libraryDe
109
110
  state
110
111
  };
111
112
  }
113
+ function createFormattingLocaleResolver(customMapping) {
114
+ if (customMapping === void 0) return void 0;
115
+ return (locale) => {
116
+ const customLocale = customMapping[locale];
117
+ const mappedLocale = typeof customLocale === "object" && customLocale !== null && typeof customLocale.code === "string" ? customLocale.code : locale;
118
+ try {
119
+ return Intl.getCanonicalLocales(mappedLocale)[0] ?? locale;
120
+ } catch {
121
+ return locale;
122
+ }
123
+ };
124
+ }
112
125
  function useGTState() {
113
126
  const state = (0, vue.inject)(gtContextKey);
114
127
  if (state) return state;