@shoelace-style/localize 3.1.0 → 3.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.1.2
4
+
5
+ - Fixed a bug that caused underscores in locale identifiers to throw a `RangeError`
6
+
7
+ ## 3.1.1
8
+
9
+ - Upgraded TypeScript to 5.1.3
10
+
3
11
  ## 3.1.0
4
12
 
5
13
  - Added `exists()` method to determine if a term and/or a fallback term exists [#17](https://github.com/shoelace-style/localize/issues/17)
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
- export declare type FunctionParams<T> = T extends (...args: infer U) => string ? U : never;
2
+ export type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];
3
3
  export interface Translation {
4
4
  $code: string;
5
5
  $name: string;
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ export class LocalizeController {
51
51
  }
52
52
  getTranslationData(lang) {
53
53
  var _a, _b;
54
- const locale = new Intl.Locale(lang);
54
+ const locale = new Intl.Locale(lang.replace(/_/g, '-'));
55
55
  const language = locale === null || locale === void 0 ? void 0 : locale.language.toLowerCase();
56
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
57
  const primary = translations.get(`${language}-${region}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoelace-style/localize",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "A micro library for localizing custom elements using Lit's Reactive Controller model.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -35,6 +35,6 @@
35
35
  "devDependencies": {
36
36
  "del": "^6.0.0",
37
37
  "lit": "^2.0.2",
38
- "typescript": "4.8.4"
38
+ "typescript": "^5.1.3"
39
39
  }
40
40
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { LitElement, ReactiveController, ReactiveControllerHost } from 'lit';
2
2
 
3
- export type FunctionParams<T> = T extends (...args: infer U) => string ? U : never;
3
+ export type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];
4
4
 
5
5
  export interface Translation {
6
6
  $code: string; // e.g. en, en-GB
@@ -117,7 +117,9 @@ export class LocalizeController<UserTranslation extends Translation = DefaultTra
117
117
  }
118
118
 
119
119
  private getTranslationData(lang: string) {
120
- const locale = new Intl.Locale(lang);
120
+ // Convert "en_US" to "en-US". Note that both underscores and dashes are allowed per spec, but underscores result in
121
+ // a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier
122
+ const locale = new Intl.Locale(lang.replace(/_/g, '-'));
121
123
  const language = locale?.language.toLowerCase();
122
124
  const region = locale?.region?.toLowerCase() ?? '';
123
125
  const primary = <UserTranslation>translations.get(`${language}-${region}`);