gt-vue 0.1.0 → 0.1.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # gt-vue
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`34845f9`](https://github.com/generaltranslation/gt/commit/34845f92d64fd9c94a712e4710e8958022066b7b)]:
8
+ - generaltranslation@9.1.8
9
+ - gt-i18n@1.0.18
10
+
11
+ ## 0.1.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#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.
16
+
3
17
  ## 0.1.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -251,6 +251,19 @@ and then the default locale. Inside `<T>`, the rich translation pipeline owns
251
251
  formatting locales: source fallbacks use the default locale, while translated
252
252
  content uses the active locale followed by the default.
253
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
+
254
267
  In a browser, gt-vue persists the active locale in the
255
268
  `generaltranslation.locale` path-wide session cookie. When `locale` is omitted
256
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;