{"id":20538030,"url":"https://github.com/yoannmoinet/i18njs","last_synced_at":"2025-07-26T07:11:44.511Z","repository":{"id":29941388,"uuid":"33487744","full_name":"yoannmoinet/i18njs","owner":"yoannmoinet","description":":tongue: Simplistic I18N tool for universal/isomorphic Javascript.","archived":false,"fork":false,"pushed_at":"2016-03-22T18:33:57.000Z","size":102,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T09:11:24.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://yoannmoinet.github.io/i18njs/","language":"JavaScript","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/yoannmoinet.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":"2015-04-06T15:00:04.000Z","updated_at":"2018-06-06T09:09:47.000Z","dependencies_parsed_at":"2022-08-31T04:22:48.671Z","dependency_job_id":null,"html_url":"https://github.com/yoannmoinet/i18njs","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/yoannmoinet/i18njs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannmoinet%2Fi18njs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannmoinet%2Fi18njs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannmoinet%2Fi18njs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannmoinet%2Fi18njs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoannmoinet","download_url":"https://codeload.github.com/yoannmoinet/i18njs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannmoinet%2Fi18njs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267133958,"owners_count":24040789,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T00:43:55.784Z","updated_at":"2025-07-26T07:11:44.451Z","avatar_url":"https://github.com/yoannmoinet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](./dist/logo.png)\n-----\n\n\u003e Simplistic I18N tool for universal/isomorphic Javascript.\n\n[![npm version](https://img.shields.io/npm/v/i18njs.svg?style=flat)](http://badge.fury.io/js/i18njs)\n[![bower version](https://img.shields.io/bower/v/i18njs.svg?style=flat)](http://bower.io/search/?q=i18njs)\n[![travis](https://travis-ci.org/yoannmoinet/i18njs.svg)](https://travis-ci.org/yoannmoinet/i18njs)\n\n[![NPM](https://nodei.co/npm-dl/i18njs.png?months=1)](https://npmjs.org/package/i18njs)\n\n----\n\n\n## Usage with RequireJS\n\nTo use with **[RequireJS](http://requirejs.org)** I'd advise to also use the plugin\n[requirejs-i18njs](https://github.com/yoannmoinet/requirejs-i18njs) to be able to precompile the templates\nthat are in your translation files for your production code.\n\n----\n\n## Usage with Handlebars\n\nYou can register your helper simply by using the `.get()` function of i18njs\n\n```javascript\nHandlebars.registerHelper('i18n',\n    function () {\n        // Pass all arguments except the last one\n        // that is a Handlebars specific.\n        return i18njs.get.apply(i18njs,\n                Array.prototype.slice.call(arguments, 0, -1));\n    }\n);\n```\n\nthen in your templates :\n\n```javascript\n// Arguments after the 'key' are optionals\n{{i18n 'key' data options lang}}\n```\n\n----\n\n## Installation\n\nEither\n\n```node\nnpm install --save i18njs\n```\n\nor\n\n```node\nbower install --save i18njs\n```\n----\n\n## Usage\n\nImport it the way you want into your project :\n\n```javascript\n// CommonJS\nvar i18njs = require('i18njs');\n```\n\n```javascript\n// AMD\ndefine(['i18njs'], function (i18njs) {\n    // use i18njs\n});\n```\n\n```html\n// Global\n\u003cscript type=\"text/javascript\" src=\"./dist/i18njs.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    // use i18njs\n\u003c/script\u003e\n```\n\n### Add locales\n\nYour localized strings are simple json objects.\n\nNamespaces can be as deep as you need.\n\n```javascript\n\nvar en_locales = {\n    'hello_world': {\n        'hello': 'Hello',\n        'world': 'World'\n    }\n};\n\nvar fr_locales = {\n    'hello_world': {\n        'hello': 'Bonjour',\n        'world': 'Monde'\n    }\n};\n\n// i18n.add(language, [namespace,] locales);\ni18n.add('en', 'first_level_namespace', en_locales);\ni18n.add('fr', 'first_level_namespace', fr_locales);\n\n```\n\n### Change language\n\nBy default, language is set to `en`.\n\n```javascript\n\ni18n.setLang('fr');\n\n```\n\n### Get current language\n\n```javascript\n\ni18n.getCurrentLang();\n\n```\n\n### Get dictionary\n\n```javascript\n\ni18n.getDico();\n\n```\n### Check for availability\n\nIf needed, you can also check for the presence of a specific localized string in a particular language.\n\nYou can check only the language too.\n\n ```javascript\n // i18n.has([key,] lang)\n i18n.has('first_level_namespace.hello_world.hello', 'en');\n // true\n\n i18n.has('first_level_namespace.hello_world.hello');\n // true\n\n i18n.has('en');\n // true\n\n  i18n.has('de');\n  // false\n\n  i18n.has('hello_world.bye', 'en');\n  // false\n\n  i18n.has('test');\n  // false\n ```\n\n### List available languages\n\n```javascript\n\ni18n.listLangs();\n// ['en', 'fr']\n\n```\n\n### Get basic localized string\n\n```javascript\n\n// i18n.get(key[, data, options][, lang]);\ni18n.get('first_level_namespace.hello_world.hello');\n// Hello\n\ni18n.get('first_level_namespace.hello_world.hello', 'fr');\n// Bonjour\n\n```\n\n### Get templated string\n\nIt uses a basic templating engine, the same as [underscore](http://underscorejs.org/#template).\n\nIt works in the form of `{{=interpolate}}`, `{{evaluate}}` or `{{-escape}}` :\n\n```javascript\n// localized strings\nvar en_locales = {\n    'st': '{{=interpolate}}{{for(var i = 0, max = 5; i \u003c max; i += 1) {}} to{{}}} {{-escape}}'\n};\n\n// context used in the templated string\nvar data = {\n    'interpolate': 'Hello',\n    'escape': '\\'\u003cthe\u003e\\' `\u0026` \"World\"'\n};\n\n// register the localized string\ni18n.add('en', en_locales);\n\n// give it a context with the data object\nvar st = i18n.get('st', data);\n// \"Hello  to to to to to \u0026#x27;\u0026lt;the\u0026gt;\u0026#x27; \u0026#x60;\u0026amp;\u0026#x60; \u0026quot;World\u0026quot;\"\n\n```\n\n### Change delimiters\n\nYou can also change delimiters by passing the third `options` arguments\n\n```javascript\n\nvar st = i18n.get('st', data, {\n    evaluate: /\u003c%([\\s\\S]+?)%\u003e/g;\n    interpolate: /\u003c%=([\\s\\S]+?)%\u003e/g;\n    escape: /\u003c%-([\\s\\S]+?)%\u003e/g;\n});\n\n```\n\nWill result in these delimiters `\u003c%=interpolate%\u003e`, `\u003c%evaluate%\u003e` or `\u003c%-escape%\u003e`\n\n### Add default values for templates\n\nIf you need to have a special key always replaced by the same value (a brand for example),\nyou can set it as a **default**.\n\nThis `key` will be then replaced across your application's localized strings and you\nwon't need to pass it as a context object to your `.get()`.\n\n```javascript\nvar fr = {\n    welcome: 'Bienvenue sur {{=brand}}'\n};\n\nvar en = {\n    welcome: 'Welcome to {{=brand}}'\n};\n\nvar defaults = {\n    fr: {\n        brand: 'Ma Marque'\n    },\n    en: {\n        brand: 'My Brand'\n    }\n};\n\ni18n.add('fr', fr);\ni18n.add('en', en);\ni18n.setDefaults(defaults);\n\ni18n.get('welcome');\n//Welcome to My Brand\ni18n.get('brand');\n// My Brand\n```\n\nYou don't have to use localized defaults if you don't need to :\n\n```javascript\nvar defaults = {\n    brand: 'My Brand'\n};\n\ni18n.setDefaults(defaults);\ni18n.setLang('fr');\n\ni18n.get('welcome');\n//Bienvenue sur My Brand\n```\n\nYou can also check your defaults :\n\n```javascript\ni18n.getDefaults();\n//{\n//  brand: 'My Brand',\n//  fr: {\n//      brand: 'Ma Marque'\n//  },\n//  en: {\n//      brand: 'My Brand'\n//  }\n//}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoannmoinet%2Fi18njs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoannmoinet%2Fi18njs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoannmoinet%2Fi18njs/lists"}