{"_id":"@andersoncustodio/i18n","_rev":"3-63504b7c180b372a578cc6a3618a4100","name":"@andersoncustodio/i18n","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"@andersoncustodio/i18n","version":"0.1.0","keywords":["i18n","internationalization","localization","translate","l10n"],"author":{"name":"Anderson Custódio","email":"npmjs@andersoncustodio.com"},"license":"MIT","_id":"@andersoncustodio/i18n@0.1.0","maintainers":[{"name":"andersoncustodio","email":"contato@andersoncustodio.com"}],"homepage":"https://github.com/andersoncustodio/i18n#readme","bugs":{"url":"https://github.com/andersoncustodio/i18n/issues"},"dist":{"shasum":"1fd5d41e47bbfcd1e4462550d89139b034690ec7","tarball":"https://registry.npmjs.org/@andersoncustodio/i18n/-/i18n-0.1.0.tgz","fileCount":6,"integrity":"sha512-wOR3zVpkKYIKET45CNr4xOlC3PBDIWefa5iKu27Q5n0e0dBtde6l20GzYdWC5VgMMRF3xPcCZPygDDTJ+cqdOg==","signatures":[{"sig":"MEYCIQCZrI2Lv98ZNaibCdegCFIIKcaZSvx5d06bVoStcPPosQIhAPTyVXlrDIauIRzNgyHdW5q6ELfcwBYVaOiV/f0gtFSH","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12901},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"gitHead":"17ca8fab04f5bd391b9d9f03ee07a587c77063a2","scripts":{"test":"node index.test.js"},"_npmUser":{"name":"andersoncustodio","email":"contato@andersoncustodio.com"},"repository":{"url":"git+https://github.com/andersoncustodio/i18n.git","type":"git"},"_npmVersion":"10.8.2","description":"Lightweight i18n library with interpolation and pluralization","directories":{},"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/i18n_0.1.0_1764483434356_0.9941458833754377","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@andersoncustodio/i18n","version":"0.2.1","keywords":["i18n","internationalization","localization","translate","l10n"],"author":{"name":"Anderson Custódio","email":"npmjs@andersoncustodio.com"},"license":"MIT","_id":"@andersoncustodio/i18n@0.2.1","maintainers":[{"name":"andersoncustodio","email":"contato@andersoncustodio.com"}],"homepage":"https://github.com/andersoncustodio/i18n#readme","bugs":{"url":"https://github.com/andersoncustodio/i18n/issues"},"dist":{"shasum":"b26fe151085ee9c2d44e283940efbdf58bdc82c1","tarball":"https://registry.npmjs.org/@andersoncustodio/i18n/-/i18n-0.2.1.tgz","fileCount":6,"integrity":"sha512-gipnnpSfu12xju0N8MDS8JvYMqrzLMiOsgO7Cmj10K84Og8tFoOfurPJmIbbV8byjQtJ8Ie6seZVtSc9UWwXsg==","signatures":[{"sig":"MEYCIQDUmUEP1FPameSehMbvAdgbtuWSojm2pT+kSgbNNQFRmQIhAJdPxiM1RZWebqhvybgMHsKHN6S1ZLHziAR+V7l3RK8h","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15433},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"gitHead":"027305d424e2362394c6947cb4ee5608d634d31a","scripts":{"test":"node index.test.js"},"_npmUser":{"name":"andersoncustodio","email":"contato@andersoncustodio.com"},"repository":{"url":"git+https://github.com/andersoncustodio/i18n.git","type":"git"},"_npmVersion":"10.8.2","description":"Lightweight i18n library with interpolation and pluralization","directories":{},"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/i18n_0.2.1_1768636210095_0.1299782893496917","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@andersoncustodio/i18n","version":"1.0.0","description":"Lightweight i18n library with interpolation and pluralization","main":"index.js","types":"index.d.ts","scripts":{"test":"node index.test.js"},"repository":{"type":"git","url":"git+https://github.com/andersoncustodio/i18n.git"},"keywords":["i18n","internationalization","localization","translate","l10n"],"engines":{"node":">=14"},"author":{"name":"Anderson Custódio","email":"npmjs@andersoncustodio.com"},"license":"MIT","_id":"@andersoncustodio/i18n@1.0.0","gitHead":"29f8b2611bf891094dfdcf7ad1521ef138ec0f6a","bugs":{"url":"https://github.com/andersoncustodio/i18n/issues"},"homepage":"https://github.com/andersoncustodio/i18n#readme","_nodeVersion":"20.18.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-7CnrN16qa17SyMZgLfI/Qr3PjZl5R2MKB6RmFK1UBzYPy1V5kd1FO8qd8n1nJq6xWrD8foCCOrdULg8Nldjxwg==","shasum":"fd4ffc0da6ea10c2df35c88a3aa82c829fb88267","tarball":"https://registry.npmjs.org/@andersoncustodio/i18n/-/i18n-1.0.0.tgz","fileCount":8,"unpackedSize":19067,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDmUV+UK6b927TTGIdqiDHW1VL0JkCb6paM0bYyMGxeEQIgAbcWB0YaCD1tjyAkx8AtG8yOhVg4y+zsyUaoCEpzqys="}]},"_npmUser":{"name":"andersoncustodio","email":"contato@andersoncustodio.com"},"directories":{},"maintainers":[{"name":"andersoncustodio","email":"contato@andersoncustodio.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/i18n_1.0.0_1768740254638_0.449973024381924"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-30T06:17:14.294Z","modified":"2026-01-18T12:44:14.892Z","0.1.0":"2025-11-30T06:17:14.546Z","0.2.1":"2026-01-17T07:50:10.250Z","1.0.0":"2026-01-18T12:44:14.765Z"},"bugs":{"url":"https://github.com/andersoncustodio/i18n/issues"},"author":{"name":"Anderson Custódio","email":"npmjs@andersoncustodio.com"},"license":"MIT","homepage":"https://github.com/andersoncustodio/i18n#readme","keywords":["i18n","internationalization","localization","translate","l10n"],"repository":{"type":"git","url":"git+https://github.com/andersoncustodio/i18n.git"},"description":"Lightweight i18n library with interpolation and pluralization","maintainers":[{"name":"andersoncustodio","email":"contato@andersoncustodio.com"}],"readme":"# @andersoncustodio/i18n\n\nLightweight internationalization (i18n) library with:\n\n- Variable interpolation (`{{name}}`)\n- CLDR plural rules (`zero | one | two | few | many | other`)\n- Locale and missing key fallbacks\n- PluralRules caching for performance\n- Zero dependencies (uses native `Intl.PluralRules`)\n\n## Installation\n\n```bash\nnpm install @andersoncustodio/i18n\n```\n\nRequires Node >= 14.\n\n## Basic Usage\n\n```js\nconst { I18n } = require('@andersoncustodio/i18n');\n\nconst locales = {\n    en: {\n        greeting: 'Hello, {{name}}!',\n        items: { zero: 'No items', one: 'One item', other: '{{count}} items' }\n    },\n    pt: {\n        greeting: 'Olá, {{name}}!',\n        items: { zero: 'Nenhum item', one: 'Um item', other: '{{count}} itens' }\n    }\n};\n\nconst i18n = new I18n(locales, () => 'en');\n\ni18n.t('greeting', { name: 'João' });     // Hello, João!\ni18n.t('items', { count: 0 });            // No items\ni18n.t('items', { count: 1 });            // One item\ni18n.t('items', { count: 5 });            // 5 items\n```\n\n## Pluralization\n\nUses `Intl.PluralRules` to determine the correct plural category based on locale and count.\n\n### CLDR Categories\n\n| Category | Description | Example languages |\n|----------|-------------|-------------------|\n| `zero` | Zero quantity | Arabic |\n| `one` | Singular | English, Portuguese, Russian |\n| `two` | Dual | Arabic |\n| `few` | Few items | Russian (2-4), Arabic (3-10) |\n| `many` | Many items | Russian (5-20), Arabic (11-99) |\n| `other` | Default/fallback | All languages |\n\n### Russian Example\n\n```js\nconst ru = {\n    items: {\n        one: '{{count}} предмет',      // 1, 21, 31...\n        few: '{{count}} предмета',     // 2-4, 22-24...\n        many: '{{count}} предметов',   // 0, 5-20, 25-30...\n        other: '{{count}} предмета'\n    }\n};\n\nconst i18n = new I18n({ ru }, () => 'ru', { defaultLocale: 'ru' });\n\ni18n.t('items', { count: 1 });   // 1 предмет\ni18n.t('items', { count: 2 });   // 2 предмета\ni18n.t('items', { count: 5 });   // 5 предметов\ni18n.t('items', { count: 21 });  // 21 предмет\n```\n\n### Arabic Example\n\n```js\nconst ar = {\n    items: {\n        // 0\n        zero: 'لا عناصر',\n        // 1\n        one: 'عنصر واحد',\n        // 2\n        two: 'عنصران',\n        // 3-10\n        few: '{{count}} عناصر',\n        // 11-99\n        many: '{{count}} عنصراً',\n        // 100+\n        other: '{{count}} عنصر'\n    }\n};\n\nconst i18n = new I18n({ ar }, () => 'ar', { defaultLocale: 'ar' });\n\ni18n.t('items', { count: 0 });   // 'لا عناصر'\ni18n.t('items', { count: 2 });   // 'عنصران'\ni18n.t('items', { count: 11 });  // '11 عنصراً'\n```\n\n### Fallbacks\n\n- Missing category falls back to `other`\n- Explicit `zero` key is used when `count === 0`, even if the language doesn't have a grammatical zero (like English)\n\n## Interpolation\n\nStrings with `{{variable}}` are replaced with values from options:\n\n```js\ni18n.t('greeting', { name: 'World' });  // Hello, World!\ni18n.t('greeting');                     // Hello, {{name}}!\n```\n\n## API\n\n```ts\nnew I18n(locales, getLocale?, options?)\n```\n\n- `locales` - Object with locale translations\n- `getLocale` - Function returning current locale\n- `options.defaultLocale` - Fallback locale (default: `'en'`)\n\n### Methods\n\n- `t(keyPath, options?)` - Translate a key\n  - `options.count` - Number for pluralization\n  - `options.*` - Variables for interpolation\n\n### Getters\n\n- `locale` - Current active locale\n- `locales` - Array of available locales\n\n## AsyncLocalStorage Example\n\n```js\nconst { AsyncLocalStorage } = require('node:async_hooks');\nconst { I18n } = require('@andersoncustodio/i18n');\n\nconst storage = new AsyncLocalStorage();\nconst i18n = new I18n(locales, () => storage.getStore()?.locale);\n\nstorage.run({ locale: 'pt' }, () => {\n    console.log(i18n.t('greeting', { name: 'Maria' }));\n});\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}