@scalar/localization 0.2.0 → 0.2.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,12 @@
1
1
  # @scalar/localization
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10175](https://github.com/scalar/scalar/pull/10175): Support API Client UI translations through `localization.translations.apiClient`, including the client embedded in API Reference. Ship client translations for English, Russian, Spanish, French, German, Simplified Chinese, Arabic, and Portuguese to match API Reference. Preserve English fallbacks across package providers and react to locale, direction, and translation updates.
8
+ - [#10175](https://github.com/scalar/scalar/pull/10175): Preserve literal dollar sequences in interpolated translation values, including existing API Reference translations.
9
+
3
10
  ## 0.2.0
4
11
 
5
12
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"create-localization.d.ts","sourceRoot":"","sources":["../src/create-localization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,gBAAgB,EAAsC,MAAM,KAAK,CAAA;AAEpH,wDAAwD;AACxD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAA;AAEzC,+EAA+E;AAC/E,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG,MAAM,CAAA;AAE5D,qFAAqF;AACrF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAE7D,yDAAyD;AACzD,MAAM,MAAM,WAAW,CAAC,GAAG,SAAS,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,eAAe,KAAK,MAAM,CAAA;AAE5F,yEAAyE;AACzE,MAAM,MAAM,mBAAmB,CAAC,YAAY,EAAE,GA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9D,MAAM,MAAM,iBAAiB,CAAC,YAAY,IAAI;IAC5C,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oEAAoE;IACpE,SAAS,CAAC,EAAE,uBAAuB,CAAA;IACnC,yFAAyF;IACzF,YAAY,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;CACzC,CAAA;AAED,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,CAAC,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC7E,+GAA+G;IAC/G,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAChD,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAA;IACrB,8EAA8E;IAC9E,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACvB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAYD;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,SAAS,MAAM,EACjG,QAAQ,kBAAkB,CAAC,YAAY,CAAC;yCAoCI,iBAAiB,CAAC,YAAY,CAAC,KAAG,oBAAoB,CAAC,YAAY,CAAC;wCAsDrE,gBAAgB,CAAC,iBAAiB,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;2BAkB5E,mBAAmB,CAAC,YAAY,EAAE,GAAG,CAAC;CA8BnE,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { getValueAtPath } from '@scalar/helpers/object/get-value-at-path';
2
2
  import { mergeObjects } from '@scalar/helpers/object/merge-objects';
3
- import { computed, inject, provide, toValue } from 'vue';
3
+ import { computed, effectScope, inject, provide, toValue, } from 'vue';
4
4
  /**
5
5
  * Shared injection key for the localization context.
6
6
  *
@@ -69,7 +69,7 @@ export const createLocalization = (config) => {
69
69
  if (!params) {
70
70
  return template;
71
71
  }
72
- return Object.entries(params).reduce((result, [param, paramValue]) => result.replaceAll(`{${param}}`, String(paramValue)), template);
72
+ return Object.entries(params).reduce((result, [param, paramValue]) => result.replaceAll(`{${param}}`, () => String(paramValue)), template);
73
73
  };
74
74
  const createContext = (localization) => {
75
75
  const resolved = computed(() => resolveLocalization(toValue(localization)));
@@ -80,15 +80,38 @@ export const createLocalization = (config) => {
80
80
  translate: (key, params) => translate(resolved.value.translations, key, params),
81
81
  };
82
82
  };
83
+ const ownContexts = new WeakSet();
83
84
  const provideLocalization = (localization) => {
84
85
  const context = createContext(localization);
86
+ ownContexts.add(context);
85
87
  provide(LOCALIZATION_SYMBOL, context);
86
88
  return context;
87
89
  };
88
90
  // Built once per instance and reused as the no-provider fallback, so `useLocalization` does not
89
91
  // construct a fresh context (and its computed chain) on every call.
90
92
  const fallbackContext = createContext(undefined);
91
- const useLocalization = () => inject(LOCALIZATION_SYMBOL, fallbackContext);
93
+ const inheritedContexts = new WeakMap();
94
+ const useLocalization = () => {
95
+ const inherited = inject(LOCALIZATION_SYMBOL, fallbackContext);
96
+ if (inherited === fallbackContext || ownContexts.has(inherited)) {
97
+ return inherited;
98
+ }
99
+ // Packages can contribute different dictionaries under the same provider. Resolve their own
100
+ // defaults before consuming the inherited overrides, and share that work between consumers.
101
+ const cached = inheritedContexts.get(inherited);
102
+ if (cached) {
103
+ return cached;
104
+ }
105
+ // This cached context outlives the first consumer. A detached scope makes ownership explicit;
106
+ // the context contains only lazy computeds, with no watchers or external resources to dispose.
107
+ const context = effectScope(true).run(() => createContext(() => ({
108
+ locale: inherited.locale.value,
109
+ direction: inherited.direction.value,
110
+ translations: inherited.translations.value,
111
+ })));
112
+ inheritedContexts.set(inherited, context);
113
+ return context;
114
+ };
92
115
  return {
93
116
  resolveLocalization,
94
117
  provideLocalization,
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "i18n",
17
17
  "translations"
18
18
  ],
19
- "version": "0.2.0",
19
+ "version": "0.2.1",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -37,9 +37,9 @@
37
37
  ],
38
38
  "sideEffects": false,
39
39
  "dependencies": {
40
+ "@scalar/helpers": "0.13.0",
40
41
  "type-fest": "^5.8.0",
41
- "vue": "^3.5.40",
42
- "@scalar/helpers": "0.12.0"
42
+ "vue": "^3.5.40"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@vue/test-utils": "2.4.11",