{"_id":"@appinventiv/locale","_rev":"2-9e66f738ce31d9b06010189700c5ca38","name":"@appinventiv/locale","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@appinventiv/locale","version":"1.0.0","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/locale@1.0.0","maintainers":[{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"05956a59399764a7e30e76c7ff3a8c0ed406d8b9","tarball":"https://registry.npmjs.org/@appinventiv/locale/-/locale-1.0.0.tgz","fileCount":16,"integrity":"sha512-8wNpUm1PKo7BmxWN7gKOfINkU8Qw3hx7Q5f/7JEOex50ZceIYi4RUtneasj7T5arveCoUKhLjW5yDF/mUKlGmg==","signatures":[{"sig":"MEYCIQD27X9hXRDJAHYdvAlDzQzJ6pXwludKyCRFdNA2i6PAXAIhAKmG40UNvQbBx3McpMnN3akazfnIv0BpigYXMntGcxkP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":49204},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"A lightweight locale management package for Node.js applications that provides easy translation functionality by loading locale files from a directory.","directories":{},"_nodeVersion":"22.19.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9"},"_npmOperationalInternal":{"tmp":"tmp/locale_1.0.0_1769313960605_0.1351514870491084","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-01-25T04:06:00.446Z","modified":"2026-01-25T04:07:32.817Z","1.0.0":"2026-01-25T04:06:00.749Z"},"license":"ISC","keywords":[],"description":"A lightweight locale management package for Node.js applications that provides easy translation functionality by loading locale files from a directory.","maintainers":[{"email":"abhishektyagi199816@gmail.com","name":"developer-at"},{"email":"abhishek.tyagi1@appinventiv.com","name":"abhishek.tyagi1"}],"readme":"# @developer-at/locale\n\nA lightweight locale management package for Node.js applications that provides easy translation functionality by loading locale files from a directory.\n\n## Installation\n\n```bash\nnpm install @developer-at/locale\n```\n\n## Features\n\n- Load locale files from a directory\n- Support for multiple languages\n- Simple translation API\n- TypeScript support\n\n## Supported Languages\n\nThe package supports the following language codes:\n- `en` - English\n- `mn` - Mongolian\n- `ru` - Russian\n- `hi` - Hindi\n- `es` - Spanish\n- `fr` - French\n- `de` - German\n- `it` - Italian\n- `ja` - Japanese\n- `ko` - Korean\n- `pt` - Portuguese\n- `zh` - Chinese\n- `ar` - Arabic\n- `he` - Hebrew\n\n## Usage\n\n### Basic Setup\n\n1. Create a directory with your locale JSON files:\n\n```\nlocales/\n  ├── en.json\n  ├── fr.json\n  ├── es.json\n  └── ...\n```\n\n2. Example locale file (`en.json`):\n\n```json\n{\n  \"welcome\": \"Welcome\",\n  \"greeting\": \"Hello, {name}!\",\n  \"errors\": {\n    \"notFound\": \"Resource not found\",\n    \"unauthorized\": \"Unauthorized access\"\n  }\n}\n```\n\n3. Initialize and use in your code:\n\n```typescript\nimport { locales } from '@developer-at/locale';\nimport { join } from 'path';\n\n// Initialize locales from directory\nlocales.initaliseLocale(join(__dirname, 'locales'));\n\n// Translate a key\nconst welcomeMessage = locales.translate('welcome', 'en');\nconsole.log(welcomeMessage); // \"Welcome\"\n\n// Use default language (English)\nconst greeting = locales.translate('greeting', 'en');\nconsole.log(greeting); // \"Hello, {name}!\"\n\n// Translate with different language\nconst welcomeFr = locales.translate('welcome', 'fr');\nconsole.log(welcomeFr); // \"Bienvenue\" (if fr.json exists)\n\n// Nested keys\nconst errorMsg = locales.translate('errors.notFound', 'en');\nconsole.log(errorMsg); // \"Resource not found\"\n```\n\n### API Reference\n\n#### `initaliseLocale(dir: string)`\n\nInitializes and loads all locale JSON files from the specified directory.\n\n**Parameters:**\n- `dir` (string): Path to the directory containing locale JSON files\n\n**Example:**\n```typescript\nlocales.initaliseLocale('./locales');\n```\n\n#### `translate(key: string, lang: Lang = 'en')`\n\nTranslates a key to the specified language.\n\n**Parameters:**\n- `key` (string): Translation key to look up (supports dot notation for nested keys)\n- `lang` (Lang): Language code (default: 'en')\n\n**Returns:**\n- `string | undefined`: Translated string or undefined if key/language not found\n\n**Example:**\n```typescript\n// Simple key\nconst msg = locales.translate('welcome', 'en');\n\n// Nested key\nconst error = locales.translate('errors.notFound', 'en');\n\n// Default language\nconst defaultMsg = locales.translate('welcome');\n```\n\n## TypeScript Support\n\nThe package includes TypeScript definitions. Import the `Lang` type for type-safe language codes:\n\n```typescript\nimport { locales, Lang } from '@developer-at/locale';\n\nconst lang: Lang = 'fr';\nconst message = locales.translate('welcome', lang);\n```\n\n## Notes\n\n- Locale files must be in JSON format\n- File names should match the language code (e.g., `en.json`, `fr.json`)\n- The package automatically loads all `.json` files from the specified directory\n- If a translation key or language is not found, `undefined` is returned\n- Nested keys are supported using dot notation (e.g., `errors.notFound`)\n\n## License\n\nISC\n","readmeFilename":"README.md"}