{"id":13806671,"url":"https://github.com/sveltekit-i18n/lib","last_synced_at":"2025-05-13T22:30:32.081Z","repository":{"id":39413407,"uuid":"438193963","full_name":"sveltekit-i18n/lib","owner":"sveltekit-i18n","description":"Internationalization library built for SvelteKit.","archived":false,"fork":false,"pushed_at":"2025-02-25T23:45:30.000Z","size":2444,"stargazers_count":545,"open_issues_count":25,"forks_count":33,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-05T23:48:53.758Z","etag":null,"topics":["i18n","i18n-js","internationalization","l10n","localization","svelte","sveltekit","sveltekit-i18n","translation"],"latest_commit_sha":null,"homepage":"","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/sveltekit-i18n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["sveltekit-i18n"]}},"created_at":"2021-12-14T09:34:10.000Z","updated_at":"2025-04-27T16:05:38.000Z","dependencies_parsed_at":"2023-12-17T14:27:57.727Z","dependency_job_id":"c6ee76d5-6547-4e90-96f7-cb284ca4dff7","html_url":"https://github.com/sveltekit-i18n/lib","commit_stats":{"total_commits":447,"total_committers":7,"mean_commits":"63.857142857142854","dds":"0.22371364653243853","last_synced_commit":"b09444c66df7cf1d34852b70893b9f93d82d4cb9"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltekit-i18n%2Flib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltekit-i18n%2Flib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltekit-i18n%2Flib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveltekit-i18n%2Flib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sveltekit-i18n","download_url":"https://codeload.github.com/sveltekit-i18n/lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036812,"owners_count":22003655,"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","i18n-js","internationalization","l10n","localization","svelte","sveltekit","sveltekit-i18n","translation"],"created_at":"2024-08-04T01:01:14.555Z","updated_at":"2025-05-13T22:30:32.073Z","avatar_url":"https://github.com/sveltekit-i18n.png","language":"TypeScript","funding_links":["https://github.com/sponsors/sveltekit-i18n"],"categories":["Utilities","TypeScript"],"sub_categories":["Internationalisation"],"readme":"[![npm version](https://badge.fury.io/js/sveltekit-i18n.svg)](https://badge.fury.io/js/sveltekit-i18n) ![](https://github.com/sveltekit-i18n/lib/workflows/Tests/badge.svg)\n\n\u003e [!NOTE]\n\u003e Looking for maintainers. Feel free to contact me if you want to take over the maintanance of this project.\n\u003e \n\u003e https://github.com/sveltekit-i18n/lib/issues/197\n\n\n# sveltekit-i18n\n`sveltekit-i18n` is a tiny library with no external dependencies, built for [Svelte](https://github.com/sveltejs/svelte) and [SvelteKit](https://github.com/sveltejs/kit). It glues [@sveltekit-i18n/base](https://github.com/sveltekit-i18n/base) and [@sveltekit-i18n/parser-default](https://github.com/sveltekit-i18n/parsers/tree/master/parser-default) together to provide you the most straightforward `sveltekit-i18n` solution.\n\n## Key features\n\n✅ SvelteKit ready\\\n✅ SSR support\\\n✅ Custom data sources – no matter if you are using local files or remote API to get your translations\\\n✅ Module-based – your translations are loaded for visited pages only (and only once!)\\\n✅ Component-scoped translations – you can create multiple instances with custom definitions\\\n✅ Custom modifiers – you can modify the input data the way you really need\\\n✅ TS support\\\n✅ No external dependencies\n\n## Usage\n\nSetup `translations.js` in your lib folder...\n```javascript\nimport i18n from 'sveltekit-i18n';\n\n/** @type {import('sveltekit-i18n').Config} */\nconst config = ({\n  loaders: [\n    {\n      locale: 'en',\n      key: 'common',\n      loader: async () =\u003e (\n        await import('./en/common.json')\n      ).default,\n    },\n    {\n      locale: 'en',\n      key: 'home',\n      routes: ['/'], // you can use regexes as well!\n      loader: async () =\u003e (\n        await import('./en/home.json')\n      ).default,\n    },\n    {\n      locale: 'en',\n      key: 'about',\n      routes: ['/about'],\n      loader: async () =\u003e (\n        await import('./en/about.json')\n      ).default,\n    },\n    {\n      locale: 'cs',\n      key: 'common',\n      loader: async () =\u003e (\n        await import('./cs/common.json')\n      ).default,\n    },\n    {\n      locale: 'cs',\n      key: 'home',\n      routes: ['/'],\n      loader: async () =\u003e (\n        await import('./cs/home.json')\n      ).default,\n    },\n    {\n      locale: 'cs',\n      key: 'about',\n      routes: ['/about'],\n      loader: async () =\u003e (\n        await import('./cs/about.json')\n      ).default,\n    },\n  ],\n});\n\nexport const { t, locale, locales, loading, loadTranslations } = new i18n(config);\n```\n\n...load your translations in `+layout.js`...\n\n```javascript\nimport { loadTranslations } from '$lib/translations';\n\n/** @type {import('@sveltejs/kit').Load} */\nexport const load = async ({ url }) =\u003e {\n  const { pathname } = url;\n\n  const initLocale = 'en'; // get from cookie, user session, ...\n\n  await loadTranslations(initLocale, pathname); // keep this just before the `return`\n\n  return {};\n}\n```\n\n...and include your translations within pages and components.\n\n```svelte\n\u003cscript\u003e\n  import { t } from '$lib/translations';\n\n  const pageName = 'This page is Home page!';\n\u003c/script\u003e\n\n\u003cdiv\u003e\n  \u003c!-- you can use `placeholders` and `modifiers` in your definitions (see docs) --\u003e\n  \u003ch2\u003e{$t('common.page', { pageName })}\u003c/h2\u003e\n  \u003cp\u003e{$t('home.content')}\u003c/p\u003e\n\u003c/div\u003e\n```\n\n## More info\n[Docs](https://github.com/sveltekit-i18n/lib/tree/master/docs/README.md)\\\n[Examples](https://github.com/sveltekit-i18n/lib/tree/master/examples)\\\n[Changelog](https://github.com/sveltekit-i18n/lib/releases)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveltekit-i18n%2Flib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsveltekit-i18n%2Flib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveltekit-i18n%2Flib/lists"}