@joralvmel/cosmos-i18n 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/llms.md +21 -0
- package/package.json +42 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jorge Andrés Álvarez Melchor (joralvmel)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @joralvmel/cosmos-i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internationalization for [Cosmos UI](../../README.md).
|
|
4
|
+
|
|
5
|
+
> Status: early development. The API below is the current skeleton.
|
|
6
|
+
|
|
7
|
+
Message formatting with `{name}` arguments and `Intl` helpers.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createTranslator } from '@joralvmel/cosmos-i18n';
|
|
11
|
+
|
|
12
|
+
const t = createTranslator('es', { greeting: 'Hola, {name}' });
|
|
13
|
+
t.t('greeting', { name: 'Ada' }); // 'Hola, Ada'
|
|
14
|
+
t.list(['a', 'b', 'c']); // 'a, b y c'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
ICU plural/select and lazy locales are planned.
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Messages = Readonly<Record<string, string>>;
|
|
2
|
+
export type Values = Readonly<Record<string, string | number | Date>>;
|
|
3
|
+
export interface Translator {
|
|
4
|
+
readonly locale: string;
|
|
5
|
+
/** Formats a message: `{name}` arguments, numbers and dates formatted with `Intl`. */
|
|
6
|
+
t(key: string, values?: Values): string;
|
|
7
|
+
number(value: number, options?: Intl.NumberFormatOptions): string;
|
|
8
|
+
date(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
9
|
+
list(values: readonly string[], options?: Intl.ListFormatOptions): string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a translator for one locale. Missing keys fall back to `fallback` messages and then
|
|
13
|
+
* to the key itself, so the UI never shows `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createTranslator(locale: string, messages: Messages, fallback?: Messages): Translator;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,MAAM,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAEtE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sFAAsF;IACtF,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IAClE,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;IACzE,IAAI,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;CAC3E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,GAAE,QAAa,GACtB,UAAU,CAsBZ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a translator for one locale. Missing keys fall back to `fallback` messages and then
|
|
3
|
+
* to the key itself, so the UI never shows `undefined`.
|
|
4
|
+
*/
|
|
5
|
+
export function createTranslator(locale, messages, fallback = {}) {
|
|
6
|
+
const numberFormat = (options) => new Intl.NumberFormat(locale, options);
|
|
7
|
+
const format = (value) => typeof value === 'number'
|
|
8
|
+
? numberFormat().format(value)
|
|
9
|
+
: value instanceof Date
|
|
10
|
+
? new Intl.DateTimeFormat(locale).format(value)
|
|
11
|
+
: value;
|
|
12
|
+
return {
|
|
13
|
+
locale,
|
|
14
|
+
t(key, values = {}) {
|
|
15
|
+
const template = messages[key] ?? fallback[key] ?? key;
|
|
16
|
+
return template.replace(/\{(\w+)\}/g, (match, name) => Object.hasOwn(values, name) ? format(values[name]) : match);
|
|
17
|
+
},
|
|
18
|
+
number: (value, options) => numberFormat(options).format(value),
|
|
19
|
+
date: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
|
|
20
|
+
list: (values, options) => new Intl.ListFormat(locale, options).format(values),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,QAAkB,EAClB,WAAqB,EAAE;IAEvB,MAAM,YAAY,GAAG,CAAC,OAAkC,EAAE,EAAE,CAC1D,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,KAA6B,EAAE,EAAE,CAC/C,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;QAC9B,CAAC,CAAC,KAAK,YAAY,IAAI;YACrB,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC/C,CAAC,CAAC,KAAK,CAAC;IAEd,OAAO;QACL,MAAM;QACN,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE;YAChB,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvD,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE,CAC5D,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC,CAAC,CAAC,CAAC,KAAK,CACrF,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/D,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;KAC/E,CAAC;AACJ,CAAC"}
|
package/llms.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @joralvmel/cosmos-i18n
|
|
2
|
+
|
|
3
|
+
Message formatting with `{name}` arguments and `Intl` helpers: `createTranslator(locale, messages, fallback?)` → `{ t, number, date, list }`.
|
|
4
|
+
|
|
5
|
+
<!-- generated:start (npm run llms, do not edit this block by hand) -->
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @joralvmel/cosmos-i18n
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Rules for AI assistants
|
|
14
|
+
|
|
15
|
+
- Use Cosmos components before writing custom UI; check `list_components` / the component status page for what exists.
|
|
16
|
+
- Style with Cosmos tokens: `var(--cosm-*)` in CSS or the Tailwind theme utilities (`bg-primary`, `text-fg-muted`, `rounded-md`). Never hard-code colors.
|
|
17
|
+
- Set the theme and mode with `data-theme` and `data-mode` on the root element (or `CosmosThemeProvider` on React Native).
|
|
18
|
+
- Keep accessibility: give icon-only buttons a `label`, never rely on color alone, keep keyboard support.
|
|
19
|
+
- Never render untrusted HTML (`innerHTML`, `dangerouslySetInnerHTML`) and never build class names from user input.
|
|
20
|
+
|
|
21
|
+
<!-- generated:end -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joralvmel/cosmos-i18n",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cosmos UI internationalization: message formatting and Intl helpers.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18n",
|
|
7
|
+
"l10n",
|
|
8
|
+
"intl",
|
|
9
|
+
"cosmos-ui"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "joralvmel",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/joralvmel/cosmos-ui.git",
|
|
17
|
+
"directory": "packages/i18n"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"llms.md"
|
|
26
|
+
],
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./llms.md": "./llms.md",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
|
|
43
|
+
}
|
|
44
|
+
}
|