{"id":18871869,"url":"https://github.com/foxifyjs/i18n","last_synced_at":"2026-02-15T14:30:16.098Z","repository":{"id":34909486,"uuid":"188434072","full_name":"foxifyjs/i18n","owner":"foxifyjs","description":"A lightweight translation module for Node.js and browser","archived":false,"fork":false,"pushed_at":"2023-01-03T22:35:12.000Z","size":728,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T19:03:44.491Z","etag":null,"topics":["i18n","international","internationalization","translate","translation"],"latest_commit_sha":null,"homepage":"https://foxifyjs.github.io/i18n","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foxifyjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-24T14:16:47.000Z","updated_at":"2021-12-21T07:20:16.000Z","dependencies_parsed_at":"2023-01-15T10:13:11.428Z","dependency_job_id":null,"html_url":"https://github.com/foxifyjs/i18n","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fi18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fi18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fi18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fi18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxifyjs","download_url":"https://codeload.github.com/foxifyjs/i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239736116,"owners_count":19688389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","international","internationalization","translate","translation"],"created_at":"2024-11-08T05:27:47.945Z","updated_at":"2026-02-15T14:30:16.064Z","avatar_url":"https://github.com/foxifyjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I18n\n\nA lightweight translation module for Node.js and browser.\n\n[![NPM Version](https://img.shields.io/npm/v/@foxify/i18n.svg)](https://www.npmjs.com/package/@foxify/i18n)\n[![TypeScript Version](https://img.shields.io/npm/types/@foxify/i18n.svg)](https://www.typescriptlang.org)\n[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/@foxify/i18n.svg)](https://www.npmjs.com/package/@foxify/i18n)\n[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@foxify/i18n.svg)](https://www.npmjs.com/package/@foxify/i18n)\n[![Tested With Jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n[![Pull Requests](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/foxifyjs/i18n/pulls)\n[![License](https://img.shields.io/github/license/foxifyjs/i18n.svg)](https://github.com/foxifyjs/i18n/blob/master/LICENSE)\n[![Build Status](https://api.travis-ci.com/foxifyjs/i18n.svg?branch=master)](https://travis-ci.com/foxifyjs/i18n)\n[![Coverage Status](https://codecov.io/gh/foxifyjs/i18n/branch/master/graph/badge.svg)](https://codecov.io/gh/foxifyjs/i18n)\n[![Package Quality](http://npm.packagequality.com/shield/%40foxify%2Fodin.svg)](http://packagequality.com/#?package=@foxify/i18n)\n[![Dependencies Status](https://david-dm.org/foxifyjs/i18n.svg)](https://david-dm.org/foxifyjs/i18n)\n[![NPM Total Downloads](https://img.shields.io/npm/dt/@foxify/i18n.svg)](https://www.npmjs.com/package/@foxify/i18n)\n[![NPM Monthly Downloads](https://img.shields.io/npm/dm/@foxify/i18n.svg)](https://www.npmjs.com/package/@foxify/i18n)\n[![Open Issues](https://img.shields.io/github/issues-raw/foxifyjs/i18n.svg)](https://github.com/foxifyjs/i18n/issues?q=is%3Aopen+is%3Aissue)\n[![Closed Issues](https://img.shields.io/github/issues-closed-raw/foxifyjs/i18n.svg)](https://github.com/foxifyjs/i18n/issues?q=is%3Aissue+is%3Aclosed)\n[![known vulnerabilities](https://snyk.io/test/github/foxifyjs/i18n/badge.svg?targetFile=package.json)](https://snyk.io/test/github/foxifyjs/i18n?targetFile=package.json)\n[![Github Stars](https://img.shields.io/github/stars/foxifyjs/i18n.svg?style=social)](https://github.com/foxifyjs/i18n)\n[![Github Forks](https://img.shields.io/github/forks/foxifyjs/i18n.svg?style=social\u0026label=Fork)](https://github.com/foxifyjs/i18n)\n\n## Table of Contents \u003c!-- omit in toc --\u003e\n\n- [I18n](#i18n)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Configure](#configure)\n    - [Init](#init)\n    - [Properties](#properties)\n    - [translate](#translate)\n  - [Versioning](#versioning)\n  - [Authors](#authors)\n  - [License](#license)\n\n## Installation\n\n```bash\nnpm i @foxify/i18n\n```\n\n## Usage\n\n```js\nconst I18n = require(\"@foxify/i18n\");\n```\n\n### Configure\n\n`config` is an static method\nIt gets an object containing the locales and an optional fallback locale, which would be `\"en\"` by default.\nLocales support dot notation and parameters...\n\n```js\nI18n.config({\n  fallback: \"en\", // optional, default: \"en\"\n  locales: { // required\n    en: {\n      names: {\n        Ardalan: \"Ardalan\",\n      },\n      greetings: {\n        hello: \"hello\",\n        hi: \"hi, {{name}}\", // translation with parameters (required parameter)\n        hi2: \"hi, {{name=}}\", // optional parameter\n        // default output: \"hi, \"\n\n        hi3: \"hi, {{name=foo}}\", // optional parameter with default value: \"foo\"\n        // default output: \"hi, foo\"\n\n        hi4: \"hi, {{name=$names.Ardalan}}\", // optional parameter with default value referenced to translation: \"Ardalan\"\n        // default output: \"hi, Ardalan\"\n\n        hi5: \"hi, {{$names.Ardalan}}\", // value referenced to translation: \"Ardalan\" (this is not considered as a parameter)\n        // output: \"hi, Ardalan\"\n      },\n    },\n  },\n  severity: \"error\", // optional, default: \"error\"\n  // `ignore`: will return the key if no translation was found\n  // `warn`: will warn (`console.warn`) and return the key if no translation was found\n  // `error`: will throw an error if no translation was found\n\n  strict: false, // optional, default: false\n  // true: don't use the fallback locale for translation\n  // false: use the fallback locale if necessary\n});\n```\n\n### Init\n\nThe `I18n` constructor accepts an optional locale parameter, which would be the fallback locale by default.\n\n```js\nconst i18n = new I18n();\n```\n\nSet the locale when creating new instance:\n\n```js\nconst i18n = new I18n(\"en\");\n```\n\nSet the strict mode when creating new instance:\n\n```js\nconst i18n = new I18n(true);\n```\n\nSet the locale and the strict mode when creating new instance:\n\n```js\nconst i18n = new I18n(\"en\", true);\n```\n\n### Properties\n\n```js\nconsole.log(i18n.locale); // instance's locale\n\nconsole.log(i18n.direction); // instance's locale direction: \"rtl\" | \"ltr\"\n```\n\n### translate\n\nTranslates the given string according the instance's locale and configured locales;\nIf it doesn't find any translation and it isn't in strict mode, it will try again with the fallback locale;\nIf it doesn't find any translation again, it will throw an error.\n\n```js\ni18n.translate(\"greetings.hello\");\ni18n.t(\"greetings.hello\");\n// hello\n\ni18n.translate(\"greetings.hello\", true); // strict mode\ni18n.t(\"greetings.hello\", true);\n\ni18n.translate(\"greetings.hi\", { name: \"Ardalan!\" }); // pass the params\ni18n.t(\"greetings.hi\", { name: \"Ardalan!\" });\n// hi, Ardalan!\n\ni18n.translate(\"greetings.hi\", { name: \"$names.Ardalan\" }); // you can use reference as param too\ni18n.t(\"greetings.hi\", { name: \"$names.Ardalan\" });\n// hi, Ardalan\n\ni18n.translate(\"greetings.hi\", { name: \"$names.Ardalan\" }, true); // strict mode\ni18n.t(\"greetings.hi\", { name: \"$names.Ardalan\" }, true);\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org) for versioning. For the versions available, see the [tags on this repository](https://github.com/foxifyjs/i18n/tags).\n\n## Authors\n\n- **Ardalan Amini** - _Core Maintainer_ - [@ardalanamini](https://github.com/ardalanamini)\n\nSee also the list of [contributors](https://github.com/foxifyjs/i18n/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Fi18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxifyjs%2Fi18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Fi18n/lists"}