├── .nvmrc ├── .github ├── FUNDING.yml └── workflows │ ├── tests.yml │ └── publish.yml ├── .npmignore ├── pnpm-workspace.yaml ├── tests ├── data │ ├── translations │ │ ├── en │ │ │ ├── route.json │ │ │ └── common.json │ │ ├── ku │ │ │ └── common.json │ │ ├── zh-Hans │ │ │ └── common.json │ │ └── index.ts │ └── index.ts ├── tsconfig.json └── utils │ └── index.ts ├── examples ├── loaders │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── cs │ │ │ │ │ ├── more.json │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── lang.json │ │ │ │ └── en │ │ │ │ │ ├── more.json │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +server.js │ │ │ ├── +layout.svelte │ │ │ └── +layout.server.js │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── svelte.config.js │ ├── netlify.toml │ ├── vite.config.js │ ├── package.json │ └── README.md ├── locale-param │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── +layout.server.js │ │ │ └── +layout.svelte │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── svelte.config.js │ ├── netlify.toml │ ├── vite.config.js │ ├── package.json │ └── README.md ├── multi-page │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── +layout.svelte │ │ │ └── +layout.server.js │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── svelte.config.js │ ├── netlify.toml │ ├── vite.config.js │ ├── package.json │ └── README.md ├── one-page │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── content.json │ │ │ │ │ └── menu.json │ │ │ │ ├── en │ │ │ │ │ ├── content.json │ │ │ │ │ └── menu.json │ │ │ │ └── index.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ └── +layout.svelte │ │ ├── app.d.ts │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── preprocess │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── index.js │ │ │ │ └── translations.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── app.d.ts │ │ ├── app.html │ │ └── routes │ │ │ ├── +layout.svelte │ │ │ └── +page.svelte │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── single-load │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── index.js │ │ │ │ └── translations.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── app.d.ts │ │ ├── routes │ │ │ ├── +page.svelte │ │ │ └── +layout.svelte │ │ └── app.html │ ├── static │ │ └── robots.txt │ ├── svelte.config.js │ ├── netlify.toml │ ├── .gitignore │ ├── vite.config.js │ ├── package.json │ └── README.md ├── fallback-locale │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── +layout.server.js │ │ │ └── +layout.svelte │ │ ├── app.d.ts │ │ └── app.html │ ├── .gitignore │ ├── static │ │ └── favicon.png │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── locale-router │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── de │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── [lang] │ │ │ │ ├── about │ │ │ │ │ └── +page.svelte │ │ │ │ ├── +page.svelte │ │ │ │ └── +layout.svelte │ │ │ ├── +layout.js │ │ │ ├── +error.svelte │ │ │ └── +layout.server.js │ │ ├── app.d.ts │ │ ├── app.html │ │ └── hooks.server.js │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── component-scoped-csr │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ ├── component │ │ │ │ ├── translations │ │ │ │ │ ├── de │ │ │ │ │ │ └── common.json │ │ │ │ │ ├── lang.json │ │ │ │ │ ├── en │ │ │ │ │ │ └── common.json │ │ │ │ │ ├── cs │ │ │ │ │ │ └── common.json │ │ │ │ │ └── index.js │ │ │ │ └── index.svelte │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── +page.svelte │ │ │ ├── +layout.svelte │ │ │ └── +layout.server.js │ │ ├── app.d.ts │ │ └── app.html │ ├── .gitignore │ ├── static │ │ └── favicon.png │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── component-scoped-ssr │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ ├── component │ │ │ │ ├── translations │ │ │ │ │ ├── de │ │ │ │ │ │ └── common.json │ │ │ │ │ ├── lang.json │ │ │ │ │ ├── en │ │ │ │ │ │ └── common.json │ │ │ │ │ ├── cs │ │ │ │ │ │ └── common.json │ │ │ │ │ └── index.js │ │ │ │ └── index.svelte │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── about │ │ │ │ └── +page.svelte │ │ │ ├── +page.js │ │ │ ├── +page.svelte │ │ │ ├── +layout.js │ │ │ ├── +layout.svelte │ │ │ └── +layout.server.js │ │ ├── app.d.ts │ │ └── app.html │ ├── .gitignore │ ├── static │ │ └── favicon.png │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── locale-router-advanced │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ │ └── de │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ └── about.json │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── [...lang=locale] │ │ │ │ ├── about │ │ │ │ │ └── +page.svelte │ │ │ │ ├── +page.svelte │ │ │ │ └── +layout.svelte │ │ │ ├── +layout.js │ │ │ ├── +error.svelte │ │ │ └── +layout.server.js │ │ ├── app.d.ts │ │ ├── params │ │ │ └── locale.js │ │ └── app.html │ ├── .gitignore │ ├── static │ │ └── favicon.png │ ├── netlify.toml │ ├── svelte.config.js │ ├── vite.config.js │ ├── package.json │ └── README.md ├── locale-router-static │ ├── jsconfig.json │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.js │ │ │ │ ├── cs │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ ├── index.js │ │ │ │ │ └── about.json │ │ │ │ ├── en │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ ├── index.js │ │ │ │ │ └── about.json │ │ │ │ ├── de │ │ │ │ │ ├── home.json │ │ │ │ │ ├── error.json │ │ │ │ │ ├── menu.json │ │ │ │ │ ├── index.js │ │ │ │ │ └── about.json │ │ │ │ └── index.js │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── [lang] │ │ │ │ ├── about │ │ │ │ │ └── +page.svelte │ │ │ │ ├── [...error] │ │ │ │ │ ├── +page@.svelte │ │ │ │ │ └── +page.js │ │ │ │ ├── +page.svelte │ │ │ │ └── +layout.svelte │ │ │ ├── +error.svelte │ │ │ └── +layout.js │ │ ├── app.d.ts │ │ ├── app.html │ │ └── hooks.server.js │ ├── .gitignore │ ├── static │ │ └── favicon.png │ ├── vite.config.js │ ├── netlify.toml │ ├── package.json │ └── svelte.config.js ├── parser-icu │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── cs │ │ │ │ │ └── content.json │ │ │ │ ├── en │ │ │ │ │ └── content.json │ │ │ │ └── index.ts │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── +layout.ts │ │ │ ├── +layout.svelte │ │ │ └── +page.svelte │ │ ├── app.d.ts │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── tsconfig.json │ ├── netlify.toml │ ├── vite.config.js │ ├── svelte.config.js │ ├── README.md │ └── package.json ├── parser-default │ ├── src │ │ ├── lib │ │ │ ├── translations │ │ │ │ ├── lang.json │ │ │ │ ├── modifiers.ts │ │ │ │ ├── index.ts │ │ │ │ ├── en │ │ │ │ │ └── content.json │ │ │ │ └── cs │ │ │ │ │ └── content.json │ │ │ └── assets │ │ │ │ └── favicon.svg │ │ ├── routes │ │ │ ├── +layout.ts │ │ │ └── +layout.svelte │ │ ├── app.d.ts │ │ └── app.html │ ├── static │ │ └── favicon.png │ ├── .gitignore │ ├── tsconfig.json │ ├── vite.config.js │ ├── netlify.toml │ ├── svelte.config.js │ ├── package.json │ └── README.md └── tsconfig.json ├── jest.config.js ├── src ├── types.ts └── index.ts ├── tsconfig.json ├── tsup.config.js ├── .gitignore ├── .eslintrc ├── LICENSE └── package.json /.nvmrc: -------------------------------------------------------------------------------- 1 | 22 2 | 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [sveltekit-i18n] 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github 2 | src 3 | tests 4 | examples 5 | docs -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'examples/*' 3 | 4 | -------------------------------------------------------------------------------- /tests/data/translations/en/route.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "value" 3 | } -------------------------------------------------------------------------------- /examples/loaders/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/locale-param/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/multi-page/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/one-page/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/preprocess/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/single-load/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/fallback-locale/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/locale-router/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/cs/more.json: -------------------------------------------------------------------------------- 1 | { 2 | "content": "Nějaký další obsah..." 3 | } -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/locale-router-static/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/en/more.json: -------------------------------------------------------------------------------- 1 | { 2 | "content": "Some additional content..." 3 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/parser-icu/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/preprocess/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/single-load/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "include": [ 4 | "./" 5 | ] 6 | } -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/parser-default/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky" 4 | } -------------------------------------------------------------------------------- /examples/single-load/static/robots.txt: -------------------------------------------------------------------------------- 1 | # allow crawling everything by default 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/translations/de/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "Some Schweinefleisch..." 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/translations/de/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "Some Schweinefleisch..." 3 | } -------------------------------------------------------------------------------- /examples/loaders/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/loaders/static/favicon.png -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "de": "Deutsch", 4 | "cs": "Česky" 5 | } -------------------------------------------------------------------------------- /examples/one-page/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/one-page/static/favicon.png -------------------------------------------------------------------------------- /examples/multi-page/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/multi-page/static/favicon.png -------------------------------------------------------------------------------- /examples/parser-icu/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/parser-icu/static/favicon.png -------------------------------------------------------------------------------- /examples/preprocess/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/preprocess/static/favicon.png -------------------------------------------------------------------------------- /examples/loaders/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/locale-param/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/locale-param/static/favicon.png -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "de": "Deutsch", 4 | "cs": "Česky" 5 | } -------------------------------------------------------------------------------- /examples/locale-router/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/locale-router/static/favicon.png -------------------------------------------------------------------------------- /examples/multi-page/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/one-page/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/parser-default/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/parser-default/static/favicon.png -------------------------------------------------------------------------------- /examples/parser-icu/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/preprocess/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky", 4 | "de": "Deutsch" 5 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/translations/lang.json: -------------------------------------------------------------------------------- 1 | { 2 | "en": "English", 3 | "cs": "Česky", 4 | "de": "Deutsch" 5 | } -------------------------------------------------------------------------------- /examples/fallback-locale/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/fallback-locale/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/fallback-locale/static/favicon.png -------------------------------------------------------------------------------- /examples/locale-param/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/lang.js: -------------------------------------------------------------------------------- 1 | export default { 2 | en: 'English', 3 | de: 'Deutsch', 4 | cs: 'Česky', 5 | }; -------------------------------------------------------------------------------- /examples/locale-router/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/parser-default/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/translations/en/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "This component uses its own instance of i18n!" 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/translations/en/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "This component uses its own instance of i18n!" 3 | } -------------------------------------------------------------------------------- /examples/locale-router-static/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/translations/cs/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "Tato komponenta používá svou vlastní instanci i18n!" 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/component-scoped-csr/static/favicon.png -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/translations/cs/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": "Tato komponenta používá svou vlastní instanci i18n!" 3 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/component-scoped-ssr/static/favicon.png -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 3 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build 4 | .svelte-kit 5 | package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /examples/locale-router-static/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/locale-router-static/static/favicon.png -------------------------------------------------------------------------------- /examples/locale-router-advanced/static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sveltekit-i18n/lib/HEAD/examples/locale-router-advanced/static/favicon.png -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default ({ 3 | preset: 'ts-jest/presets/default-esm', 4 | testEnvironment: 'node', 5 | }); -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/cs/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/en/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 3 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/locale-param/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/cs/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Vítejte ve SvelteKit", 3 | "text": "Dokumentace je k přečtení na kit.svelte.dev" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/multi-page/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Welcome to SvelteKit", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/parser-icu/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule": true, 5 | "allowSyntheticDefaultImports": true 6 | } 7 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/de/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Willkommen bei SvelteKit", 3 | "text": "Besuchen Sie kit.svelte.dev, um die Dokumentation zu lesen" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/src/routes/[lang]/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 3 | } -------------------------------------------------------------------------------- /examples/parser-default/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "resolveJsonModule": true, 5 | "allowSyntheticDefaultImports": true 6 | } 7 | } -------------------------------------------------------------------------------- /examples/parser-default/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | 4 | export default defineConfig({ 5 | plugins: [sveltekit()], 6 | }); 7 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/de/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Willkommen bei SvelteKit", 3 | "text": "Besuchen Sie kit.svelte.dev, um die Dokumentation zu lesen" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/[lang]/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/cs/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "No toto...", 3 | "404": "Stránka nenalezena.", 4 | "500": "Interní chyba serveru.", 5 | "default": "Něco se pokazilo." 6 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/en/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Oh, dear...", 3 | "404": "Page not found.", 4 | "500": "Server internal error.", 5 | "default": "Some error occurred." 6 | } -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/en/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "This title is from EN (fallback) definitions", 3 | "text": "Visit kit.svelte.dev to read the documentation" 4 | } -------------------------------------------------------------------------------- /examples/fallback-locale/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('missing.fallback.translation')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/de/home.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Willkommen bei SvelteKit", 3 | "text": "Besuchen Sie kit.svelte.dev, um die Dokumentation zu lesen" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/cs/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "No toto...", 3 | "404": "Stránka nenalezena.", 4 | "500": "Interní chyba serveru.", 5 | "default": "Něco se pokazilo." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/en/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Oh, dear...", 3 | "404": "Page not found.", 4 | "500": "Server internal error.", 5 | "default": "Some error occurred." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/cs/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "No toto...", 3 | "404": "Stránka nenalezena.", 4 | "500": "Interní chyba serveru.", 5 | "default": "Něco se pokazilo." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/en/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Oh, dear...", 3 | "404": "Page not found.", 4 | "500": "Server internal error.", 5 | "default": "Some error occurred." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/[lang]/[...error]/+page@.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/de/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Auweh...", 3 | "404": "Seite nicht gefunden.", 4 | "500": "Server interner Fehler.", 5 | "default": "Ein Fehler ist aufgetreten." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/[...lang=locale]/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 |

{$t('about.title')}

6 |

{@html $t('about.text')}

7 | -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/de/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Auweh...", 3 | "404": "Seite nicht gefunden.", 4 | "500": "Server interner Fehler.", 5 | "default": "Ein Fehler ist aufgetreten." 6 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/de/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "shit.happens": "Auweh...", 3 | "404": "Seite nicht gefunden.", 4 | "500": "Server interner Fehler.", 5 | "default": "Ein Fehler ist aufgetreten." 6 | } -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/single-load/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from "@sveltejs/adapter-netlify"; 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { kit: { adapter: adapter() } }; 5 | 6 | export default config; 7 | -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/parser-icu/src/routes/+layout.ts: -------------------------------------------------------------------------------- 1 | import type { Load } from '@sveltejs/kit'; 2 | import { loading } from '$lib/translations'; 3 | 4 | export const load: Load = async () => { 5 | await loading.toPromise(); 6 | 7 | return {}; 8 | }; -------------------------------------------------------------------------------- /examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "paths": { 5 | "$lib": [ 6 | "./*/src/lib" 7 | ] 8 | } 9 | }, 10 | "include": [ 11 | "./" 12 | ] 13 | } -------------------------------------------------------------------------------- /examples/loaders/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/en/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Home", 3 | "about": "About", 4 | "notification": "You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}" 5 | } -------------------------------------------------------------------------------- /examples/multi-page/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/parser-default/src/routes/+layout.ts: -------------------------------------------------------------------------------- 1 | import type { Load } from '@sveltejs/kit'; 2 | import { loading } from '$lib/translations'; 3 | 4 | export const load: Load = async () => { 5 | await loading.toPromise(); 6 | 7 | return {}; 8 | }; -------------------------------------------------------------------------------- /examples/fallback-locale/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-param/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/one-page/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('content.title')}

8 |

{@html $t('content.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/de/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Startseite", 3 | "about": "Über uns", 4 | "notification": "Sie haben {{count:gt; 0:{{count}} neue {{count; 1:Nachricht; default:Nachrichten}}!; default:keine Nachrichten...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router/src/routes/[lang]/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/loaders/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-netlify'; 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { 5 | kit: { 6 | adapter: adapter(), 7 | }, 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/loaders/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter loaders run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/locale-param/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-netlify'; 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { 5 | kit: { 6 | adapter: adapter(), 7 | }, 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/de/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Startseite", 3 | "about": "Über uns", 4 | "notification": "Sie haben {{count:gt; 0:{{count}} neue {{count; 1:Nachricht; default:Nachrichten}}!; default:keine Nachrichten...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/cs/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Domů", 3 | "about": "O nás", 4 | "notification": "{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/de/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "home": "Startseite", 3 | "about": "Über uns", 4 | "notification": "Sie haben {{count:gt; 0:{{count}} neue {{count; 1:Nachricht; default:Nachrichten}}!; default:keine Nachrichten...}}" 5 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/[lang]/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/multi-page/svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-netlify'; 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { 5 | kit: { 6 | adapter: adapter(), 7 | }, 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /examples/one-page/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter one-page run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/locale-param/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter locale-param run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/[...lang=locale]/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('home.title')}

8 |

{@html $t('home.text', { link })}

9 | -------------------------------------------------------------------------------- /examples/multi-page/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter multi-page run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/parser-default/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter parser-default run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/parser-icu/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter parser-icu run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/preprocess/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter preprocess run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/single-load/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter single-load run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/locale-router/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter locale-router run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/fallback-locale/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter fallback-locale run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/preprocess/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter component-scoped-csr run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/component-scoped-ssr/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter component-scoped-ssr run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/fallback-locale/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter locale-router-advanced run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [functions] 9 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /examples/locale-router/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/one-page/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import adapter from '@sveltejs/adapter-netlify'; 4 | 5 | /** @type {import('@sveltejs/kit').Config} */ 6 | const config = { 7 | kit: { 8 | adapter: adapter(), 9 | }, 10 | }; 11 | 12 | export default config; 13 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | kit: { 7 | adapter: adapter(), 8 | }, 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/cs/index.js: -------------------------------------------------------------------------------- 1 | import about from './about.json'; 2 | import error from './error.json'; 3 | import home from './home.json'; 4 | import menu from './menu.json'; 5 | 6 | export default { 7 | about, 8 | error, 9 | home, 10 | menu, 11 | }; -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/de/index.js: -------------------------------------------------------------------------------- 1 | import about from './about.json'; 2 | import error from './error.json'; 3 | import home from './home.json'; 4 | import menu from './menu.json'; 5 | 6 | export default { 7 | about, 8 | error, 9 | home, 10 | menu, 11 | }; -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/en/index.js: -------------------------------------------------------------------------------- 1 | import about from './about.json'; 2 | import error from './error.json'; 3 | import home from './home.json'; 4 | import menu from './menu.json'; 5 | 6 | export default { 7 | about, 8 | error, 9 | home, 10 | menu, 11 | }; -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import type { Config as C } from '@sveltekit-i18n/base'; 2 | import type { Parser } from '@sveltekit-i18n/parser-default'; 3 | 4 | export type Config = { 5 | parserOptions?: Parser.Options; 6 | } & Omit>, 'parser'>; 7 | -------------------------------------------------------------------------------- /examples/parser-icu/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | 4 | export default defineConfig({ 5 | plugins: [sveltekit()], 6 | ssr: { 7 | noExternal: true, // or ['@sveltekit-i18n/*', 'intl-messageformat', '@formatjs/*'] 8 | }, 9 | }); 10 | -------------------------------------------------------------------------------- /examples/single-load/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import translations from './translations'; 3 | 4 | /** @type {import('sveltekit-i18n').Config} */ 5 | const config = { 6 | initLocale: 'en', 7 | translations, 8 | }; 9 | 10 | export const { t, l, locales, locale } = new i18n(config); -------------------------------------------------------------------------------- /examples/one-page/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/parser-icu/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/preprocess/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/fallback-locale/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/locale-router/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/parser-default/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/single-load/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/single-load/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | .DS_Store 4 | 5 | 6 | # Output 7 | .output 8 | .vercel 9 | .netlify 10 | .wrangler 11 | /.svelte-kit 12 | /build 13 | 14 | # Env 15 | .env 16 | .env.* 17 | !.env.example 18 | !.env.test 19 | 20 | 21 | # Lock files 22 | pnpm-lock.yaml 23 | yarn.lock 24 | package-lock.json 25 | bun.lockb 26 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /examples/loaders/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/one-page/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/+page.js: -------------------------------------------------------------------------------- 1 | import { init } from '$lib/component/index.svelte'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async () => { 5 | const cs = init('cs'); 6 | const de = init('de'); 7 | 8 | await Promise.all([cs.loading.toPromise(), de.loading.toPromise()]); 9 | 10 | return { cs, de }; 11 | }; -------------------------------------------------------------------------------- /examples/locale-param/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/locale-router/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/multi-page/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/preprocess/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/single-load/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/fallback-locale/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/single-load/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |

{$t('content.title')}

8 |

{@html $t('content.info')}

9 |
10 | {#each $locales as locale} 11 |

{@html $l(locale, 'content.text', { link })}

12 | {/each} 13 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/locale-router-static/vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from "@sveltejs/kit/vite"; 2 | import { defineConfig } from "vite"; 3 | import path from "path"; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | resolve: { 8 | alias: { 9 | "sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"), 10 | }, 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /examples/one-page/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { loadTranslations } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async () => { 5 | 6 | const initialLocale = 'en'; // get from cookie / url / fetch from server... 7 | 8 | await loadTranslations(initialLocale); // keep this just before the `return` 9 | 10 | return {}; 11 | }; -------------------------------------------------------------------------------- /examples/loaders/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/params/locale.js: -------------------------------------------------------------------------------- 1 | import { locales } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ParamMatcher} */ 4 | export function match(param) { 5 | const definedLocales = locales.get(); 6 | const paths = [...definedLocales, '']; 7 | const slashPaths = paths.map((l) => `${l}/`); 8 | 9 | return [...paths, ...slashPaths].includes(param); 10 | } -------------------------------------------------------------------------------- /examples/locale-param/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/multi-page/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/one-page/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/locale-router/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/parser-icu/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/preprocess/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/single-load/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/fallback-locale/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/parser-default/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/loaders/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %sveltekit.head% 10 | 11 | 12 | 13 |
%sveltekit.body%
14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/locale-param/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/multi-page/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 9 | 10 |

{$t('home.title')}

11 |

{@html $t('home.text', { link })}

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/fallback-locale/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/locale-router/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').LayoutLoad} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { lang, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(lang); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/parser-icu/src/lib/translations/cs/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "plural": "Máte {value, plural, =0 {nula fotek.} =1 {jednu fotku.} few {# fotky.} other {# fotek.}}", 3 | "select": "{value, select, male {On} female {Ona} other {Oni}} odpoví brzy.", 4 | "selectordinal": "Moje kočka slaví {value, selectordinal, other {#.}} narozeniny.", 5 | "number": "Cena je: {value, number, ::currency/CZK}", 6 | "date": "Dnes je: {value, date, FULL}" 7 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { locale, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(locale); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { addTranslations, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').LayoutLoad} */ 4 | export const load = async ({ data }) => { 5 | const { i18n, translations } = data; 6 | const { lang, route } = i18n; 7 | 8 | addTranslations(translations); 9 | 10 | await setRoute(route); 11 | await setLocale(lang); 12 | 13 | return i18n; 14 | }; -------------------------------------------------------------------------------- /examples/locale-router/src/routes/+error.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |

{$t('error.shit.happens')} ({status})

10 |

{$t(`error.${status}`, { default: $t('error.default') })}

11 |
12 |
13 | {$locale} – {$t(`lang.${$locale}`)} 14 |
15 | -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/+error.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |

{$t('error.shit.happens')} ({status})

10 |

{$t(`error.${status}`, { default: $t('error.default') })}

11 |
12 |
13 | {$locale} – {$t(`lang.${$locale}`)} 14 |
15 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/+error.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |

{$t('error.shit.happens')} ({status})

10 |

{$t(`error.${status}`, { default: $t('error.default') })}

11 |
12 |
13 | {$locale} – {$t(`lang.${$locale}`)} 14 |
15 | -------------------------------------------------------------------------------- /examples/parser-icu/src/lib/translations/en/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "plural": "You have {value, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}", 3 | "select": "{value, select, male {He} female {She} other {They}} will respond shortly.", 4 | "selectordinal": "It's my cat's {value, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} birthday", 5 | "number": "The price is: {value, number, ::currency/EUR}", 6 | "date": "Today is: {value, date, FULL}" 7 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/[lang]/[...error]/+page.js: -------------------------------------------------------------------------------- 1 | import { setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Load} */ 4 | export const load = async ({ params }) => { 5 | const { error, lang } = params; 6 | 7 | let status = parseInt(error); 8 | 9 | if (Number.isNaN(status)) status = 404; 10 | 11 | await setLocale(lang); 12 | await setRoute('error'); 13 | 14 | return { 15 | status, 16 | }; 17 | }; -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 3 | } -------------------------------------------------------------------------------- /examples/parser-default/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | import preprocess from 'svelte-preprocess'; 4 | 5 | /** @type {import('@sveltejs/kit').Config} */ 6 | const config = { 7 | // Consult https://github.com/sveltejs/svelte-preprocess 8 | // for more information about preprocessors 9 | preprocess: preprocess(), 10 | 11 | kit: { 12 | adapter: adapter() 13 | } 14 | }; 15 | 16 | export default config; 17 | -------------------------------------------------------------------------------- /examples/parser-icu/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import adapter from '@sveltejs/adapter-netlify'; 3 | import preprocess from 'svelte-preprocess'; 4 | 5 | /** @type {import('@sveltejs/kit').Config} */ 6 | const config = { 7 | // Consult https://github.com/sveltejs/svelte-preprocess 8 | // for more information about preprocessors 9 | preprocess: preprocess(), 10 | 11 | kit: { 12 | adapter: adapter() 13 | } 14 | }; 15 | 16 | export default config; 17 | 18 | -------------------------------------------------------------------------------- /examples/locale-router/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { loadTranslations, translations } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, locals }) => { 5 | const { pathname } = url; 6 | const { lang } = locals; 7 | 8 | const route = pathname.replace(new RegExp(`^/${lang}`), ''); 9 | 10 | await loadTranslations(lang, route); 11 | 12 | return { i18n: { route, lang }, translations: translations.get() }; 13 | }; -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 3 | } -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { loadTranslations, translations } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, locals }) => { 5 | const { pathname } = url; 6 | const { lang } = locals; 7 | 8 | const route = pathname.replace(new RegExp(`^/${lang}`), ''); 9 | 10 | await loadTranslations(lang, route); 11 | 12 | return { i18n: { route, lang }, translations: translations.get() }; 13 | }; -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/cs/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "O této aplikaci", 3 | "text": "

Toto je SvelteKit aplikace. Můžete si vytvořit svou vlastní vložením následujícího příkazu do příkazové řádky:

npm init svelte@next

Tato stránka je čistě statické HTML, bez nutnosti klientské interakce. Díky tomu není potřeba načítat žádný JavaScript. Zkuste zobrazit drojový kód stránky, nebo otevřete vývojářské nástroje a znovu načtěte stránku.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/+layout.js: -------------------------------------------------------------------------------- 1 | import { setLocale, setRoute } from '$lib/translations'; 2 | 3 | export const prerender = true; 4 | 5 | /** @type { import('@sveltejs/kit').Load } */ 6 | export const load = async ({ url }) => { 7 | const { pathname } = url; 8 | 9 | const lang = `${pathname.match(/\w+?(?=\/|$)/) || ''}`; 10 | 11 | const route = pathname.replace(new RegExp(`^/${lang}`), ''); 12 | 13 | await setLocale(lang); 14 | await setRoute(route); 15 | 16 | return { route, lang }; 17 | }; -------------------------------------------------------------------------------- /examples/loaders/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "noImplicitReturns": true, 5 | "noUnusedLocals": true, 6 | "removeComments": true, 7 | "outDir": "lib", 8 | "sourceMap": false, 9 | "strict": true, 10 | "target": "es2020", 11 | "lib": ["ES2020"], 12 | "moduleResolution": "node", 13 | "noEmit": true, 14 | "resolveJsonModule": true, 15 | "allowSyntheticDefaultImports": true 16 | }, 17 | "include": [ 18 | "./src", 19 | "./*.js", 20 | "./*.ts" 21 | ] 22 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/en/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "About this app", 3 | "text": "

This is a SvelteKit app. You can make your own by typing the following into your command line and following the prompts:

npm init svelte@next

The page you're looking at is purely static HTML, with no client-side interactivity needed. Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening the devtools network panel and reloading.

" 4 | } -------------------------------------------------------------------------------- /examples/loaders/src/routes/about/+page.svelte: -------------------------------------------------------------------------------- 1 | 9 | 10 |

{$t('about.title')}

11 |

{@html $t('about.text')}

12 | 13 |
14 |
15 | 16 | 17 | 18 | {#if data.route === redirectedRoute} 19 |

{$t('more.content')}

20 | {/if} -------------------------------------------------------------------------------- /examples/loaders/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loaders", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/one-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "one-page", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/multi-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multi-page", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/parser-icu/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | {@render children()} 13 |
14 |
15 |
16 |
17 | 22 | -------------------------------------------------------------------------------- /examples/preprocess/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "preprocess", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /tests/data/translations/ku/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "no_placeholder": "NO_PLACEHOLDER", 3 | "placeholder": "VALUES: {{value}}, {{value;}}, {{ value }}, {{ value; }}", 4 | "modifier_test": "VALUES: {{value; option1:VALUE1; option2:VALUE2; default:DEFAULT VALUE;}}, {{ value ; option1 : VALUE1 ; option2 : VALUE2 ; default : DEFAULT VALUE ;}}", 5 | "custom_modifier": "{{date:date;}}", 6 | "modifier_number": "{{value:number;}}", 7 | "modifier_date": "{{value:date;}}", 8 | "modifier_ago": "{{value:ago;}}", 9 | "modifier_currency": "{{value:currency;}}" 10 | } -------------------------------------------------------------------------------- /examples/locale-param/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "locale-param", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/locale-router/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "locale-router", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/parser-default/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | {@render children()} 13 |
14 |
15 |
16 |
17 | 22 | -------------------------------------------------------------------------------- /tests/data/translations/zh-Hans/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "no_placeholder": "NO_PLACEHOLDER", 3 | "placeholder": "VALUES: {{value}}, {{value;}}, {{ value }}, {{ value; }}", 4 | "modifier_test": "VALUES: {{value; option1:VALUE1; option2:VALUE2; default:DEFAULT VALUE;}}, {{ value ; option1 : VALUE1 ; option2 : VALUE2 ; default : DEFAULT VALUE ;}}", 5 | "custom_modifier": "{{date:date;}}", 6 | "modifier_number": "{{value:number;}}", 7 | "modifier_date": "{{value:date;}}", 8 | "modifier_ago": "{{value:ago;}}", 9 | "modifier_currency": "{{value:currency;}}" 10 | } -------------------------------------------------------------------------------- /examples/fallback-locale/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fallback-locale", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/single-load/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "single-load", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/loaders/src/routes/+server.js: -------------------------------------------------------------------------------- 1 | import { defaultLocale } from '$lib/translations'; 2 | import { json } from '@sveltejs/kit'; 3 | 4 | import { default as cs } from '$lib/translations/cs/home.json'; 5 | import { default as en } from '$lib/translations/en/home.json'; 6 | 7 | const translations = { cs, en }; 8 | 9 | /** @type {import('./home/$types').RequestHandler} */ 10 | export async function GET({ url }) { 11 | const lang = url.searchParams.get('lang') || defaultLocale; 12 | 13 | const translation = translations[lang]; 14 | 15 | return json(translation); 16 | } -------------------------------------------------------------------------------- /examples/component-scoped-csr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "component-scoped-csr", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "component-scoped-ssr", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/locale-router-static/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../../ && pnpm install && pnpm run build && pnpm --filter locale-router-static run build" 3 | publish = "build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "22" 7 | 8 | [[redirects]] 9 | from = "/*" 10 | to = "/cs/:splat" 11 | status = 302 12 | conditions = {Language = ["cs"]} 13 | 14 | [[redirects]] 15 | from = "/*" 16 | to = "/de/:splat" 17 | status = 302 18 | conditions = {Language = ["de"]} 19 | 20 | [[redirects]] 21 | from = "/*" 22 | to = "/en/:splat" 23 | status = 302 -------------------------------------------------------------------------------- /examples/locale-router-advanced/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "locale-router-advanced", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-netlify": "^5.2.4", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/locale-router-static/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "locale-router-static", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "sveltekit-i18n": "workspace:*" 13 | }, 14 | "devDependencies": { 15 | "@sveltejs/adapter-static": "^3.0.8", 16 | "@sveltejs/kit": "^2.47.1", 17 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 18 | "svelte": "^5.41.0", 19 | "vite": "^7.1.10" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/locale-router/src/lib/translations/de/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Über diese App", 3 | "text": "

Dies ist eine SvelteKit-App. Sie können Ihre eigene erstellen, indem Sie Folgendes in Ihre Befehlszeile eingeben und den Eingabeaufforderungen folgen:

npm init svelte@next

Die Seite, die Sie sich ansehen, ist rein statisches HTML mit keine clientseitige Interaktivität erforderlich. Aus diesem Grund müssen wir kein JavaScript laden. Versuchen Sie, die Quelle der Seite anzuzeigen oder das devtools-Netzwerkfenster zu öffnen und neu zu laden.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/de/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Über diese App", 3 | "text": "

Dies ist eine SvelteKit-App. Sie können Ihre eigene erstellen, indem Sie Folgendes in Ihre Befehlszeile eingeben und den Eingabeaufforderungen folgen:

npm init svelte@next

Die Seite, die Sie sich ansehen, ist rein statisches HTML mit keine clientseitige Interaktivität erforderlich. Aus diesem Grund müssen wir kein JavaScript laden. Versuchen Sie, die Quelle der Seite anzuzeigen oder das devtools-Netzwerkfenster zu öffnen und neu zu laden.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/translations/de/about.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Über diese App", 3 | "text": "

Dies ist eine SvelteKit-App. Sie können Ihre eigene erstellen, indem Sie Folgendes in Ihre Befehlszeile eingeben und den Eingabeaufforderungen folgen:

npm init svelte@next

Die Seite, die Sie sich ansehen, ist rein statisches HTML mit keine clientseitige Interaktivität erforderlich. Aus diesem Grund müssen wir kein JavaScript laden. Versuchen Sie, die Quelle der Seite anzuzeigen oder das devtools-Netzwerkfenster zu öffnen und neu zu laden.

" 4 | } -------------------------------------------------------------------------------- /examples/locale-router/README.md: -------------------------------------------------------------------------------- 1 | # Locale-router 2 | This app shows how to integrate locale routing using dynamic adapters (e.g. `@sveltejs/adapter-node`). It includes two pages and three language mutations (`en`, `de`, `cs`). Error pages are included as well. 3 | 4 | ## How to use this example 5 | 6 | - Download this example 7 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 8 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) 9 | 10 | ## Setup 11 | 12 | ### `./src/hooks.server.js` 13 | Takes care about redirects to appropriate language mutation. -------------------------------------------------------------------------------- /examples/fallback-locale/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/897bc245-3432-44a8-8a4b-26c6a61f2d5f/deploy-status)](https://app.netlify.com/sites/fallback-locale/deploys) 2 | 3 | # Fallback locale 4 | This app shows how to use `config.fallbackLocale` parameter. 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://fallback-locale.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /tsup.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig( 4 | /** @type {() => import('tsup').Options} */ 5 | (options) => [ 6 | { 7 | clean: true, 8 | dts: true, 9 | format: ['esm'], 10 | entry: ['src/index.ts'], 11 | minify: !options.watch, 12 | sourcemap: options.watch, 13 | splitting: true, 14 | }, 15 | { 16 | clean: false, 17 | dts: false, 18 | format: ['cjs'], 19 | entry: ['src/index.ts'], 20 | minify: !options.watch, 21 | sourcemap: options.watch, 22 | splitting: true, 23 | }, 24 | ], 25 | ); -------------------------------------------------------------------------------- /examples/preprocess/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/4aa31aaf-e010-423e-8a3d-36ca6d224882/deploy-status)](https://app.netlify.com/sites/preprocess-example/deploys) 2 | 3 | # Preprocess 4 | This app demonstrates behavior of `preprocess` config prop on multiple `i18n` instances. 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://preprocess-example.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/locale-router-static/svelte.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | import adapter from '@sveltejs/adapter-static'; 4 | import lang from './src/lib/translations/lang.js'; 5 | 6 | const supportedLocales = Object.keys(lang); 7 | 8 | /** @type {import('@sveltejs/kit').Config} */ 9 | const config = { 10 | kit: { 11 | adapter: adapter(), 12 | prerender: { 13 | // NOTE: You can modify your exported error pages here. 14 | entries: supportedLocales.reduce((acc, locale) => [...acc, `/${locale}`, `/${locale}/401`, `/${locale}/403`, `/${locale}/404`, `/${locale}/500`], ['*']), 15 | }, 16 | }, 17 | }; 18 | 19 | export default config; 20 | -------------------------------------------------------------------------------- /examples/locale-param/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/bea2dd0c-89ec-4fcc-87c7-86192d1fe48d/deploy-status)](https://app.netlify.com/sites/locale-param/deploys) 2 | 3 | # Locale-param 4 | This `multi-page` app demonstrates lang routing based on URL parameter (e.g. `https://example.com/?lang=en`). 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://locale-param.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/index.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
12 | {JSON.stringify($translations)} 13 |

{$t('common.info')}

14 | 15 | 20 |
21 | 22 | 29 | -------------------------------------------------------------------------------- /examples/loaders/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/08c1c114-2b6b-4fb9-b6dc-5049e783f5e0/deploy-status)](https://app.netlify.com/sites/loaders-example/deploys) 2 | 3 | # Loaders example 4 | This demo shows different `config.loaders` in action. It covers importing translation definitions from JSON files as well as fetching it from API server. 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://loaders-example.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/preprocess/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import translations from './translations'; 3 | 4 | /** @type {import('sveltekit-i18n').Config} */ 5 | const config = { 6 | initLocale: 'en', 7 | translations, 8 | }; 9 | 10 | export const full = new i18n({ 11 | ...config, 12 | preprocess: 'full', // default 13 | }); 14 | 15 | export const preserveArrays = new i18n({ 16 | ...config, 17 | preprocess: 'preserveArrays', 18 | }); 19 | 20 | export const none = new i18n({ 21 | ...config, 22 | preprocess: 'none', 23 | }); 24 | 25 | export const custom = new i18n({ 26 | ...config, 27 | preprocess: (input) => JSON.parse(JSON.stringify(input).replaceAll(':)', '🙂')), 28 | }); -------------------------------------------------------------------------------- /examples/single-load/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/ad81521b-7293-400b-8709-e9b874c884ff/deploy-status)](https://app.netlify.com/sites/single-load/deploys) 2 | 3 | # Single-load app 4 | In this app, all translations are loaded by default. 5 | 6 | It's useful in case all language mutations are used within the app or if you are using SvelteKit's `adapter-static`. 7 | 8 | ## Preview 9 | You can view this demo live on [Netlify](https://single-load.netlify.app). 10 | 11 | ## How to use this example 12 | 13 | - Download this example 14 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 15 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/locale-param/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies }) => { 5 | const { pathname, searchParams } = url; 6 | 7 | const initLocale = searchParams.get('lang') || cookies.get('locale') || defaultLocale; 8 | 9 | cookies.set('locale', initLocale); 10 | 11 | await loadTranslations(initLocale, pathname); // keep this just before the `return` 12 | 13 | return { 14 | i18n: { locale: initLocale, route: pathname }, 15 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 16 | }; 17 | }; -------------------------------------------------------------------------------- /examples/one-page/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/ffa0f443-e517-4e1d-ad88-abdbbfa0e30c/deploy-status)](https://app.netlify.com/sites/one-page-example/deploys) 2 | 3 | # One-page app 4 | In this app, all translations for given locale (`config.initLocale`) are loaded during initialization. Other mutations are loaded on `$locale` change. 5 | 6 | This concept is great for one-page apps. 7 | 8 | ## Preview 9 | You can view this demo live on [Netlify](https://one-page-example.netlify.app). 10 | 11 | ## How to use this example 12 | 13 | - Download this example 14 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 15 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/one-page/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 14 | {$t('menu.notification', { count })}
15 | 16 | 17 |
18 | 19 | {@render children()} 20 |
21 |
22 |
23 |
24 | 29 | -------------------------------------------------------------------------------- /examples/preprocess/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {@render children()} 20 |
21 |
22 |
23 |
24 | 29 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import { dev } from '$app/environment'; 2 | import i18n from 'sveltekit-i18n'; 3 | import en from './en'; 4 | import de from './de'; 5 | import cs from './cs'; 6 | import lang from './lang'; 7 | 8 | /** @type {import('sveltekit-i18n').Config} */ 9 | const config = { 10 | log: { 11 | level: dev ? 'warn' : 'error', 12 | }, 13 | translations: { 14 | en: { 15 | ...en, 16 | lang, 17 | }, 18 | de: { 19 | ...de, 20 | lang, 21 | }, 22 | cs: { 23 | ...cs, 24 | lang, 25 | }, 26 | }, 27 | }; 28 | 29 | export const defaultLocale = 'en'; 30 | 31 | export const { t, locale, locales, loading, setLocale, setRoute, translations } = new i18n(config); 32 | -------------------------------------------------------------------------------- /examples/parser-icu/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/cd425de0-b200-4a6a-8ab6-68cf34b8b6c7/deploy-status)](https://app.netlify.com/sites/parser-icu/deploys) 2 | 3 | # @sveltekit-i18n/parser-icu 4 | This app demonstrates features of the [@sveltekit-i18n/parser-icu](https://github.com/sveltekit-i18n/parsers/blob/master/parser-icu). 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://parser-icu.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `cd ./parser-icu/` in Terminal to navigate to example's folder 13 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 14 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) 15 | -------------------------------------------------------------------------------- /examples/single-load/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | {$t('menu.notification', { count })}
16 | 17 | 18 |
19 | 20 | {@render children()} 21 |
22 |
23 |
24 |
25 | 30 | 31 | -------------------------------------------------------------------------------- /examples/parser-default/src/lib/translations/modifiers.ts: -------------------------------------------------------------------------------- 1 | import type { Modifier } from '@sveltekit-i18n/parser-default'; 2 | 3 | export const test: Modifier.T = ({ value, defaultValue }) => `${value || defaultValue} 🥳`; 4 | 5 | export const eqAbs: Modifier.T = ({ value, options, defaultValue }) => options.find(({ key }) => Math.abs(+key) === Math.abs(value))?.value || defaultValue; 6 | 7 | export type CurrencyProps = { currency?: Intl.NumberFormatOptions & { ratio?: number } }; 8 | 9 | export const currency: Modifier.T = ({ value, props, defaultValue, locale }) => { 10 | const { ratio = 1, currency } = props?.currency || {}; 11 | 12 | return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(ratio * (value || defaultValue)); 13 | }; 14 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import Base from '@sveltekit-i18n/base'; 2 | import parser from '@sveltekit-i18n/parser-default'; 3 | 4 | import type { Parser, Modifier } from '@sveltekit-i18n/parser-default'; 5 | import type { Config } from './types'; 6 | 7 | export type { Config, Parser, Modifier }; 8 | 9 | const normalizeConfig =

({ parserOptions = {}, ...rest }: Config) => ({ 10 | ...rest, 11 | parser: parser(parserOptions), 12 | }); 13 | 14 | class I18n, P = Parser.PayloadDefault, M = Modifier.DefaultProps> extends Base { 15 | constructor(config?: Config) { 16 | super(config && normalizeConfig(config)); 17 | } 18 | 19 | loadConfig = (config: Config) => super.configLoader(normalizeConfig(config)); 20 | } 21 | 22 | export default I18n; 23 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | workflow_call: 5 | workflow_dispatch: 6 | pull_request: 7 | types: [opened,reopened,synchronize] 8 | push: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | Tests: 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | node-version: [22] 18 | os: [ubuntu-latest, windows-latest, macOS-latest] 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | 23 | - uses: pnpm/action-setup@v2 24 | with: 25 | version: 10 26 | 27 | - uses: actions/setup-node@v3 28 | with: 29 | node-version: ${{ matrix.node-version }} 30 | cache: 'pnpm' 31 | 32 | - name: Install Dependencies 33 | run: pnpm install 34 | 35 | - run: pnpm run test 36 | env: 37 | tests: true 38 | -------------------------------------------------------------------------------- /examples/multi-page/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/c5bbe5c2-c9b9-4175-aa68-fd4aec778589/deploy-status)](https://app.netlify.com/sites/multi-page-example/deploys) 2 | 3 | # Multi-page app 4 | In this app, translations are loaded dynamically according to user navigation and `$locale` change. It has built-in mechanism to prevent duplicit (server and client) translation load on app enter. It's useful, when you are fetching your translations from remote API, or using other data-expensive solution. 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://multi-page-example.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 24 | 25 |

{$t('home.title')}

26 |

{@html $t('home.text', { link })}

27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/preprocess/src/lib/translations/translations.js: -------------------------------------------------------------------------------- 1 | import lang from './lang.json'; 2 | 3 | export default ({ 4 | en: { 5 | lang, 6 | content: [ 7 | { 8 | title: 'Welcome to SvelteKit! :)', 9 | text: 'Visit kit.svelte.dev to read the documentation', 10 | something: { else: ':)' }, 11 | }, 12 | { 13 | title: 'Some additional info...', 14 | text: ':) :) :)', 15 | something: { else: ':O' }, 16 | }, 17 | ], 18 | }, 19 | cs: { 20 | lang, 21 | content: [ 22 | { 23 | title: 'Vítejte ve SvelteKit! :)', 24 | text: 'Dokumentace je k přečtení na kit.svelte.dev', 25 | something: { else: ':)' }, 26 | }, 27 | { 28 | title: 'Nějaké další informace...', 29 | text: ':) :) :)', 30 | something: { else: ':O' }, 31 | }, 32 | ], 33 | }, 34 | }); -------------------------------------------------------------------------------- /examples/component-scoped-csr/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/7e679fc0-9808-4677-be27-fdeccdd6449f/deploy-status)](https://app.netlify.com/sites/component-scoped-csr/deploys) 2 | 3 | # Component-scoped app 4 | This app includes multiple instances of `sveltekit-i18n`. 5 | 6 | - app translations are loaded using SSR 7 | - component's translations are loaded in component promise (CSR - SvelteKit does not provide server side load method for components, so translation loaders are triggered on client side only) 8 | 9 | This approach is good for more complex apps. 10 | 11 | ## Preview 12 | You can view this demo live on [Netlify](https://component-scoped-csr.netlify.app). 13 | 14 | ## How to use this example 15 | 16 | - Download this example 17 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 18 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) 19 | -------------------------------------------------------------------------------- /tests/data/translations/index.ts: -------------------------------------------------------------------------------- 1 | import { toDotNotation } from '../../utils'; 2 | 3 | import { default as common } from './en/common.json'; 4 | import { default as route } from './en/route.json'; 5 | import { default as common_ku } from './ku/common.json'; 6 | import { default as common_zhHans } from './zh-Hans/common.json'; 7 | 8 | export default (preprocess = 'full') => { 9 | const en = { 10 | common, 11 | route1: route, 12 | route2: route, 13 | }; 14 | 15 | const zhHans = { 16 | common: common_zhHans, 17 | }; 18 | 19 | const ku = { 20 | common: common_ku, 21 | }; 22 | 23 | return ({ 24 | en: preprocess === 'none' ? en : toDotNotation(en, preprocess === 'preserveArays'), 25 | 'zh-Hans': preprocess === 'none' ? zhHans : toDotNotation(zhHans, preprocess === 'preserveArays'), 26 | ku: preprocess === 'none' ? ku : toDotNotation(ku, preprocess === 'preserveArays'), 27 | }) as Record; 28 | }; -------------------------------------------------------------------------------- /examples/fallback-locale/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { locales, loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies }) => { 5 | const { pathname } = url; 6 | 7 | // Try to get the locale from cookie 8 | let locale = (cookies.get('lang') || '').toLowerCase(); 9 | 10 | // Get defined locales 11 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 12 | 13 | // Use default locale if current locale is not supported 14 | if (!supportedLocales.includes(locale)) { 15 | locale = defaultLocale; 16 | } 17 | 18 | await loadTranslations(locale, pathname); // keep this just before the `return` 19 | 20 | return { 21 | i18n: { locale, route: pathname }, 22 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 23 | }; 24 | }; -------------------------------------------------------------------------------- /examples/parser-icu/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "parser-icu", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview", 10 | "check": "svelte-check --tsconfig ./tsconfig.json", 11 | "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch" 12 | }, 13 | "dependencies": { 14 | "@sveltekit-i18n/base": "^1.0.0", 15 | "@sveltekit-i18n/parser-icu": "^1.0.0" 16 | }, 17 | "devDependencies": { 18 | "@sveltejs/adapter-netlify": "^5.2.4", 19 | "@sveltejs/kit": "^2.47.1", 20 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 21 | "svelte": "^5.41.0", 22 | "svelte-check": "^3.4.5", 23 | "svelte-preprocess": "^5.0.4", 24 | "tslib": "^2.3.1", 25 | "typescript": "^5.1.6", 26 | "vite": "^7.1.10" 27 | }, 28 | "peerDependencies": { 29 | "sveltekit-i18n": "workspace:*" 30 | } 31 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.svelte-kit 2 | **/.netlify 3 | **/package 4 | **/build 5 | /lib 6 | /types 7 | 8 | .env 9 | .vscode 10 | 11 | # These are some examples of commonly ignored file patterns. 12 | # You should customize this list as applicable to your project. 13 | # Learn more about .gitignore: 14 | # https://www.atlassian.com/git/tutorials/saving-changes/gitignore 15 | 16 | # Node artifact files 17 | node_modules/ 18 | 19 | # Compiled Java class files 20 | *.class 21 | 22 | # Compiled Python bytecode 23 | *.py[cod] 24 | 25 | # Log files 26 | *.log 27 | 28 | # Package files 29 | *.jar 30 | 31 | # Maven 32 | target/ 33 | dist/ 34 | 35 | # JetBrains IDE 36 | .idea/ 37 | 38 | # Unit test reports 39 | TEST*.xml 40 | 41 | # Generated by MacOS 42 | .DS_Store 43 | 44 | # Generated by Windows 45 | Thumbs.db 46 | 47 | # Applications 48 | *.app 49 | *.exe 50 | *.war 51 | 52 | # Large media files 53 | *.tiff 54 | *.avi 55 | *.flv 56 | *.mov 57 | *.wmv 58 | 59 | -------------------------------------------------------------------------------- /examples/parser-default/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "parser-default", 3 | "private": true, 4 | "version": "0.0.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite dev", 8 | "build": "vite build", 9 | "preview": "vite preview", 10 | "check": "svelte-check --tsconfig ./tsconfig.json", 11 | "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch" 12 | }, 13 | "dependencies": { 14 | "@sveltekit-i18n/base": "^1.0.0", 15 | "@sveltekit-i18n/parser-default": "^1.0.0" 16 | }, 17 | "devDependencies": { 18 | "@sveltejs/adapter-netlify": "^5.2.4", 19 | "@sveltejs/kit": "^2.47.1", 20 | "@sveltejs/vite-plugin-svelte": "^6.2.1", 21 | "svelte": "^5.41.0", 22 | "svelte-check": "^3.4.5", 23 | "svelte-preprocess": "^5.0.4", 24 | "tslib": "^2.3.1", 25 | "typescript": "^5.1.6", 26 | "vite": "^7.1.10" 27 | }, 28 | "peerDependencies": { 29 | "sveltekit-i18n": "workspace:*" 30 | } 31 | } -------------------------------------------------------------------------------- /examples/component-scoped-ssr/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/7b79a988-ea49-40a0-bad9-842312b1c647/deploy-status)](https://app.netlify.com/sites/component-scoped-ssr/deploys) 2 | 3 | # Component-scoped app (SSR) 4 | This app includes multiple instances of `sveltekit-i18n`. 5 | 6 | - SvelteKit does not provide server side load method for components. 7 | - component's `load` in this example is replaced by exported init method. This method initializes related language mutation within parent page's `load` method. 8 | - after the load, appropriate props are delegated back to the component instance. 9 | 10 | This approach is good for more complex apps. 11 | 12 | ## Preview 13 | You can view this demo live on [Netlify](https://component-scoped-ssr.netlify.app). 14 | 15 | ## How to use this example 16 | 17 | - Download this example 18 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 19 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) -------------------------------------------------------------------------------- /examples/loaders/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {$t('menu.home')} 20 | {$t('menu.about')} 21 |
22 |
23 | {$t('menu.notification', { count })}
24 | 25 | 26 |
27 | {@render children()} 28 |
29 |
30 |
31 |
32 | 37 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb-typescript/base", 4 | "plugin:svelte/recommended" 5 | ], 6 | "parser": "@typescript-eslint/parser", 7 | "parserOptions": { 8 | "project": "**/tsconfig.json", 9 | "sourceType": "module", 10 | "extraFileExtensions": [ 11 | ".svelte" 12 | ] 13 | }, 14 | "plugins": [ 15 | "import" 16 | ], 17 | "overrides": [ 18 | { 19 | "files": [ 20 | "*.svelte" 21 | ], 22 | "parser": "svelte-eslint-parser", 23 | "parserOptions": { 24 | "parser": "@typescript-eslint/parser" 25 | } 26 | } 27 | ], 28 | "rules": { 29 | "no-console": 0, 30 | "@typescript-eslint/naming-convention": 0, 31 | "@typescript-eslint/no-redeclare": 0, 32 | "@typescript-eslint/no-shadow": 0, 33 | "no-trailing-spaces": "error", 34 | "no-multiple-empty-lines": "error", 35 | "import/extensions": 0, 36 | "import/no-extraneous-dependencies": 0, 37 | "svelte/no-at-html-tags": 0 38 | }, 39 | "settings": {} 40 | } -------------------------------------------------------------------------------- /examples/multi-page/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {$t('menu.home')} 20 | {$t('menu.about')} 21 |
22 |
23 | {$t('menu.notification', { count })}
24 | 25 | 26 |
27 | {@render children()} 28 |
29 |
30 |
31 |
32 | 37 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | /** @type {import('sveltekit-i18n').Config} */ 5 | export const config = { 6 | loaders: [ 7 | { 8 | locale: 'en', 9 | key: 'lang', 10 | loader: () => lang, 11 | }, 12 | { 13 | locale: 'en', 14 | key: 'common', 15 | loader: async () => (await import('./en/common.json')).default, 16 | }, 17 | { 18 | locale: 'cs', 19 | key: 'lang', 20 | loader: () => lang, 21 | }, 22 | { 23 | locale: 'cs', 24 | key: 'common', 25 | loader: async () => (await import('./cs/common.json')).default, 26 | }, 27 | { 28 | locale: 'de', 29 | key: 'lang', 30 | loader: () => lang, 31 | }, 32 | { 33 | locale: 'de', 34 | key: 'common', 35 | loader: async () => (await import('./de/common.json')).default, 36 | }, 37 | ], 38 | }; 39 | 40 | export default () => new i18n(config); -------------------------------------------------------------------------------- /examples/fallback-locale/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {$t('menu.home')} 20 | {$t('menu.about')} 21 |
22 |
23 | {$t('menu.notification', { count })}
24 | 25 | 26 |
27 | {@render children()} 28 |
29 |
30 |
31 |
32 | 37 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {$t('menu.home')} 20 | {$t('menu.about')} 21 |
22 |
23 | {$t('menu.notification', { count })}
24 | 25 | 26 |
27 | {@render children()} 28 |
29 |
30 |
31 |
32 | 37 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | {$t('menu.home')} 20 | {$t('menu.about')} 21 |
22 |
23 | {$t('menu.notification', { count })}
24 | 25 | 26 |
27 | {@render children()} 28 |
29 |
30 |
31 |
32 | 37 | -------------------------------------------------------------------------------- /examples/locale-param/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | {$t('menu.home')} 17 | {$t('menu.about')} 18 |
19 |
20 | {$t('menu.notification', { count })}
21 | 22 | 23 |
24 | {@render children()} 25 |
26 |
27 |
28 |
29 | 34 | -------------------------------------------------------------------------------- /examples/parser-icu/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | 16 | 17 | 18 |
19 | 20 |

{$t('content.plural', { value: number })}

21 |

{$t('content.number', { value: number * currencyRatio[$locale] })}

22 |

{$t('content.date', { value: now }, { date: { FULL:{ timeStyle: 'full', dateStyle: 'full' } } })}

23 |

{$t('content.selectordinal', { value: number })}

24 | 25 |
26 |
27 | {$t('content.select', { value: gender })}
28 |
-------------------------------------------------------------------------------- /examples/one-page/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | /** @type {import('sveltekit-i18n').Config} */ 5 | export const config = { 6 | translations: { 7 | en: { lang }, 8 | cs: { lang }, 9 | }, 10 | loaders: [ 11 | { 12 | locale: 'en', 13 | key: 'menu', 14 | loader: async () => (await import('./en/menu.json')).default, 15 | }, 16 | { 17 | locale: 'en', 18 | key: 'content', 19 | loader: async () => (await import('./en/content.json')).default, 20 | }, 21 | { 22 | locale: 'cs', 23 | key: 'menu', 24 | loader: async () => (await import('./cs/menu.json')).default, 25 | }, 26 | { 27 | locale: 'cs', 28 | key: 'content', 29 | loader: async () => (await import('./cs/content.json')).default, 30 | }, 31 | ], 32 | }; 33 | 34 | export const { t, loading, locales, locale, loadTranslations } = new i18n(config); 35 | 36 | loading.subscribe(($loading) => $loading && console.log('Loading translations...')); -------------------------------------------------------------------------------- /examples/locale-router/src/routes/[lang]/+layout.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | {$t('menu.home')} 19 | {$t('menu.about')} 20 |
21 |
22 | {$t('menu.notification', { count })}
23 | 24 | 25 |
26 | {@render children()} 27 |
28 |
29 |
30 |
31 | 36 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/component/index.svelte: -------------------------------------------------------------------------------- 1 | 18 | 19 |
20 | {JSON.stringify($translations)} 21 | {#await promise} 22 | Loading... 23 | {:then} 24 |

{$t('common.info')}

25 | 26 | 31 | {/await} 32 |
33 | 34 | 41 | -------------------------------------------------------------------------------- /examples/single-load/src/lib/translations/translations.js: -------------------------------------------------------------------------------- 1 | import lang from './lang.json'; 2 | 3 | export default ({ 4 | en: { 5 | lang, 6 | menu: { 7 | notification: 'You have {{count:gt; 0:{{count}} new {{count; 1:message; default:messages}}!; default:no messages...}}', 8 | }, 9 | content: { 10 | title: 'Welcome to SvelteKit', 11 | info: 'You can now access all your language mutations using {$l(LOCALE, TRANSLATION_KEY)}:', 12 | text: 'Visit kit.svelte.dev to read the documentation', 13 | }, 14 | }, 15 | cs: { 16 | lang, 17 | menu: { 18 | notification: '{{count:gt; 0:Máte {{count}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}', 19 | }, 20 | content: { 21 | title: 'Vítejte ve SvelteKit', 22 | info: 'Nyní máte přístup ke všem jazykovým mutacím prostřednictvím {$l(LOCALE, TRANSLATION_KEY)}:', 23 | text: 'Dokumentace je k přečtení na kit.svelte.dev', 24 | }, 25 | }, 26 | }); -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/routes/[...lang=locale]/+layout.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | {$t('menu.home')} 19 | {$t('menu.about')} 20 |
21 |
22 | {$t('menu.notification', { count })}
23 | 24 | 25 |
26 | {@render children()} 27 |
28 |
29 |
30 |
31 | 36 | -------------------------------------------------------------------------------- /tests/data/index.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from '../../src/types'; 2 | export { default as getTranslations } from './translations'; 3 | 4 | export const CONFIG: Config< 5 | {} /* Add your payload props here */, 6 | {} /* Add your modifier props here */ 7 | > = { 8 | initLocale: 'en', 9 | log: { 10 | level: 'error', 11 | }, 12 | loaders: [ 13 | { 14 | key: 'common', 15 | locale: 'EN', 16 | loader: async () => (await import('../data/translations/en/common.json')).default, 17 | }, 18 | { 19 | key: 'route1', 20 | locale: 'EN', 21 | routes: [/./], 22 | loader: async () => (await import('../data/translations/en/route.json')).default, 23 | }, 24 | { 25 | key: 'route2', 26 | locale: 'EN', 27 | routes: ['/path#hash?a=b&c=d'], 28 | loader: async () => (await import('../data/translations/en/route.json')).default, 29 | }, 30 | { 31 | key: 'common', 32 | locale: 'zh-Hans', 33 | loader: async () => (await import('../data/translations/zh-Hans/common.json')).default, 34 | }, 35 | ], 36 | }; -------------------------------------------------------------------------------- /examples/parser-icu/src/lib/translations/index.ts: -------------------------------------------------------------------------------- 1 | import i18n from '@sveltekit-i18n/base'; 2 | import parser from '@sveltekit-i18n/parser-icu'; 3 | 4 | import type { Config } from '@sveltekit-i18n/parser-icu'; 5 | 6 | import lang from './lang.json'; 7 | 8 | const config: Config<{/* Translation payload props */}> = { 9 | initLocale: 'en', 10 | 11 | parser: parser(), 12 | 13 | translations: { 14 | en: { lang }, 15 | cs: { lang }, 16 | }, 17 | 18 | loaders: [ 19 | { 20 | locale: 'en', 21 | key: 'content', 22 | loader: async () => (await import('./en/content.json')).default, 23 | }, 24 | { 25 | locale: 'cs', 26 | key: 'content', 27 | loader: async () => (await import('./cs/content.json')).default, 28 | }, 29 | ], 30 | }; 31 | 32 | export const { t, loading, locales, locale, translations } = new i18n(config); 33 | 34 | loading.subscribe(async ($loading) => { 35 | if ($loading) { 36 | console.log('Loading translations...'); 37 | await loading.toPromise(); 38 | console.log('Updated translations', translations.get()); 39 | } 40 | }); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 sveltekit-i18n 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { locales, loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies, request }) => { 5 | const { pathname } = url; 6 | 7 | // Try to get the locale from cookie 8 | let locale = (cookies.get('lang') || '').toLowerCase(); 9 | 10 | // Get user preferred locale 11 | if (!locale) { 12 | locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase(); 13 | } 14 | 15 | // Get defined locales 16 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 17 | 18 | // Use default locale if current locale is not supported 19 | if (!supportedLocales.includes(locale)) { 20 | locale = defaultLocale; 21 | } 22 | 23 | await loadTranslations(locale, pathname); // keep this just before the `return` 24 | 25 | return { 26 | i18n: { locale, route: pathname }, 27 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 28 | }; 29 | }; -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { locales, loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies, request }) => { 5 | const { pathname } = url; 6 | 7 | // Try to get the locale from cookie 8 | let locale = (cookies.get('lang') || '').toLowerCase(); 9 | 10 | // Get user preferred locale 11 | if (!locale) { 12 | locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase(); 13 | } 14 | 15 | // Get defined locales 16 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 17 | 18 | // Use default locale if current locale is not supported 19 | if (!supportedLocales.includes(locale)) { 20 | locale = defaultLocale; 21 | } 22 | 23 | await loadTranslations(locale, pathname); // keep this just before the `return` 24 | 25 | return { 26 | i18n: { locale, route: pathname }, 27 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 28 | }; 29 | }; -------------------------------------------------------------------------------- /examples/parser-default/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/61a65082-1dc8-4c2a-94f2-0334c005dad0/deploy-status)](https://app.netlify.com/sites/parser-default/deploys) 2 | 3 | # @sveltekit-i18n/parser-default 4 | This app demonstrates features of the [@sveltekit-i18n/parser-default](https://github.com/sveltekit-i18n/parsers/blob/master/parser-default). It includes an overview of [placeholders](https://github.com/sveltekit-i18n/parsers/blob/master/parser-default/README.md#placeholders), [built-in modifiers](https://github.com/sveltekit-i18n/parsers/blob/master/parser-default/README.md#modifiers) and [custom modifiers](https://github.com/sveltekit-i18n/parsers/blob/master/parser-default/README.md#options). 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://parser-default.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `cd ./parser-default/` in Terminal to navigate to example's folder 13 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 14 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) 15 | -------------------------------------------------------------------------------- /examples/loaders/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { locales, loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies, request }) => { 5 | const { pathname, search } = url; 6 | 7 | // Try to get the locale from cookie 8 | let locale = (cookies.get('lang') || '').toLowerCase(); 9 | 10 | // Get user preferred locale 11 | if (!locale) { 12 | locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase(); 13 | } 14 | 15 | // Get defined locales 16 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 17 | 18 | // Use default locale if current locale is not supported 19 | if (!supportedLocales.includes(locale)) { 20 | locale = defaultLocale; 21 | } 22 | 23 | const route = `${pathname}${search}`; 24 | 25 | await loadTranslations(locale, route); // keep this just before the `return` 26 | 27 | return { 28 | i18n: { locale, route }, 29 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 30 | }; 31 | }; -------------------------------------------------------------------------------- /examples/locale-router-static/src/routes/[lang]/+layout.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | {$t('menu.home')} 19 | {$t('menu.about')} 20 |
21 |
22 | {$t('menu.notification', { count })}
23 | 24 | 25 |
26 | {@render children()} 27 |
28 |
29 |
30 |
31 | 41 | -------------------------------------------------------------------------------- /tests/utils/index.ts: -------------------------------------------------------------------------------- 1 | export const filterTranslationKeys = (localeTranslation: any, keys: string[]) => keys.reduce((a, key) => ({ 2 | ...a, 3 | ...Object.keys(localeTranslation).filter((k: string) => `${k}`.startsWith(`${key}.`)).reduce((acc, k) => ({ ...acc, [k]: localeTranslation[k] }), {}), 4 | }), 5 | {}, 6 | ); 7 | 8 | export module DotNotation { 9 | export type Input = Record | null | undefined | any; 10 | 11 | export type Output = { [P in K]?: V[K] }; 12 | 13 | export type T = (input: I, preserveArrays?: boolean, parentKey?: string) => Output; 14 | } 15 | 16 | export const toDotNotation: DotNotation.T = (input, preserveArrays, parentKey) => Object.keys(input || {}).reduce((acc, key) => { 17 | const value = (input as any)[key]; 18 | const outputKey = parentKey ? `${parentKey}.${key}` : `${key}`; 19 | 20 | if (preserveArrays && Array.isArray(value)) return ({ ...acc, [outputKey]: value.map(v => toDotNotation(v, preserveArrays)) }); 21 | 22 | if (value && typeof value === 'object') return ({ ...acc, ...toDotNotation(value, preserveArrays, outputKey) }); 23 | 24 | return ({ ...acc, [outputKey]: value }); 25 | }, {}); -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/component/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | /** @type {import('sveltekit-i18n').Config} */ 5 | export const config = { 6 | loaders: [ 7 | { 8 | locale: 'en', 9 | key: 'lang', 10 | loader: () => lang, 11 | }, 12 | { 13 | locale: 'en', 14 | key: 'common', 15 | loader: async () => (await import('./en/common.json')).default, 16 | }, 17 | { 18 | locale: 'cs', 19 | key: 'lang', 20 | loader: () => lang, 21 | }, 22 | { 23 | locale: 'cs', 24 | key: 'common', 25 | loader: async () => (await import('./cs/common.json')).default, 26 | }, 27 | { 28 | locale: 'de', 29 | key: 'lang', 30 | loader: () => lang, 31 | }, 32 | { 33 | locale: 'de', 34 | key: 'common', 35 | loader: async () => (await import('./de/common.json')).default, 36 | }, 37 | ], 38 | }; 39 | 40 | export default (initLocale) => { 41 | const instance = new i18n({ ...config, initLocale }); 42 | 43 | instance.loading.subscribe(($loading) => { 44 | if ($loading) console.log(`Loading translations for '${initLocale}' instance...`); 45 | }); 46 | 47 | return instance; 48 | }; -------------------------------------------------------------------------------- /examples/locale-router-advanced/README.md: -------------------------------------------------------------------------------- 1 | [![Netlify Status](https://api.netlify.com/api/v1/badges/bcefda87-9dad-4c73-bf5f-d9b4c03cac9c/deploy-status)](https://app.netlify.com/sites/locale-router-advanced/deploys) 2 | 3 | # Locale-router-advanced 4 | This app shows how to integrate locale routing using dynamic adapters (e.g. `@sveltejs/adapter-node`). It includes two pages and three language mutations (`en`, `de`, `cs`). Error pages are included as well. The default language (`en`) has no lang prefix in URL path. 5 | 6 | ## Preview 7 | You can view this demo live on [Netlify](https://locale-router-advanced.netlify.app). 8 | 9 | ## How to use this example 10 | 11 | - Download this example 12 | - Run `npm i` to install all dependencies (or `pnpm i`, `yarn`, etc.) 13 | - Run `npm run dev -- --open` to preview (or `pnpm run dev -- --open`, `yarn dev --open`, etc.) 14 | 15 | ## Noticeable files 16 | 17 | ### `./src/hooks.server.js` 18 | Takes care about redirects to appropriate language mutation. It fetches pages with the default language mutation on background, and serves it to the client with no lang prefix in the URL path. 19 | 20 | ### `./src/params/locale.js` (`./src/routes/[...lang=locale]`) 21 | Allows to pass only pages starting with locale or having no `path` (dafault lang index). -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: NPM Publish 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: 'Version' 8 | required: true 9 | default: 'patch' 10 | type: choice 11 | options: 12 | - patch 13 | - minor 14 | - major 15 | 16 | jobs: 17 | tests: 18 | uses: ./.github/workflows/tests.yml 19 | 20 | publish-npm: 21 | needs: tests 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v3 25 | 26 | - uses: pnpm/action-setup@v2 27 | with: 28 | version: 10 29 | 30 | - uses: actions/setup-node@v3 31 | with: 32 | node-version: 22 33 | registry-url: https://registry.npmjs.org/ 34 | cache: 'pnpm' 35 | 36 | - name: Install dependencies 37 | run: pnpm install 38 | 39 | - name: Update version 40 | run: | 41 | git config --local user.email "github-actions[bot]@users.noreply.github.com" 42 | git config --local user.name "github-actions[bot]" 43 | pnpm version ${{ inputs.version }} 44 | 45 | - name: Publish package 46 | env: 47 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 48 | run: pnpm publish 49 | 50 | - name: Push changes 51 | run: git push 52 | -------------------------------------------------------------------------------- /examples/parser-default/src/lib/translations/index.ts: -------------------------------------------------------------------------------- 1 | import i18n from '@sveltekit-i18n/base'; 2 | import parser from '@sveltekit-i18n/parser-default'; 3 | import type { Config } from '@sveltekit-i18n/parser-default'; 4 | // Or you could use `import i18n from 'sveltekit-i18n';` 5 | 6 | import lang from './lang.json'; 7 | import * as customModifiers from './modifiers'; 8 | import type { CurrencyProps } from './modifiers'; 9 | 10 | const config: Config< 11 | { 12 | placeholder?: string; 13 | value?: any; 14 | count?: number; 15 | }, /* Translation payload props */ 16 | CurrencyProps /* Modifier props */ 17 | > = { 18 | initLocale: 'en', 19 | 20 | parser: parser({ 21 | customModifiers, 22 | }), 23 | // Replace `parser` with `parserOptions` in case of `sveltekit-i18n` 24 | 25 | translations: { 26 | en: { lang }, 27 | cs: { lang }, 28 | }, 29 | loaders: [ 30 | { 31 | locale: 'en', 32 | key: 'content', 33 | loader: async () => (await import('./en/content.json')).default, 34 | }, 35 | { 36 | locale: 'cs', 37 | key: 'content', 38 | loader: async () => (await import('./cs/content.json')).default, 39 | }, 40 | ], 41 | }; 42 | 43 | export const { t, loading, locales, locale, translations } = new i18n(config); 44 | 45 | loading.subscribe(async ($loading) => { 46 | if ($loading) { 47 | console.log('Loading translations...'); 48 | await loading.toPromise(); 49 | console.log('Updated translations', translations.get()); 50 | } 51 | }); -------------------------------------------------------------------------------- /examples/locale-router/src/hooks.server.js: -------------------------------------------------------------------------------- 1 | import { defaultLocale, loadTranslations, locales } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Handle} */ 4 | export const handle = async ({ event, resolve }) => { 5 | const { url, request } = event; 6 | const { pathname } = url; 7 | 8 | // Get defined locales 9 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 10 | 11 | // Try to get locale from `pathname`. 12 | let locale = supportedLocales.find((l) => l === `${pathname.match(/[^/]+?(?=\/|$)/)}`.toLowerCase()); 13 | 14 | // If route locale is not supported 15 | if (!locale) { 16 | // Get user preferred locale 17 | locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase(); 18 | 19 | // Set default locale if user preferred locale does not match 20 | if (!supportedLocales.includes(locale)) locale = defaultLocale; 21 | 22 | // 301 redirect 23 | return new Response(undefined, { headers: { 'location': `/${locale}${pathname}` }, status: 301 }); 24 | } 25 | 26 | // Add html `lang` attribute 27 | return resolve({ ...event, locals: { lang: locale } }, { 28 | transformPageChunk: ({ html }) => html.replace(//, ``), 29 | }); 30 | }; 31 | 32 | 33 | /** @type {import('@sveltejs/kit').HandleServerError} */ 34 | export const handleError = async ({ event }) => { 35 | const { locals } = event; 36 | const { lang } = locals; 37 | 38 | await loadTranslations(lang, 'error'); 39 | 40 | return locals; 41 | }; -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | export const defaultLocale = 'en'; 5 | 6 | /** @type {import('sveltekit-i18n').Config} */ 7 | export const config = { 8 | translations: { 9 | en: { lang }, 10 | cs: { lang }, 11 | }, 12 | loaders: [ 13 | { 14 | locale: 'en', 15 | key: 'menu', 16 | loader: async () => (await import('./en/menu.json')).default, 17 | }, 18 | { 19 | locale: 'en', 20 | key: 'about', 21 | routes: ['/about'], 22 | loader: async () => (await import('./en/about.json')).default, 23 | }, 24 | { 25 | locale: 'en', 26 | key: 'home', 27 | routes: ['/'], 28 | loader: async () => (await import('./en/home.json')).default, 29 | }, 30 | { 31 | locale: 'cs', 32 | key: 'menu', 33 | loader: async () => (await import('./cs/menu.json')).default, 34 | }, 35 | { 36 | locale: 'cs', 37 | key: 'about', 38 | routes: ['/about'], 39 | loader: async () => (await import('./cs/about.json')).default, 40 | }, 41 | { 42 | locale: 'cs', 43 | key: 'home', 44 | routes: ['/'], 45 | loader: async () => (await import('./cs/home.json')).default, 46 | }, 47 | ], 48 | }; 49 | 50 | export const { t, loading, locales, locale, translations, loadTranslations, addTranslations, setLocale, setRoute } = new i18n(config); 51 | 52 | loading.subscribe(($loading) => $loading && console.log('Loading translations...')); -------------------------------------------------------------------------------- /examples/loaders/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/one-page/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/single-load/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo -------------------------------------------------------------------------------- /examples/locale-param/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/hooks.server.js: -------------------------------------------------------------------------------- 1 | import { defaultLocale, locales, setLocale, setRoute } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').Handle} */ 4 | export const handle = async ({ event, resolve }) => { 5 | const { url, request } = event; 6 | const { pathname } = url; 7 | 8 | // Get defined locales 9 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 10 | 11 | // Try to get locale from `pathname`. 12 | let locale = supportedLocales.find((l) => l === `${pathname.match(/[^/]+?(?=\/|$)/)}`.toLowerCase()); 13 | 14 | // If route locale is not supported 15 | if (!locale) { 16 | // Get user preferred locale 17 | locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase(); 18 | 19 | // Set default locale if user preferred locale does not match 20 | if (!supportedLocales.includes(locale)) locale = defaultLocale; 21 | 22 | // 301 redirect 23 | return new Response(undefined, { headers: { 'location': `/${locale}${pathname}` }, status: 301 }); 24 | } 25 | 26 | // Add html `lang` attribute 27 | return resolve({ ...event, locals: { lang: locale } }, { 28 | transformPageChunk: ({ html }) => html.replace(//, ``), 29 | }); 30 | }; 31 | 32 | /** @type {import('@sveltejs/kit').HandleServerError} */ 33 | export const handleError = async ({ event }) => { 34 | const { locals } = event; 35 | const { lang } = locals; 36 | 37 | await setLocale(lang); 38 | await setRoute('error'); 39 | 40 | return locals; 41 | }; -------------------------------------------------------------------------------- /examples/locale-router/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/multi-page/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/parser-icu/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/preprocess/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/parser-default/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/component-scoped-csr/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/component-scoped-ssr/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | export const defaultLocale = 'en'; 5 | 6 | /** @type {import('sveltekit-i18n').Config} */ 7 | export const config = { 8 | translations: { 9 | en: { lang }, 10 | cs: { lang }, 11 | }, 12 | loaders: [ 13 | { 14 | locale: 'en', 15 | key: 'menu', 16 | loader: async () => (await import('./en/menu.json')).default, 17 | }, 18 | { 19 | locale: 'en', 20 | key: 'about', 21 | routes: ['/about'], 22 | loader: async () => (await import('./en/about.json')).default, 23 | }, 24 | { 25 | locale: 'en', 26 | key: 'home', 27 | routes: ['/'], 28 | loader: async () => (await import('./en/home.json')).default, 29 | }, 30 | { 31 | locale: 'cs', 32 | key: 'menu', 33 | loader: async () => (await import('./cs/menu.json')).default, 34 | }, 35 | { 36 | locale: 'cs', 37 | key: 'about', 38 | routes: ['/about'], 39 | loader: async () => (await import('./cs/about.json')).default, 40 | }, 41 | { 42 | locale: 'cs', 43 | key: 'home', 44 | routes: ['/'], 45 | loader: async () => (await import('./cs/home.json')).default, 46 | }, 47 | ], 48 | }; 49 | 50 | export const { t, loading, locales, locale, loadTranslations, addTranslations, translations, setLocale, setRoute } = new i18n(config); 51 | 52 | loading.subscribe(($loading) => $loading && console.log('Loading translations for the main instance...')); -------------------------------------------------------------------------------- /examples/fallback-locale/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import lang from './lang.json'; 3 | 4 | export const defaultLocale = 'cs'; 5 | 6 | /** @type {import('sveltekit-i18n').Config} */ 7 | export const config = { 8 | fallbackLocale: 'en', 9 | translations: { 10 | en: { lang }, 11 | cs: { lang }, 12 | }, 13 | loaders: [ 14 | { 15 | locale: 'en', 16 | key: 'menu', 17 | loader: async () => (await import('./en/menu.json')).default, 18 | }, 19 | { 20 | locale: 'en', 21 | key: 'about', 22 | routes: ['/about'], 23 | loader: async () => (await import('./en/about.json')).default, 24 | }, 25 | { 26 | locale: 'en', 27 | key: 'home', 28 | routes: ['/'], 29 | loader: async () => (await import('./en/home.json')).default, 30 | }, 31 | { 32 | locale: 'cs', 33 | key: 'menu', 34 | loader: async () => (await import('./cs/menu.json')).default, 35 | }, 36 | { 37 | locale: 'cs', 38 | key: 'about', 39 | routes: ['/about'], 40 | loader: async () => (await import('./cs/about.json')).default, 41 | }, 42 | { 43 | locale: 'cs', 44 | key: 'home', 45 | routes: ['/'], 46 | loader: async () => (await import('./cs/home.json')).default, 47 | }, 48 | ], 49 | }; 50 | 51 | export const { t, loading, locales, locale, translations, loadTranslations, addTranslations, setLocale, setRoute } = new i18n(config); 52 | 53 | loading.subscribe(($loading) => $loading && console.log('Loading translations...')); -------------------------------------------------------------------------------- /examples/locale-router-advanced/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/locale-router-static/src/lib/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | svelte-logo 2 | -------------------------------------------------------------------------------- /examples/multi-page/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import { dev } from '$app/environment'; 3 | import lang from './lang.json'; 4 | 5 | export const defaultLocale = 'en'; 6 | 7 | /** @type {import('sveltekit-i18n').Config} */ 8 | export const config = { 9 | log: { 10 | level: dev ? 'warn' : 'error', 11 | }, 12 | translations: { 13 | en: { lang }, 14 | cs: { lang }, 15 | }, 16 | loaders: [ 17 | { 18 | locale: 'en', 19 | key: 'menu', 20 | loader: async () => (await import('./en/menu.json')).default, 21 | }, 22 | { 23 | locale: 'en', 24 | key: 'about', 25 | routes: ['/about'], 26 | loader: async () => (await import('./en/about.json')).default, 27 | }, 28 | { 29 | locale: 'en', 30 | key: 'home', 31 | routes: ['/'], 32 | loader: async () => (await import('./en/home.json')).default, 33 | }, 34 | { 35 | locale: 'cs', 36 | key: 'menu', 37 | loader: async () => (await import('./cs/menu.json')).default, 38 | }, 39 | { 40 | locale: 'cs', 41 | key: 'about', 42 | routes: ['/about'], 43 | loader: async () => (await import('./cs/about.json')).default, 44 | }, 45 | { 46 | locale: 'cs', 47 | key: 'home', 48 | routes: ['/'], 49 | loader: async () => (await import('./cs/home.json')).default, 50 | }, 51 | ], 52 | }; 53 | 54 | export const { t, loading, locales, locale, translations, loadTranslations, addTranslations, setLocale, setRoute } = new i18n(config); 55 | 56 | loading.subscribe(($loading) => $loading && console.log('Loading translations...')); -------------------------------------------------------------------------------- /examples/multi-page/src/routes/+layout.server.js: -------------------------------------------------------------------------------- 1 | import { locales, loadTranslations, translations, defaultLocale } from '$lib/translations'; 2 | 3 | /** @type {import('@sveltejs/kit').ServerLoad} */ 4 | export const load = async ({ url, cookies, request }) => { 5 | const { pathname } = url; 6 | 7 | // Try to get the locale from cookie 8 | let locale = (cookies.get('lang') || '').toLowerCase(); 9 | 10 | // Get user preferred locale 11 | if (!locale) { 12 | // If no cookie is set, try to determine the locale from the 'Accept-Language' header 13 | const acceptLanguageHeader = request.headers.get('accept-language') || ''; 14 | // Attempt to match the language code with optional region code 15 | let match = acceptLanguageHeader.match(/^[a-z]+(?=[-_])/i); 16 | 17 | // If no match is found, try to match just the language code 18 | if (!match) { 19 | match = acceptLanguageHeader.match(/^[a-z]+/i); 20 | } 21 | 22 | // If a match is found, use it as the locale, otherwise fall back to the default locale 23 | locale = match ? match[0].toLowerCase() : defaultLocale; 24 | } 25 | 26 | 27 | // Get defined locales 28 | const supportedLocales = locales.get().map((l) => l.toLowerCase()); 29 | 30 | // Use default locale if current locale is not supported 31 | if (!supportedLocales.includes(locale)) { 32 | locale = defaultLocale; 33 | } 34 | 35 | await loadTranslations(locale, pathname); // keep this just before the `return` 36 | 37 | return { 38 | i18n: { locale, route: pathname }, 39 | translations: translations.get(), // `translations` on server contain all translations loaded by different clients 40 | }; 41 | }; 42 | -------------------------------------------------------------------------------- /examples/locale-param/src/lib/translations/index.js: -------------------------------------------------------------------------------- 1 | import i18n from 'sveltekit-i18n'; 2 | import { dev } from '$app/environment'; 3 | import lang from './lang.json'; 4 | 5 | export const defaultLocale = 'en'; 6 | 7 | /** @type {import('sveltekit-i18n').Config} */ 8 | export const config = { 9 | log: { 10 | level: dev ? 'warn' : 'error', 11 | }, 12 | translations: { 13 | en: { lang }, 14 | cs: { lang }, 15 | }, 16 | loaders: [ 17 | { 18 | locale: 'en', 19 | key: 'menu', 20 | loader: async () => (await import('./en/menu.json')).default, 21 | }, 22 | { 23 | locale: 'en', 24 | key: 'about', 25 | routes: ['/about'], 26 | loader: async () => (await import('./en/about.json')).default, 27 | }, 28 | { 29 | locale: 'en', 30 | key: 'home', 31 | routes: ['/'], 32 | loader: async () => (await import('./en/home.json')).default, 33 | }, 34 | { 35 | locale: 'cs', 36 | key: 'menu', 37 | loader: async () => (await import('./cs/menu.json')).default, 38 | }, 39 | { 40 | locale: 'cs', 41 | key: 'about', 42 | routes: ['/about'], 43 | loader: async () => (await import('./cs/about.json')).default, 44 | }, 45 | { 46 | locale: 'cs', 47 | key: 'home', 48 | routes: ['/'], 49 | loader: async () => (await import('./cs/home.json')).default, 50 | }, 51 | ], 52 | }; 53 | 54 | export const { t, loading, locales, locale, translations, loadTranslations, addTranslations, setLocale, setRoute } = new i18n(config); 55 | 56 | loading.subscribe(($loading) => $loading && console.log('Loading translations...')); -------------------------------------------------------------------------------- /tests/data/translations/en/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "no_placeholder": "NO_PLACEHOLDER", 3 | "placeholder": "VALUES: {{value}}, {{value;}}, {{ value }}, {{ value; }}", 4 | "placeholder_default": "VALUES: {{value; default: DEFAULT_VALUE}}, {{value; default: DEFAULT_VALUE;}}, {{ value; default: DEFAULT_VALUE }}, {{ value; default: DEFAULT_VALUE; }}", 5 | "placeholder_escaped": "{{pl\\:ace\\;holder}}", 6 | "modifier_eq": "VALUES: {{value; option1:VALUE1; option2:VALUE2; default:DEFAULT VALUE;}}, {{ value ; option1 : VALUE1 ; option2 : VALUE2 ; default : DEFAULT VALUE ;}}, {{value:eq; option1:VALUE1; option2:VALUE2; default:DEFAULT VALUE;}}, {{ value : eq ; option1 : VALUE1 ; option2 : VALUE2 ; default : DEFAULT VALUE ;}}", 7 | "modifier_ne": "{{value:ne; 10:VALUE2; default:DEFAULT VALUE;}}", 8 | "modifier_lt": "{{value:lt; 1:VALUE1; 10:VALUE2; default:DEFAULT VALUE;}}", 9 | "modifier_lte": "{{value:lte; 1:VALUE1; 10:VALUE2; default:DEFAULT VALUE;}}", 10 | "modifier_gt": "{{value:gt; 1:VALUE1; 10:VALUE2; default:DEFAULT VALUE;}}", 11 | "modifier_gte": "{{value:gte; 1:VALUE1; 10:VALUE2; default:DEFAULT VALUE;}}", 12 | "modifier_number": "{{value:number;}}", 13 | "modifier_date": "{{value:date;}}", 14 | "modifier_ago": "{{value:ago;}}", 15 | "modifier_currency": "{{value:currency;}}", 16 | "modifier_custom": "{{data:test;}}", 17 | "modifier_escaped": "{{va\\:lue; option\\:1:VA\\;\\{\\{LUE\\}\\}\\:1; option\\:2:VA\\;\\{\\{LUE\\}\\}\\:2; default:DEFAULT \\{\\{VALUE\\}\\}\\;}}", 18 | "preprocess": [ 19 | { 20 | "test": { 21 | "array": "passed" 22 | } 23 | }, 24 | "string", 25 | null, 26 | 0, 27 | 1, 28 | -1, 29 | true, 30 | false 31 | ] 32 | } -------------------------------------------------------------------------------- /examples/parser-default/src/lib/translations/en/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "title_placeholders": "Placeholders", 3 | "title_built-in": "Built-in Modifiers", 4 | "title_custom": "Custom Modifiers", 5 | "title_dynamic_default": "Dynamic default", 6 | "title_direct_input": "Direct input", 7 | "placeholder_simple": "This is {{placeholder}}", 8 | "placeholder_default": "This is {{placeholder; default:a default value.}}", 9 | "modifier_eq_string": "{{value; male:He; female:She; default:No one}} has a dog.", 10 | "modifier_ne_string": "The dog is not {{value:ne; male:his; female:hers;}}.", 11 | "modifier_eq": "Value {{value; 10:is; default:is not;}} equal to ten", 12 | "modifier_ne": "Value {{value:ne; 10:is not; default:is;}} equal to ten", 13 | "modifier_lt": "Value {{value:lt; 10:is; default:is not;}} lower than ten", 14 | "modifier_lte": "Value {{value:lte; 10:is; default:is not;}} lower than or equal to ten", 15 | "modifier_gt": "Value {{value:gt; 10:is; default:is not;}} bigger than ten", 16 | "modifier_gte": "Value {{value:gte; 10:is; default:is not;}} bigger than or equal to ten", 17 | "modifier_number": "You have {{count:gt; 0:{{count:number;}} new {{count; 1:message; default:messages}}!; default:no messages...}}", 18 | "modifier_date": "Local date format: {{value:date;}}", 19 | "modifier_ago": "Page loaded (relative format): {{value:ago;}}", 20 | "modifier_test": "Test modifier: {{value:test; default:no input}}", 21 | "modifier_eqAbs": "Absolute value {{value:eqAbs; 10:is; default:is not;}} equal to ten.", 22 | "modifier_currency": "Currency: {{value:currency}}", 23 | "currency": "USD", 24 | "error": { 25 | "404": "Not found.", 26 | "500": "Internal server error.", 27 | "default": "Some error occurred." 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/parser-default/src/lib/translations/cs/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "title_placeholders": "Placeholdery", 3 | "title_built-in": "Vestavěné modifikátory", 4 | "title_custom": "Vlastní modifikátory", 5 | "title_dynamic_default": "Proměnná výchozí hodnota", 6 | "title_direct_input": "Přímý vstup", 7 | "placeholder_simple": "Toto je {{placeholder}}", 8 | "placeholder_default": "Toto je {{placeholder; default:výchozí hodnota.}}", 9 | "modifier_eq_string": "{{value; male:On; female:Ona; default:Někdo}} má psa.", 10 | "modifier_ne_string": "Ten pes není {{value:ne; male:jeho; female:její;}}.", 11 | "modifier_eq": "Hodnota {{value; 10:je; default:není;}} rovna deseti", 12 | "modifier_ne": "Hodnota {{value:ne; 10:není; default:je;}} rovna deseti", 13 | "modifier_lt": "Hodnota {{value:lt; 10:je; default:není;}} nižší než deset", 14 | "modifier_lte": "Hodnota {{value:lte; 10:je; default:není;}} nižší než nebo rovna deseti", 15 | "modifier_gt": "Hodnota {{value:gt; 10:je; default:není;}} vyšší než deset", 16 | "modifier_gte": "Hodnota {{value:gte; 10:je; default:není;}} vyšší než nebo rovna deseti", 17 | "modifier_number": "{{count:gt; 0:Máte {{count:number;}} {{count:gte; 1:novou zprávu; 2:nové zprávy; 5:nových zpráv}}!; default:Nemáte žádné zprávy...}}", 18 | "modifier_date": "Lokální formát data: {{value:date;}}", 19 | "modifier_ago": "Stránka načtena (relativní formát): {{value:ago;}}", 20 | "modifier_test": "Testovací modifikátor: {{value:test; default:žádný vstup}}", 21 | "modifier_eqAbs": "Absolutní hodnota {{value:eqAbs; 10:je; default:není;}} rovna deseti.", 22 | "modifier_currency": "Měna: {{value:currency;}}", 23 | "currency": "CZK", 24 | "error": { 25 | "404": "Nenalezeno.", 26 | "500": "Chyba serveru.", 27 | "default": "Něco se pokazilo." 28 | } 29 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sveltekit-i18n", 3 | "version": "2.4.2", 4 | "description": "Internationalization library for SvelteKit", 5 | "type": "module", 6 | "main": "./dist/index.cjs", 7 | "module": "./dist/index.js", 8 | "types": "./dist/index.d.ts", 9 | "exports": { 10 | ".": { 11 | "types": "./dist/index.d.ts", 12 | "require": "./dist/index.cjs", 13 | "import": "./dist/index.js" 14 | }, 15 | "./package.json": "./package.json" 16 | }, 17 | "scripts": { 18 | "dev": "tsup --watch", 19 | "test": "npx cross-env NODE_OPTIONS=--experimental-vm-modules jest --verbose", 20 | "build": "tsup", 21 | "prepublishOnly": "pnpm run build", 22 | "lint": "eslint --fix --ext .ts,.js,.svelte --ignore-path .gitignore ." 23 | }, 24 | "files": [ 25 | "dist" 26 | ], 27 | "pre-commit": [ 28 | "lint" 29 | ], 30 | "repository": { 31 | "type": "git", 32 | "url": "git+ssh://git@github.com/sveltekit-i18n/lib.git" 33 | }, 34 | "keywords": [ 35 | "svelte", 36 | "sveltekit", 37 | "i18n", 38 | "l10n", 39 | "internationalization", 40 | "localization", 41 | "translation" 42 | ], 43 | "author": "Jarda Svoboda", 44 | "license": "MIT", 45 | "bugs": { 46 | "url": "https://github.com/sveltekit-i18n/lib/issues" 47 | }, 48 | "homepage": "https://github.com/sveltekit-i18n/lib#readme", 49 | "peerDependencies": { 50 | "svelte": ">=3.49.0" 51 | }, 52 | "devDependencies": { 53 | "@types/jest": "^29.5.2", 54 | "@types/node": "^24.10.1", 55 | "@typescript-eslint/eslint-plugin": "^6.3.0", 56 | "@typescript-eslint/parser": "^6.3.0", 57 | "eslint": "^8.4.1", 58 | "eslint-config-airbnb-typescript": "^17.0.0", 59 | "eslint-plugin-import": "^2.25.3", 60 | "eslint-plugin-svelte": "^2.32.2", 61 | "jest": "^29.6.1", 62 | "pre-commit": "^1.2.2", 63 | "ts-jest": "^29.1.1", 64 | "tsup": "^8.0.1", 65 | "typescript": "^5.1.6" 66 | }, 67 | "dependencies": { 68 | "@sveltekit-i18n/base": "~1.3.0", 69 | "@sveltekit-i18n/parser-default": "~1.1.0" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/preprocess/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 |

Full preprocessing (default)

14 | 15 |
16 | {JSON.stringify($translationsFull, null, 2)}
17 | 
18 | 19 |

{$tFull('content.0.title')}

20 |

{@html $tFull('content.0.text', { link })}

21 |

{$tFull('content.0.something.else')}

22 |
23 | 24 |

{$tFull('content.1.title')}

25 |

{@html $tFull('content.1.text')}

26 |

{$tFull('content.1.something.else')}

27 |
28 | 29 |
30 | 31 |

Arrays preserved

32 | 33 |
34 | {JSON.stringify($translationsPreserveArrays, null, 2)}
35 | 
36 | 37 | {#each $tPreserveArrays('content', { default: [] }) as content} 38 |

{$tPreserveArrays(`${content.title}`)}

39 |

{@html $tPreserveArrays(`${content.text}`, { link })}

40 |

{$tPreserveArrays(`${content['something.else']}`)}

41 |
42 | {/each} 43 | 44 |
45 | 46 |

No preprocessing

47 | 48 |
49 | {JSON.stringify($translationsNone, null, 2)}
50 | 
51 | 52 | {#each $tNone('content', { default: [] }) as content} 53 |

{$tNone(`${content.title}`)}

54 |

{@html $tNone(`${content.text}`, { link })}

55 |

{$tNone(`${content.something.else}`)}

56 |
57 | {/each} 58 | 59 |
60 | 61 |

Custom preprocessing

62 | 63 |
64 | {JSON.stringify($translationsCustom, null, 2)}
65 | 
66 | 67 | {#each $tCustom('content', { default: [] }) as content} 68 |

{$tCustom(`${content.title}`)}

69 |

{@html $tCustom(`${content.text}`, { link })}

70 |

{$tCustom(`${content.something.else}`)}

71 |
72 | {/each} 73 | 74 | --------------------------------------------------------------------------------