locon 1.5.0 → 1.6.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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Per-call options for `l()`, `lIn()` and `<LText>`.
3
+ *
4
+ * All four are optional and independent: `params` interpolates, `count`
5
+ * selects a plural form, and `locale` renders one call in a language other
6
+ * than the current one (used when an app exports a document in a language
7
+ * the interface is not currently showing). `fallback` is returned only when
8
+ * no locale resolves the input.
9
+ */
10
+ interface TranslateOptions {
11
+ /** Values for `{token}` placeholders inside the resolved string. */
12
+ params?: Record<string, string | number>;
13
+ /** Selects `key_one` / `key_few` / `key_other` … via `Intl.PluralRules`. */
14
+ count?: number;
15
+ /** Resolve against this locale instead of the current one. */
16
+ locale?: string;
17
+ /** Human-readable fallback when no locale resolves the key/value. */
18
+ fallback?: string;
19
+ }
20
+
21
+ type Resource = Record<string, string>;
22
+ type ResourceLoader = () => Promise<Resource | {
23
+ default: Resource;
24
+ }>;
25
+ interface ResourceOptions {
26
+ loaders: Record<string, ResourceLoader>;
27
+ defaultLocale: string;
28
+ projectLocale?: string;
29
+ locale?: string | null;
30
+ /** Ordered browser/device preferences, or an explicit list in Node. */
31
+ languages?: readonly string[];
32
+ }
33
+ interface LocaleSnapshot {
34
+ currentLocale: string;
35
+ loading: boolean;
36
+ ready: boolean;
37
+ error: Error | null;
38
+ }
39
+ /** First matching preference wins; regional variants can use a base resource. */
40
+ declare function matchLocale(languages: readonly string[], supported: readonly string[], fallback: string): string;
41
+ /** A per-app/per-request store. Importing it touches neither React nor a platform API. */
42
+ declare function createLocon(options: ResourceOptions): {
43
+ locales: string[];
44
+ l: (key: string, translateOptions?: TranslateOptions) => string;
45
+ loadLocale: (locale: string) => Promise<Resource>;
46
+ setLocale: (locale: string | null) => Promise<boolean>;
47
+ getSnapshot: () => LocaleSnapshot;
48
+ subscribe(listener: () => void): () => void;
49
+ };
50
+ type LoconInstance = ReturnType<typeof createLocon>;
51
+
52
+ export { type LocaleSnapshot as L, type ResourceLoader as R, type TranslateOptions as T, type LoconInstance as a, type ResourceOptions as b, createLocon as c, matchLocale as m };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "locon",
3
- "version": "1.5.0",
4
- "description": "locon is a simple and lightweight library for React Native that provides a simple way to manage translations in your app.",
3
+ "version": "1.6.0",
4
+ "description": "Lightweight localization for React Native, React and Node with lazy locale resources.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -10,17 +10,28 @@
10
10
  "default": "./dist/index.js"
11
11
  },
12
12
  "./skills/*": "./skills/*",
13
- "./package.json": "./package.json"
13
+ "./package.json": "./package.json",
14
+ "./core": {
15
+ "types": "./dist/core.d.ts",
16
+ "import": "./dist/core.mjs",
17
+ "require": "./dist/core.js"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react.d.ts",
21
+ "import": "./dist/react.mjs",
22
+ "require": "./dist/react.js"
23
+ }
14
24
  },
15
25
  "files": [
16
26
  "dist",
17
- "skills"
27
+ "skills",
28
+ "CHANGELOG.md"
18
29
  ],
19
30
  "scripts": {
20
- "build": "tsup",
31
+ "build": "tsup && tsup --config tsup.web.config.ts",
21
32
  "lint": "eslint src",
22
- "prepare": "tsup",
23
- "pretest": "tsup",
33
+ "prepare": "npm run build",
34
+ "pretest": "npm run build",
24
35
  "test": "jest"
25
36
  },
26
37
  "keywords": [
@@ -59,6 +70,12 @@
59
70
  },
60
71
  "react-native-localize": {
61
72
  "optional": true
73
+ },
74
+ "react": {
75
+ "optional": true
76
+ },
77
+ "react-native": {
78
+ "optional": true
62
79
  }
63
80
  },
64
81
  "devDependencies": {