@shoelace-style/localize 3.0.0 → 3.0.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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.2
4
+
5
+ - Fixed a parsing bug in extended language codes [#16](https://github.com/shoelace-style/localize/issues/16)
6
+ - Updated TypeScript to 4.8.4
7
+
8
+ ## 3.0.1
9
+
10
+ - Fixed module paths in `package.json`
11
+
3
12
  ## 3.0.0
4
13
 
5
14
  - 🚨BREAKING: Removed top level `term()`, `date()`, `number()`, and `relativeTime()` functions
package/README.md CHANGED
@@ -176,7 +176,8 @@ import { LocalizeController } from '@shoelace-style/localize/dist/lit.js';
176
176
  export class MyElement extends LitElement {
177
177
  private localize = new LocalizeController(this);
178
178
 
179
- // Make sure to define `lang` so the component will respond to changes to its own lang attribute
179
+ // Make sure to make `dir` and `lang` reactive so the component will respond to changes to its own attributes
180
+ @property() dir: string;
180
181
  @property() lang: string;
181
182
 
182
183
  render() {
package/dist/index.js CHANGED
@@ -50,10 +50,12 @@ export class LocalizeController {
50
50
  return `${this.host.lang || documentLanguage}`.toLowerCase();
51
51
  }
52
52
  term(key, ...args) {
53
- const code = this.lang().toLowerCase().slice(0, 2);
54
- const regionCode = this.lang().length > 2 ? this.lang().toLowerCase() : '';
55
- const primary = translations.get(regionCode);
56
- const secondary = translations.get(code);
53
+ var _a, _b;
54
+ const locale = new Intl.Locale(this.lang());
55
+ const language = locale === null || locale === void 0 ? void 0 : locale.language.toLowerCase();
56
+ const region = (_b = (_a = locale === null || locale === void 0 ? void 0 : locale.region) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
57
+ const primary = translations.get(region);
58
+ const secondary = translations.get(language);
57
59
  let term;
58
60
  if (primary && primary[key]) {
59
61
  term = primary[key];
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@shoelace-style/localize",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A micro library for localizing custom elements using Lit's Reactive Controller model.",
5
- "main": "/dist/index.js",
6
- "module": "/dist/index.js",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
7
  "type": "module",
8
8
  "types": "dist/index.d.ts",
9
9
  "scripts": {
@@ -35,6 +35,6 @@
35
35
  "devDependencies": {
36
36
  "del": "^6.0.0",
37
37
  "lit": "^2.0.2",
38
- "typescript": "^4.4.3"
38
+ "typescript": "4.8.4"
39
39
  }
40
40
  }
package/src/index.ts CHANGED
@@ -116,10 +116,11 @@ export class LocalizeController<UserTranslation extends Translation = DefaultTra
116
116
  }
117
117
 
118
118
  term<K extends keyof UserTranslation>(key: K, ...args: FunctionParams<UserTranslation[K]>) {
119
- const code = this.lang().toLowerCase().slice(0, 2); // e.g. en
120
- const regionCode = this.lang().length > 2 ? this.lang().toLowerCase() : ''; // e.g. en-gb
121
- const primary = <UserTranslation>translations.get(regionCode);
122
- const secondary = <UserTranslation>translations.get(code);
119
+ const locale = new Intl.Locale(this.lang());
120
+ const language = locale?.language.toLowerCase();
121
+ const region = locale?.region?.toLowerCase() ?? '';
122
+ const primary = <UserTranslation>translations.get(region);
123
+ const secondary = <UserTranslation>translations.get(language);
123
124
  let term: any;
124
125
 
125
126
  // Look for a matching term using regionCode, code, then the fallback