{"id":14962758,"url":"https://github.com/nishugoel/svelte-i18next","last_synced_at":"2025-05-08T21:44:14.826Z","repository":{"id":41816480,"uuid":"475136754","full_name":"NishuGoel/svelte-i18next","owner":"NishuGoel","description":"Internationalization for svelte framework. Based on i18next ecosystem","archived":false,"fork":false,"pushed_at":"2024-06-05T04:25:21.000Z","size":279,"stargazers_count":52,"open_issues_count":6,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-08T21:44:09.738Z","etag":null,"topics":["i18next","svelte","sveltejs","web"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/svelte-i18next","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/NishuGoel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2022-03-28T18:49:25.000Z","updated_at":"2025-01-13T04:10:59.000Z","dependencies_parsed_at":"2023-10-16T06:21:09.960Z","dependency_job_id":"11bb6a05-7c5a-4e90-875b-93150dfba312","html_url":"https://github.com/NishuGoel/svelte-i18next","commit_stats":{"total_commits":25,"total_committers":8,"mean_commits":3.125,"dds":0.52,"last_synced_commit":"a0859d9bb80e2f34a40ae88bf8d0c4e1713ff7c8"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NishuGoel%2Fsvelte-i18next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NishuGoel%2Fsvelte-i18next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NishuGoel%2Fsvelte-i18next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NishuGoel%2Fsvelte-i18next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NishuGoel","download_url":"https://codeload.github.com/NishuGoel/svelte-i18next/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253154041,"owners_count":21862448,"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":["i18next","svelte","sveltejs","web"],"created_at":"2024-09-24T13:30:28.383Z","updated_at":"2025-05-08T21:44:14.808Z","avatar_url":"https://github.com/NishuGoel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svelte-i18next [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=%40sveltejs%20wrapper%20for%20i18next%20%0Ahttps%3A%2F%2Fgithub.com%2FNishuGoel%2Fsvelte-i18next%0Avia%20%40TheNishuGoel%20%20\u0026hashtags=i18next,sveltejs,svelte,javascript,webdev)\n\n[![CI](https://github.com/NishuGoel/svelte-i18next/workflows/CI/badge.svg)](https://github.com/NishuGoel/svelte-i18next/actions?query=workflow%3ACI)\n[![npm version](https://img.shields.io/npm/v/svelte-i18next.svg)](https://www.npmjs.com/package/svelte-i18next)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/svelte-i18next?label=gzip%20bundle)](https://bundlephobia.com/package/svelte-i18next)\n[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/NishuGoel/svelte-i18next/blob/master/LICENSE)\n\nSvelte wrapper for [i18next](https://i18next.com/)\n\n```\nnpm i svelte-i18next i18next\n```\n\n## Implementation\n\nThis library wraps an i18next instance in a Svelte Store to observe [i18next events](https://github.com/NishuGoel/svelte-i18next/blob/main/src/translation-store.ts#L23)\nso your Svelte components re-render e.g. when language is changed or a new resource is loaded by i18next.\n\n## Quick Start\n\n`i18n.js`:\n```ts\nimport i18next from \"i18next\";\nimport { createI18nStore } from \"svelte-i18next\";\n\ni18next.init({\n lng: 'en',\n resources: {\n    en: {\n      translation: {\n        \"key\": \"hello world\"\n      }\n    }\n  },\n  interpolation: {\n    escapeValue: false, // not needed for svelte as it escapes by default\n  }\n});\n\nconst i18n = createI18nStore(i18next);\nexport default i18n;\n```\n\n`App.svelte`:\n```svelte\n\u003cscript\u003e\n  import i18n from './i18n.js';\n\u003c/script\u003e\n\n\u003cdiv\u003e\n    {$i18n.t('key')}\n\u003c/div\u003e\n```\n\n## Usage with Sveltekit\n\nSveltekit shares stores across requests on server-side. This means that one users request could change the language setting of another users rendering if that is still ongoing. To avoid this issue, use `setContext` to create request-scoped store instances:\n\n`i18n.js`:\n```ts\nimport i18next from \"i18next\";\nimport { createI18nStore } from \"svelte-i18next\";\n\ni18next.init({\n lng: 'en',\n resources: {\n    en: {\n      translation: {\n        \"key\": \"hello world\"\n      }\n    }\n  },\n  interpolation: {\n    escapeValue: false, // not needed for svelte as it escapes by default\n  }\n});\n\nexport default () =\u003e createI18nStore(i18next);\n```\n\n`routes/+layout.svelte`:\n```sveltehtml\n\u003cscript\u003e\n  import getI18nStore from \"i18n.js\";\n  import { setContext } from \"svelte\";\n  \n  setContext('i18n', getI18nStore());\n\u003c/script\u003e\n```\n\n`routes/+page.svelte`:\n```sveltehtml\n\u003cscript\u003e\n  import { getContext } from \"svelte\";\n  \n  const i18n = getContext(\"i18n\");\n\u003c/script\u003e\n\n\u003cdiv\u003e\n  \u003ch1\u003e{ $i18n.t(\"key\") }\u003c/h1\u003e\n\u003c/div\u003e\n```\n\nSee full example project: [Svelte example](https://github.com/NishuGoel/svelte-i18next/blob/main/example)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnishugoel%2Fsvelte-i18next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnishugoel%2Fsvelte-i18next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnishugoel%2Fsvelte-i18next/lists"}