@wix/site-service-locale 1.0.10 → 1.0.11

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @wix/site-service-locale
2
2
 
3
- A thin signal-backed service that exposes the current site language, text direction, regional locale, and time zone.
3
+ A thin signal-backed service that exposes the site visitor's language, regional format, and currency, and the site's text direction and time zone.
4
4
 
5
5
  ## Install
6
6
 
@@ -23,20 +23,24 @@ service.language
23
23
  service.direction
24
24
  service.locale
25
25
  service.timeZone
26
+ service.currency
26
27
  ```
27
28
 
28
29
  ## API
29
30
 
30
31
  | Member | Type | Throws when | Description |
31
32
  |---|---|---|---|
32
- | `language` | `Language` | never | Site primary language code (for example `en`, `fr`). |
33
+ | `language` | `Language` | never | Language the site visitor sees (for example `en`, `fr`). Changes when `setLanguage()` is called. |
33
34
  | `direction` | `LanguageDirection` | never | Site text direction (`ltr` or `rtl`). |
34
- | `locale` | `string` | never | BCP-47 locale used for regional formatting (for example `en-US`, `de-CH`). |
35
+ | `locale` | `string` | never | Site visitor's BCP-47 regional format (for example `en-US`, `de-CH`). Changes when `setLocale()` is called. |
35
36
  | `timeZone` | `string` | never | IANA time zone of the site's business (for example `America/New_York`, `Europe/Zurich`). |
37
+ | `currency` | `string` | never | Site visitor's ISO 4217 currency code (for example `USD`). Starts as the `currency` query param in the page URL, otherwise the site's currency, and changes when `setCurrency()` is called. |
36
38
  | `_updateConfig` | `(Partial<ILocaleServiceConfig>) => void` | never | Private replace-on-write updater for provided fields. |
37
39
 
38
40
  ## Configuration
39
41
 
42
+ `language`, `locale` and `currency` come from the host's common config. The setters are in `@wix/site-service-renderer-configuration`.
43
+
40
44
  `ILocaleServiceConfig`:
41
45
 
42
46
  ```ts
@@ -45,6 +49,7 @@ type ILocaleServiceConfig = {
45
49
  direction: LanguageDirection
46
50
  locale: string
47
51
  timeZone: string
52
+ currency: string
48
53
  }
49
54
  ```
50
55
 
@@ -5,17 +5,21 @@ export type ILocaleServiceConfig = {
5
5
  direction: LanguageDirection;
6
6
  locale: string;
7
7
  timeZone: string;
8
+ currency: string;
8
9
  };
9
10
  /**
10
- * Reports the site's language, text direction, regional format, and time zone, so code running on the
11
- * site can format and lay out content to match the site's settings.
11
+ * Reports the site visitor's language, regional format, and currency, and the site's text direction and time
12
+ * zone, so code running on the site can format and lay out content for the site visitor.
13
+ *
14
+ * The language, regional format, and currency come from the host's common config. They can change while the
15
+ * page is open, through the setters in `@wix/site-service-renderer-configuration`.
12
16
  */
13
17
  export interface ILocaleService {
14
18
  /**
15
- * Site's main language, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
19
+ * Language the site visitor sees, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
16
20
  *
17
21
  * On a site with [Wix Multilingual](https://support.wix.com/en/article/wix-multilingual-an-overview),
18
- * this is the main language, even when a site visitor views the site in another language.
22
+ * this is the language the site visitor views, and it changes when `setLanguage()` is called.
19
23
  *
20
24
  * The code has no region, so formatting dates and numbers with it alone loses regional conventions.
21
25
  * Use `locale` for formatting.
@@ -32,11 +36,11 @@ export interface ILocaleService {
32
36
  */
33
37
  readonly direction: LanguageDirection;
34
38
  /**
35
- * Site's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
39
+ * Site visitor's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
36
40
  *
37
- * It's the site's setting, not the site visitor's browser language. Specify it as the locale for
38
- * `Intl` date and number formatting, so dates and numbers follow the site's conventions for every
39
- * site visitor.
41
+ * It starts as the regional format of the language the site visitor views, and changes when `setLocale()` is
42
+ * called. It's not the site visitor's browser language. Specify it as the locale for `Intl` date and number
43
+ * formatting.
40
44
  *
41
45
  * @exampleValue 'en-US'
42
46
  */
@@ -50,6 +54,15 @@ export interface ILocaleService {
50
54
  * @exampleValue 'America/New_York'
51
55
  */
52
56
  readonly timeZone: string;
57
+ /**
58
+ * Site visitor's currency, as an [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code.
59
+ *
60
+ * It starts as the `currency` query param in the page URL, otherwise the site's currency, and changes when
61
+ * `setCurrency()` is called.
62
+ *
63
+ * @exampleValue 'USD'
64
+ */
65
+ readonly currency: string;
53
66
  /** @internal Host-only. Replaces config values when the host's state changes. */
54
67
  _updateConfig: (config: Partial<ILocaleServiceConfig>) => void;
55
68
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AA8DzD,sEAAsE;AACzD,QAAA,gBAAgB,GAAG,IAAA,oCAAa,EAAuC,0BAA0B,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AA2EzD,sEAAsE;AACzD,QAAA,gBAAgB,GAAG,IAAA,oCAAa,EAAuC,0BAA0B,CAAC,CAAA"}
@@ -10,6 +10,7 @@ exports.LocaleService = (0, services_definitions_1.implementService)(definition_
10
10
  const _direction = signal(config.direction);
11
11
  const _locale = signal(config.locale);
12
12
  const _timeZone = signal(config.timeZone);
13
+ const _currency = signal(config.currency);
13
14
  return {
14
15
  get language() {
15
16
  return _language.get();
@@ -23,7 +24,10 @@ exports.LocaleService = (0, services_definitions_1.implementService)(definition_
23
24
  get timeZone() {
24
25
  return _timeZone.get();
25
26
  },
26
- _updateConfig({ language, direction, locale, timeZone }) {
27
+ get currency() {
28
+ return _currency.get();
29
+ },
30
+ _updateConfig({ language, direction, locale, timeZone, currency }) {
27
31
  if (language) {
28
32
  _language.set(language);
29
33
  }
@@ -36,6 +40,9 @@ exports.LocaleService = (0, services_definitions_1.implementService)(definition_
36
40
  if (timeZone) {
37
41
  _timeZone.set(timeZone);
38
42
  }
43
+ if (currency) {
44
+ _currency.set(currency);
45
+ }
39
46
  },
40
47
  };
41
48
  });
@@ -1 +1 @@
1
- {"version":3,"file":"localeService.js","sourceRoot":"","sources":["../../../src/implementations/localeService.ts"],"names":[],"mappings":";;;AAAA,oEAA4D;AAE5D,6EAA0F;AAE1F,8CAAgD;AAEnC,QAAA,aAAa,GAAG,IAAA,uCAAgB,EAC5C,6BAAgB,EAChB,CAAC,EAAE,MAAM,EAAE,UAAU,EAA4C,EAAkB,EAAE;IACpF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,kCAAwB,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEzC,OAAO;QACN,IAAI,QAAQ;YACX,OAAO,SAAS,CAAC,GAAG,EAAE,CAAA;QACvB,CAAC;QACD,IAAI,SAAS;YACZ,OAAO,UAAU,CAAC,GAAG,EAAE,CAAA;QACxB,CAAC;QACD,IAAI,MAAM;YACT,OAAO,OAAO,CAAC,GAAG,EAAE,CAAA;QACrB,CAAC;QACD,IAAI,QAAQ;YACX,OAAO,SAAS,CAAC,GAAG,EAAE,CAAA;QACvB,CAAC;QACD,aAAa,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAiC;YACrF,IAAI,QAAQ,EAAE,CAAC;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACxB,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACf,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC1B,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,MAAM,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,EAAE,QAAQ,EAAiC;YAC/F,IAAI,QAAQ,EAAE,CAAC;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACxB,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACf,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC1B,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACpB,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACxB,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACxB,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC,CACD,CAAA"}
@@ -5,17 +5,21 @@ export type ILocaleServiceConfig = {
5
5
  direction: LanguageDirection;
6
6
  locale: string;
7
7
  timeZone: string;
8
+ currency: string;
8
9
  };
9
10
  /**
10
- * Reports the site's language, text direction, regional format, and time zone, so code running on the
11
- * site can format and lay out content to match the site's settings.
11
+ * Reports the site visitor's language, regional format, and currency, and the site's text direction and time
12
+ * zone, so code running on the site can format and lay out content for the site visitor.
13
+ *
14
+ * The language, regional format, and currency come from the host's common config. They can change while the
15
+ * page is open, through the setters in `@wix/site-service-renderer-configuration`.
12
16
  */
13
17
  export interface ILocaleService {
14
18
  /**
15
- * Site's main language, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
19
+ * Language the site visitor sees, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
16
20
  *
17
21
  * On a site with [Wix Multilingual](https://support.wix.com/en/article/wix-multilingual-an-overview),
18
- * this is the main language, even when a site visitor views the site in another language.
22
+ * this is the language the site visitor views, and it changes when `setLanguage()` is called.
19
23
  *
20
24
  * The code has no region, so formatting dates and numbers with it alone loses regional conventions.
21
25
  * Use `locale` for formatting.
@@ -32,11 +36,11 @@ export interface ILocaleService {
32
36
  */
33
37
  readonly direction: LanguageDirection;
34
38
  /**
35
- * Site's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
39
+ * Site visitor's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
36
40
  *
37
- * It's the site's setting, not the site visitor's browser language. Specify it as the locale for
38
- * `Intl` date and number formatting, so dates and numbers follow the site's conventions for every
39
- * site visitor.
41
+ * It starts as the regional format of the language the site visitor views, and changes when `setLocale()` is
42
+ * called. It's not the site visitor's browser language. Specify it as the locale for `Intl` date and number
43
+ * formatting.
40
44
  *
41
45
  * @exampleValue 'en-US'
42
46
  */
@@ -50,6 +54,15 @@ export interface ILocaleService {
50
54
  * @exampleValue 'America/New_York'
51
55
  */
52
56
  readonly timeZone: string;
57
+ /**
58
+ * Site visitor's currency, as an [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code.
59
+ *
60
+ * It starts as the `currency` query param in the page URL, otherwise the site's currency, and changes when
61
+ * `setCurrency()` is called.
62
+ *
63
+ * @exampleValue 'USD'
64
+ */
65
+ readonly currency: string;
53
66
  /** @internal Host-only. Replaces config values when the host's state changes. */
54
67
  _updateConfig: (config: Partial<ILocaleServiceConfig>) => void;
55
68
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AA8DzD,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAuC,0BAA0B,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AA2EzD,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAuC,0BAA0B,CAAC,CAAA"}
@@ -7,6 +7,7 @@ export const LocaleService = implementService(LocaleDefinition, ({ config, getSe
7
7
  const _direction = signal(config.direction);
8
8
  const _locale = signal(config.locale);
9
9
  const _timeZone = signal(config.timeZone);
10
+ const _currency = signal(config.currency);
10
11
  return {
11
12
  get language() {
12
13
  return _language.get();
@@ -20,7 +21,10 @@ export const LocaleService = implementService(LocaleDefinition, ({ config, getSe
20
21
  get timeZone() {
21
22
  return _timeZone.get();
22
23
  },
23
- _updateConfig({ language, direction, locale, timeZone }) {
24
+ get currency() {
25
+ return _currency.get();
26
+ },
27
+ _updateConfig({ language, direction, locale, timeZone, currency }) {
24
28
  if (language) {
25
29
  _language.set(language);
26
30
  }
@@ -33,6 +37,9 @@ export const LocaleService = implementService(LocaleDefinition, ({ config, getSe
33
37
  if (timeZone) {
34
38
  _timeZone.set(timeZone);
35
39
  }
40
+ if (currency) {
41
+ _currency.set(currency);
42
+ }
36
43
  },
37
44
  };
38
45
  });
@@ -1 +1 @@
1
- {"version":3,"file":"localeService.js","sourceRoot":"","sources":["../../src/implementations/localeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAE1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAC5C,gBAAgB,EAChB,CAAC,EAAE,MAAM,EAAE,UAAU,EAA4C,EAAkB,EAAE;IACpF,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,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AAQ,EAAE,CAAC;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACxB,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC,CACD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/site-service-locale",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "falconPackageHash": "48cd6e8710cf26f68e8e2334c8f9ce7fdbd82d48d3d6a71f9d869965"
80
+ "falconPackageHash": "dfd49cb2dff85599b433e0a868e32e05f1f095bb90efeacbf13929e5"
81
81
  }
@@ -7,18 +7,22 @@ export type ILocaleServiceConfig = {
7
7
  direction: LanguageDirection
8
8
  locale: string
9
9
  timeZone: string
10
+ currency: string
10
11
  }
11
12
 
12
13
  /**
13
- * Reports the site's language, text direction, regional format, and time zone, so code running on the
14
- * site can format and lay out content to match the site's settings.
14
+ * Reports the site visitor's language, regional format, and currency, and the site's text direction and time
15
+ * zone, so code running on the site can format and lay out content for the site visitor.
16
+ *
17
+ * The language, regional format, and currency come from the host's common config. They can change while the
18
+ * page is open, through the setters in `@wix/site-service-renderer-configuration`.
15
19
  */
16
20
  export interface ILocaleService {
17
21
  /**
18
- * Site's main language, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
22
+ * Language the site visitor sees, as a 2-letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code.
19
23
  *
20
24
  * On a site with [Wix Multilingual](https://support.wix.com/en/article/wix-multilingual-an-overview),
21
- * this is the main language, even when a site visitor views the site in another language.
25
+ * this is the language the site visitor views, and it changes when `setLanguage()` is called.
22
26
  *
23
27
  * The code has no region, so formatting dates and numbers with it alone loses regional conventions.
24
28
  * Use `locale` for formatting.
@@ -35,11 +39,11 @@ export interface ILocaleService {
35
39
  */
36
40
  readonly direction: LanguageDirection
37
41
  /**
38
- * Site's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
42
+ * Site visitor's regional format, as a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
39
43
  *
40
- * It's the site's setting, not the site visitor's browser language. Specify it as the locale for
41
- * `Intl` date and number formatting, so dates and numbers follow the site's conventions for every
42
- * site visitor.
44
+ * It starts as the regional format of the language the site visitor views, and changes when `setLocale()` is
45
+ * called. It's not the site visitor's browser language. Specify it as the locale for `Intl` date and number
46
+ * formatting.
43
47
  *
44
48
  * @exampleValue 'en-US'
45
49
  */
@@ -53,6 +57,15 @@ export interface ILocaleService {
53
57
  * @exampleValue 'America/New_York'
54
58
  */
55
59
  readonly timeZone: string
60
+ /**
61
+ * Site visitor's currency, as an [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code.
62
+ *
63
+ * It starts as the `currency` query param in the page URL, otherwise the site's currency, and changes when
64
+ * `setCurrency()` is called.
65
+ *
66
+ * @exampleValue 'USD'
67
+ */
68
+ readonly currency: string
56
69
  /** @internal Host-only. Replaces config values when the host's state changes. */
57
70
  _updateConfig: (config: Partial<ILocaleServiceConfig>) => void
58
71
  }
@@ -12,6 +12,7 @@ export const LocaleService = implementService(
12
12
  const _direction = signal(config.direction)
13
13
  const _locale = signal(config.locale)
14
14
  const _timeZone = signal(config.timeZone)
15
+ const _currency = signal(config.currency)
15
16
 
16
17
  return {
17
18
  get language() {
@@ -26,7 +27,10 @@ export const LocaleService = implementService(
26
27
  get timeZone() {
27
28
  return _timeZone.get()
28
29
  },
29
- _updateConfig({ language, direction, locale, timeZone }: Partial<ILocaleServiceConfig>) {
30
+ get currency() {
31
+ return _currency.get()
32
+ },
33
+ _updateConfig({ language, direction, locale, timeZone, currency }: Partial<ILocaleServiceConfig>) {
30
34
  if (language) {
31
35
  _language.set(language)
32
36
  }
@@ -39,6 +43,9 @@ export const LocaleService = implementService(
39
43
  if (timeZone) {
40
44
  _timeZone.set(timeZone)
41
45
  }
46
+ if (currency) {
47
+ _currency.set(currency)
48
+ }
42
49
  },
43
50
  }
44
51
  }