@quietui/squeak 1.1.0 → 3.0.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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ - [breaking] Improved translation file format so args are named instead of order-based
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  - Added support for SSR environments
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Squeak is a tiny, zero-dependency library that provides a [Reactive Controller](https://lit.dev/docs/composition/controllers/) for localizing terms, dates, and numbers, and currency across one or more custom elements in a component library. It _does not_ aim to replicate a full-blown localization tool. For that, you should use something like [i18next](https://www.i18next.com/).
4
4
 
5
- Reactive Controllers are supported by Lit out of the box, but they're designed to be generic so other libraries can elect to support them either natively or through an adapter. If you're favorite custom element authoring library doesn't support Reactive Controllers yet, consider asking the maintainers to add support for them!
5
+ Reactive Controllers are supported by Lit out of the box, but they're designed to be generic so other libraries can elect to support them either natively or through an adapter. If your favorite custom element authoring library doesn't support Reactive Controllers yet, consider asking the maintainers to add support for them!
6
6
 
7
7
  ## Overview
8
8
 
@@ -175,9 +175,9 @@ async function changeLanguage(lang) {
175
175
  You can use Squeak with any library that supports [Lit's Reactive Controller pattern](https://lit.dev/docs/composition/controllers/). In Lit, a localized custom element will look something like this.
176
176
 
177
177
  ```ts
178
- import { LitElement } from 'lit';
179
- import { customElement } from 'lit/decorators.js';
180
- import { Localize } from '@quietui/squeak/dist/lit.js';
178
+ import { LitElement, html } from 'lit';
179
+ import { customElement, property } from 'lit/decorators.js';
180
+ import { Localize } from '@quietui/squeak/dist/index.js';
181
181
 
182
182
  @customElement('my-element')
183
183
  export class MyElement extends LitElement {
package/cspell.json ADDED
@@ -0,0 +1,18 @@
1
+ // cSpell Settings
2
+ {
3
+ // Version of the setting file. Always 0.2
4
+ "version": "0.2",
5
+ // language - current active spelling language
6
+ "language": "en,lorem",
7
+ // words - list of words to be always considered correct
8
+ "words": [
9
+ "claviska",
10
+ "Español",
11
+ "LaViska",
12
+ "quietui"
13
+ ],
14
+ // flagWords - list of words to be always considered incorrect
15
+ // This is useful for offensive words and common spelling errors.
16
+ // For example "hte" should be "the"
17
+ "flagWords": []
18
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
- export type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];
2
+ export type FunctionParams<T> = T extends (params: infer P) => string ? [P] : [];
3
3
  export interface Translation {
4
4
  $code: string;
5
5
  $name: string;
package/dist/index.js CHANGED
@@ -94,7 +94,13 @@ export class Localize {
94
94
  return String(key);
95
95
  }
96
96
  if (typeof term === 'function') {
97
- return term(...args);
97
+ try {
98
+ return term(args[0]);
99
+ }
100
+ catch (_a) {
101
+ console.warn(`Translation term "${String(key)}" threw an error. Make sure all required parameters are provided.`);
102
+ return String(key);
103
+ }
98
104
  }
99
105
  return term;
100
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quietui/squeak",
3
- "version": "1.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "A tiny, zero-dependency library that provides a Reactive Controller for localizing terms, dates, and numbers, and currency across one or more custom elements in a component library.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -9,9 +9,10 @@
9
9
  "scripts": {
10
10
  "start": "tsc -w",
11
11
  "build": "tsc",
12
- "clean": "node ./scripts/clean.js",
12
+ "clean": "rimraf dist",
13
13
  "prebuild": "npm run clean",
14
- "prepublishOnly": "npm run build"
14
+ "prepublishOnly": "npm run build",
15
+ "check-updates": "npx npm-check-updates --interactive --format group"
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",
@@ -35,6 +36,7 @@
35
36
  "del": "^7.1.0",
36
37
  "lit": "^3.1.2",
37
38
  "prettier": "^3.2.5",
39
+ "rimraf": "^6.0.1",
38
40
  "typescript": "^5.3.3"
39
41
  }
40
42
  }
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 : [];
3
+ export type FunctionParams<T> = T extends (params: infer P) => string ? [P] : [];
4
4
 
5
5
  export interface Translation {
6
6
  $code: string; // e.g. en, en-GB
@@ -170,7 +170,12 @@ export class Localize<UserTranslation extends Translation> implements ReactiveCo
170
170
  }
171
171
 
172
172
  if (typeof term === 'function') {
173
- return term(...args) as string;
173
+ try {
174
+ return term(args[0]) as string;
175
+ } catch {
176
+ console.warn(`Translation term "${String(key)}" threw an error. Make sure all required parameters are provided.`);
177
+ return String(key);
178
+ }
174
179
  }
175
180
 
176
181
  return term;
package/scripts/clean.js DELETED
@@ -1,3 +0,0 @@
1
- import { deleteSync } from 'del';
2
-
3
- deleteSync('./dist');