@wix/site-service-locale 1.0.10 → 1.0.12
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 +8 -3
- package/cjs/build/definition/index.d.ts +21 -8
- package/cjs/build/definition/index.js.map +1 -1
- package/cjs/build/implementations/localeService.js +8 -1
- package/cjs/build/implementations/localeService.js.map +1 -1
- package/cjs/build/index.js +3 -16
- package/cjs/build/index.js.map +1 -1
- package/dist/definition/index.d.ts +21 -8
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/localeService.js +8 -1
- package/dist/implementations/localeService.js.map +1 -1
- package/package.json +17 -7
- package/src/definition/index.ts +21 -8
- package/src/implementations/localeService.ts +8 -1
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
|
|
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 |
|
|
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
|
|
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,
|
|
11
|
-
* site can format and lay out content
|
|
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
|
-
*
|
|
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
|
|
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
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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;
|
|
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
|
-
|
|
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,CA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,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,IAAI,QAAQ;YACX,OAAO,SAAS,CAAC,GAAG,EAAE,CAAA;QACvB,CAAC;QACD,aAAa,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,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"}
|
package/cjs/build/index.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./definition"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./implementations"), exports);
|
|
19
6
|
//# sourceMappingURL=index.js.map
|
package/cjs/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,4DAAiC"}
|
|
@@ -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,
|
|
11
|
-
* site can format and lay out content
|
|
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
|
-
*
|
|
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
|
|
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
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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;
|
|
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
|
-
|
|
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,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;
|
|
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,iDA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I,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-service-locale",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -48,18 +48,29 @@
|
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc -b . && tsc --project tsconfig.cjs.json",
|
|
51
|
-
"lint": "pnpm --workspace-root run lint:package --package $npm_package_name",
|
|
52
51
|
"test": "vitest --run && pnpm run test-type-check",
|
|
53
52
|
"test-type-check": "echo 'validating typescript in test files' && tsc --project tsconfig.test.json && echo 'Finished validating typescript in test files successfully'"
|
|
54
53
|
},
|
|
55
54
|
"dependencies": {
|
|
56
|
-
"@wix/services-definitions": "^0.
|
|
57
|
-
"@wix/services-manager": "^0.
|
|
55
|
+
"@wix/services-definitions": "^1.0.5",
|
|
56
|
+
"@wix/services-manager": "^1.0.7",
|
|
57
|
+
"tslib": "^2.8.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"typescript": "~7.0.2",
|
|
61
61
|
"vitest": "4.1.11"
|
|
62
62
|
},
|
|
63
|
+
"nx": {
|
|
64
|
+
"targets": {
|
|
65
|
+
"build": {
|
|
66
|
+
"outputs": [
|
|
67
|
+
"{projectRoot}/dist/**/*",
|
|
68
|
+
"{projectRoot}/cjs/build/**/*",
|
|
69
|
+
"{projectRoot}/*.tsbuildinfo"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
63
74
|
"publishUnscoped": false,
|
|
64
75
|
"wix": {
|
|
65
76
|
"artifact": {
|
|
@@ -72,10 +83,9 @@
|
|
|
72
83
|
},
|
|
73
84
|
"validations": {
|
|
74
85
|
"postBuild": [
|
|
75
|
-
"test"
|
|
76
|
-
"lint"
|
|
86
|
+
"test"
|
|
77
87
|
]
|
|
78
88
|
}
|
|
79
89
|
},
|
|
80
|
-
"falconPackageHash": "
|
|
90
|
+
"falconPackageHash": "31593293bd1952df270c72a6cc2706731d66a8824ddf875119ba5bc6"
|
|
81
91
|
}
|
package/src/definition/index.ts
CHANGED
|
@@ -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,
|
|
14
|
-
* site can format and lay out content
|
|
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
|
-
*
|
|
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
|
|
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
|
|
41
|
-
*
|
|
42
|
-
*
|
|
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
|
-
|
|
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
|
}
|