@shoelace-style/localize 3.1.1 → 3.2.0

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.2.0
4
+
5
+ - Added support for SSR environments [#25](https://github.com/shoelace-style/localize/pull/25/)
6
+
7
+ ## 3.1.2
8
+
9
+ - Fixed a bug that caused underscores in locale identifiers to throw a `RangeError`
10
+
3
11
  ## 3.1.1
4
12
 
5
13
  - Upgraded TypeScript to 5.1.3
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.1",
3
+ "version": "3.2.0",
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",
package/src/index.ts CHANGED
@@ -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}`);