@nzyme/i18n-core 0.0.0-stage → 0.15.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,12 @@
1
+ /** The result of resolving a translation - a string, an array of interpolation parts, or undefined if missing. */
2
+ export type TranslationResult = string | unknown[] | undefined;
3
+ /** A translation function, optionally parameterized with interpolation params. */
4
+ export type Translation<T = void> = T extends void ? TranslationSimple : TranslationWithParams<T>;
5
+ /** A translation function that takes only a language code. */
6
+ export type TranslationSimple = (lang: string) => TranslationResult;
7
+ /** A translation function that takes a language code and interpolation parameters. */
8
+ export type TranslationWithParams<T> = (lang: string, params: T) => TranslationResult;
9
+ /** A translation function with any parameter type, useful for generic handling. */
10
+ export type TranslationAny = Translation<any>;
11
+ /** Extracts the parameter type from a translation function. */
12
+ export type TranslationParams<T extends TranslationAny> = T extends Translation<infer P> ? P : never;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Translation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Translation.js","sourceRoot":"","sources":["../src/Translation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from './pluralization.js';
2
+ export * from './pluralizationRules.js';
3
+ export * as pluralization from './pluralizationRules.js';
4
+ export * from './Translation.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './pluralization.js';
2
+ export * from './pluralizationRules.js';
3
+ export * as pluralization from './pluralizationRules.js';
4
+ export * from './Translation.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AACzD,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Pluralization function
3
+ */
4
+ export interface Pluralization<TPlural extends string = string> {
5
+ /**
6
+ * Plural types
7
+ */
8
+ plurals: TPlural[];
9
+ /**
10
+ * Optional plural types
11
+ */
12
+ optionalPlurals?: TPlural[];
13
+ /**
14
+ * @param count {number} a choice index given by the input to $tc.
15
+ * @param optionsCount {number} an overall amount of available choices
16
+ * @returns a final choice index to select plural word by
17
+ */
18
+ pluralize<T>(count: number, plurals: Partial<Record<TPlural, T>>): T | undefined;
19
+ }
20
+ /**
21
+ * Plural translation
22
+ */
23
+ export type PluralTranslation<TPluralization extends Pluralization, TParams extends object> = {
24
+ [plural in TPluralization['plurals'][number]]?: (params: TParams) => string | unknown[];
25
+ };
26
+ /**
27
+ * Define a pluralization method
28
+ * @param pluralization - Pluralization
29
+ * @returns Pluralization
30
+ * @__NO_SIDE_EFFECTS__
31
+ */
32
+ export declare function definePluralization<TPlural extends string>(pluralization: Pluralization<TPlural>): Pluralization<TPlural>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Define a pluralization method
3
+ * @param pluralization - Pluralization
4
+ * @returns Pluralization
5
+ * @__NO_SIDE_EFFECTS__
6
+ */
7
+ export function definePluralization(pluralization) {
8
+ return pluralization;
9
+ }
10
+ //# sourceMappingURL=pluralization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralization.js","sourceRoot":"","sources":["../src/pluralization.ts"],"names":[],"mappings":"AA6BA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAyB,aAAqC;IAC7F,OAAO,aAAa,CAAC;AACzB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * English pluralization
3
+ */
4
+ export declare const pluralizationEn: import("./pluralization.js").Pluralization<"many" | "one" | "zero">;
5
+ /**
6
+ * Polish pluralization
7
+ */
8
+ export declare const pluralizationPl: import("./pluralization.js").Pluralization<"few" | "many" | "one" | "zero">;
9
+ /**
10
+ * Czech pluralization
11
+ */
12
+ export declare const pluralizationCs: import("./pluralization.js").Pluralization<"few" | "many" | "one" | "zero">;
13
+ /**
14
+ * German pluralization
15
+ */
16
+ export declare const pluralizationDe: import("./pluralization.js").Pluralization<"many" | "one" | "zero">;
@@ -0,0 +1,53 @@
1
+ import { definePluralization } from './pluralization.js';
2
+ /**
3
+ * English pluralization
4
+ */
5
+ export const pluralizationEn = definePluralization({
6
+ plurals: ['many', 'one', 'zero'],
7
+ optionalPlurals: ['zero'],
8
+ pluralize: (count, plurals) => {
9
+ switch (count) {
10
+ case 0:
11
+ return plurals.zero ?? plurals.many;
12
+ case 1:
13
+ return plurals.one;
14
+ default:
15
+ return plurals.many;
16
+ }
17
+ },
18
+ });
19
+ /**
20
+ * Polish pluralization
21
+ */
22
+ export const pluralizationPl = definePluralization({
23
+ plurals: ['few', 'many', 'one', 'zero'],
24
+ optionalPlurals: ['zero'],
25
+ pluralize: (count, plurals) => {
26
+ // np: zero jabłek
27
+ if (count === 0) {
28
+ return plurals.zero ?? plurals.many ?? plurals.few;
29
+ }
30
+ // np: jedno jabłko
31
+ if (count === 1) {
32
+ return plurals.one;
33
+ }
34
+ if (count < 10 || count > 20) {
35
+ // np: 3 jabłka lub 23 jabłka
36
+ const lastDigit = count % 10;
37
+ if (lastDigit >= 2 && lastDigit <= 4) {
38
+ return plurals.few ?? plurals.many;
39
+ }
40
+ }
41
+ // np 8 jabłek
42
+ return plurals.many ?? plurals.few;
43
+ },
44
+ });
45
+ /**
46
+ * Czech pluralization
47
+ */
48
+ export const pluralizationCs = pluralizationPl;
49
+ /**
50
+ * German pluralization
51
+ */
52
+ export const pluralizationDe = pluralizationEn;
53
+ //# sourceMappingURL=pluralizationRules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralizationRules.js","sourceRoot":"","sources":["../src/pluralizationRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;IAC/C,OAAO,EAAE,CAAC,MAAM,EAA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H;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
- "name": "@nzyme/i18n-core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@nzyme/i18n-core",
3
+ "version": "0.15.0",
4
+ "description": "i18n core primitives",
5
+ "license": "MIT",
6
+ "author": "Michał Kędrzyński <m.kedrzynski@gmail.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kedrzu/nzyme.git"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./*.js": {
24
+ "types": "./dist/*.d.ts",
25
+ "import": "./dist/*.js",
26
+ "source": "./src/*.ts",
27
+ "default": "./dist/*.js"
28
+ }
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsgo --build tsconfig.esm.json",
35
+ "format": "oxfmt ./src > /dev/null"
36
+ },
37
+ "dependencies": {
38
+ "@nzyme/ioc": "0.15.0"
39
+ },
40
+ "devDependencies": {
41
+ "@nzyme/tsconfig": "0.15.0",
42
+ "@typescript/native-preview": "^7.0.0-dev.20260707.2",
43
+ "oxfmt": "0.71.0"
44
+ },
45
+ "nzyme": {
46
+ "cjs": true
47
+ }
48
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.