{"_id":"@alirezakeshvari/langjs","_rev":"1-316111027fe066aa6cb083c61e5e7ea1","name":"@alirezakeshvari/langjs","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@alirezakeshvari/langjs","version":"1.0.0","keywords":["lang","localization","multi-language"],"author":{"name":"alirezakeshvari"},"license":"MIT","_id":"@alirezakeshvari/langjs@1.0.0","maintainers":[{"name":"alirezakeshvari","email":"alireza.ksv@gmail.com"}],"homepage":"https://github.com/alirezakeshvari/langjs#readme","bugs":{"url":"https://github.com/alirezakeshvari/langjs/issues"},"dist":{"shasum":"2a2c46477590e980df7033f32d3355dfc6600f87","tarball":"https://registry.npmjs.org/@alirezakeshvari/langjs/-/langjs-1.0.0.tgz","fileCount":8,"integrity":"sha512-/yQWxhFFfCURZRsJch7/KdwjSCx87elA/8sPe6vUgYZApZzG8kjRZIx18JnWaAyfzbqxqxUcbPggcjqv6VsaMg==","signatures":[{"sig":"MEYCIQCTJ4TyUuPYssBTghSTjabRbqQjEBLctfJMnWFHLDxphAIhAMCaTKXSxv5Z5c5hS3j1+4HlqJVmbwC5cpj/YsEI3IH1","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10273},"main":"dist/app.js","gitHead":"2363cf63c01c3fbdaee509a90dbdec1221ff0c62","scripts":{"test":"jest","build":"tsc"},"_npmUser":{"name":"alirezakeshvari","email":"alireza.ksv@gmail.com"},"repository":{"url":"git+https://github.com/alirezakeshvari/langjs.git","type":"git"},"_npmVersion":"10.8.3","description":"`langjs` is a lightweight multi-language support package for TypeScript/JavaScript projects. It allows developers to define their own translation files in JSON format, switch between languages dynamically, and fetch localized strings for their application","directories":{},"_nodeVersion":"22.9.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.6.2","@types/jest":"^29.5.13","@types/node":"^22.7.4"},"_npmOperationalInternal":{"tmp":"tmp/langjs_1.0.0_1728037706885_0.1320998915256788","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@alirezakeshvari/langjs","version":"1.0.1","main":"dist/app.js","author":{"name":"alirezakeshvari"},"license":"MIT","scripts":{"test":"jest","build":"tsc"},"repository":{"type":"git","url":"git+https://github.com/alirezakeshvari/langjs.git"},"devDependencies":{"@types/jest":"^29.5.13","@types/node":"^22.7.4","jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.6.2"},"keywords":["lang","localization","multi-language"],"_id":"@alirezakeshvari/langjs@1.0.1","gitHead":"84752dd3c8788da837aac231f0d5a21108ed7fb3","description":"`langjs` is a lightweight multi-language support package for TypeScript/JavaScript projects. It allows developers to define their own translation files in JSON format, switch between languages dynamically, and fetch localized strings for their application","bugs":{"url":"https://github.com/alirezakeshvari/langjs/issues"},"homepage":"https://github.com/alirezakeshvari/langjs#readme","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-vlkibBoEee5yEEky93DORznfQGi8tyqWnIJuR+ADlCKSKY5B5txUHd9sUKPC0xjfPvaZCmV4Ow9RkXpoc8c7qQ==","shasum":"178187bf6ad83b46e61ba3dff23a7aaebaba7f06","tarball":"https://registry.npmjs.org/@alirezakeshvari/langjs/-/langjs-1.0.1.tgz","fileCount":8,"unpackedSize":10307,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE0/i5SD4Mz+1JUZMw3NqoDM6QodEqyq7TZ+aJ1LrZxtAiBCIHUcMiLWGd7MerpqmGr/6cMv2NbArySPop7czqsXOw=="}]},"_npmUser":{"name":"alirezakeshvari","email":"alireza.ksv@gmail.com"},"directories":{},"maintainers":[{"name":"alirezakeshvari","email":"alireza.ksv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/langjs_1.0.1_1728037975701_0.9154624461532026"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-04T10:28:26.812Z","modified":"2024-10-04T10:32:56.055Z","1.0.0":"2024-10-04T10:28:27.111Z","1.0.1":"2024-10-04T10:32:55.889Z"},"bugs":{"url":"https://github.com/alirezakeshvari/langjs/issues"},"author":{"name":"alirezakeshvari"},"license":"MIT","homepage":"https://github.com/alirezakeshvari/langjs#readme","keywords":["lang","localization","multi-language"],"repository":{"type":"git","url":"git+https://github.com/alirezakeshvari/langjs.git"},"description":"`langjs` is a lightweight multi-language support package for TypeScript/JavaScript projects. It allows developers to define their own translation files in JSON format, switch between languages dynamically, and fetch localized strings for their application","maintainers":[{"name":"alirezakeshvari","email":"alireza.ksv@gmail.com"}],"readme":"# langjs\n\n`langjs` is a lightweight multi-language support package for TypeScript/JavaScript projects. It allows developers to define their own translation files in JSON format, switch between languages dynamically, and fetch localized strings for their applications.\n\n## Features\n\n- Dynamically load translation files (JSON format).\n- Easily switch between multiple languages.\n- Simple API to retrieve translations for any key.\n- TypeScript support for type safety.\n\n## Installation\n\nYou can install `langjs` from npm:\n\n```bash\nnpm install @alirezakeshvari/langjs\n```\n\nOr using Yarn:\n\n```bash\nyarn add @alirezakeshvari/langjs\n```\n\n## Usage\n\n### 1. Setting up your translation files\n\nDefine your translations in JSON files for each language. For example, create `en.json` and `fa.json` like this:\n\n- `en.json`\n\n```json\n{\n  \"hello\": \"Hello\",\n  \"goodbye\": \"Goodbye\"\n}\n```\n\n- `fa.json`\n\n```json\n{\n  \"hello\": \"سلام\",\n  \"goodbye\": \"خداحافظ\"\n}\n```\n\n### 2. Providing the paths to your translation files\n\nIn your project, use the `setTranslations` function to provide the paths to your translation files:\n\n```ts\nimport { setTranslations, setLocale, _ } from \"langjs\";\n\n// Set paths to your translation files\nsetTranslations({\n  en: \"./path/to/en.json\",\n  fa: \"./path/to/fa.json\",\n});\n```\n\n### 3. Switching between locales\n\nUse the `setLocale` function to switch between languages:\n\n```ts\n// Set locale to English\nsetLocale(\"en\");\nconsole.log(_(\"hello\")); // Outputs: Hello\n\n// Set locale to Farsi\nsetLocale(\"fa\");\nconsole.log(_(\"hello\")); // Outputs: سلام\n```\n\n### 4. Fetching translations\n\nUse the `_` function to get translations based on the current locale:\n\n```ts\nconsole.log(_(\"goodbye\")); // Outputs the translation for the current locale\n```\n\nIf a translation key is not found, the key itself will be returned:\n\n```ts\nconsole.log(_(\"nonexistent_key\")); // Outputs: nonexistent_key\n```\n\n## API\n\n### `setTranslations(localeFiles: { [locale: string]: string }): void`\n\nSets the paths to your translation files. The object keys represent the locale code (e.g., `en`, `fa`), and the values represent the file paths to the respective JSON files.\n\n- `localeFiles`: An object where the key is the locale (e.g., `\"en\"`, `\"fa\"`) and the value is the file path to the JSON file.\n\n### `setLocale(locale: string): void`\n\nSets the active locale for translations. This locale will be used to fetch translations when calling `_`.\n\n- `locale`: The locale to switch to (e.g., `\"en\"`, `\"fa\"`).\n\n### `_ (key: string): string`\n\nFetches the translation for the given key from the currently set locale. If the key does not exist, it returns the key itself.\n\n- `key`: The key for which to get the translation (e.g., `\"hello\"`).\n\n## Example Project Setup\n\n```ts\nimport { setTranslations, setLocale, _ } from \"langjs\";\n\n// Set the translation files for English and Farsi\nsetTranslations({\n  en: \"./translations/en.json\",\n  fa: \"./translations/fa.json\",\n});\n\n// Switch to English\nsetLocale(\"en\");\nconsole.log(_(\"hello\")); // Outputs: Hello\n\n// Switch to Farsi\nsetLocale(\"fa\");\nconsole.log(_(\"hello\")); // Outputs: سلام\n```\n\n## Running Tests\n\nYou can run the unit tests with Jest. First, ensure that you've set up your project with the required development dependencies:\n\n```bash\nnpm install\n```\n\nThen, run the tests:\n\n```bash\nnpm test\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","readmeFilename":"README.md"}