{"id":20514132,"url":"https://github.com/webreflection/i18n-utils","last_synced_at":"2025-04-14T00:10:39.045Z","repository":{"id":65993215,"uuid":"108320491","full_name":"WebReflection/i18n-utils","owner":"WebReflection","description":"The i18n tag function utilitities","archived":false,"fork":false,"pushed_at":"2018-03-19T13:35:35.000Z","size":133,"stargazers_count":75,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T14:12:30.293Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-10-25T20:09:18.000Z","updated_at":"2024-03-10T18:26:10.000Z","dependencies_parsed_at":"2023-05-21T17:00:19.661Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/i18n-utils","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fi18n-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fi18n-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fi18n-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fi18n-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/i18n-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799955,"owners_count":21163404,"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":[],"created_at":"2024-11-15T21:14:57.219Z","updated_at":"2025-04-14T00:10:39.005Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"# i18n-utils\nThe i18n tag function utilitities.\n\n[![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/WebReflection/donate) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC)\n\n[Related post](https://codeburst.io/easy-i18n-in-10-lines-of-javascript-poc-eb9e5444d71e).\n\n### Features\n\n  * write strings in your language, transparently show translations without changing your code\n  * created databases are usable through 10 lines of 100% cross browser JavaScript\n  * you handle translations either one after the other or in bulks\n  * you update only what changed, you never waste time scanning the rest\n  * you can swap indexes. `Date ${0}/${1}/${2}` can be translated as `Data ${2}/${0}/${1}`\n  * automatic clean of the DB. If you change or remove a template literal the DB won't contain it anymore\n\n**Possible future improvements**\n\n  * dynamic change of index names so instead of `${0}/${1}` you can specify `${'year'}/${'month'}` in every translation\n  * use a simple client/server one way hash for strings as key to reduce raw DB size\n\n\n### Quick Introduction\n\nIf you'd like to make your code [i18n](http://www.i18nguy.com/origini18n.html) ready you can use the [i18n-dummy](https://github.com/WebReflection/i18n-dummy) module which provides a noop function tag.\n\n```js\n// anywhere you need to write future proof code\n// use template literals and put i18n in front\nconst greetings = i18n`Hello ${user.name}!`;\n```\n\nOnce you have put the `i18n` function tag in front of all sentences that need translations, you can install this utility and point at the main entry point of your program:\n\n```sh\n# you could use -g too\nnpm install i18n-utils\n\n# if you have latest npm use the binary\nnpx i18n-utils src/main.js\n```\n\nAt this point you just need to follow instructions until a browser page opens, giving you all the found sentences that need translation in other languages you've specified.\n\nOnce you've translated all languages you can install and use [i18n-yummy](https://github.com/WebReflection/i18n-yummy) function\nwhich expects a runtime locale and a database to use.\n\nSpecify both and see that changing locale will produce automatically sentences in the different language.\n\n**test.js** example\n```js\n// somehow include the client library\nconst i18n = require('i18n-yummy');\n\n// specify the locale to display\n// and the database to use\ni18n.locale = 'it';\ni18n.db = require('./i18n.db.json');\n\n// write content in the language you used\n// as default to setup the database (en)\nconsole.log(i18n`Hello ${'i18n'}!`);\n```\n\nTry to save above file as `test.js` and then `i18n-utils ./test.js` providing `it` as translation language and writing `Ciao` instead of `Hello` in the dedicated area.\n\nIf you'll `node test.js` after you will see the output will be `Ciao i18n!` instead of `Hello i18n!`.\n\n\u003cimg src=\"images/shell.png\" width=\"600\"\u003e\n\n\u003cimg src=\"images/browser.png\" width=\"600\"\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fi18n-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fi18n-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fi18n-utils/lists"}