Skip to content

Commit

Permalink
Comment shared server translations
Browse files Browse the repository at this point in the history
  • Loading branch information
jarda-svoboda committed Jul 12, 2023
1 parent 989bdb0 commit edd416a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
14 changes: 8 additions & 6 deletions examples/component-scoped-csr/src/routes/+layout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { loadTranslations } from '$lib/translations';
import { addTranslations, setLocale, setRoute } from '$lib/translations';

/** @type {import('@sveltejs/kit').Load} */
export const load = async ({ url }) => {
const { pathname } = url;
export const load = async ({ data }) => {
const { i18n, translations } = data;
const { locale, route } = i18n;

const initLocale = 'en'; // get from cookie / user session etc...
addTranslations(translations);

await loadTranslations(initLocale, pathname); // keep this just before the `return`
await setRoute(route);
await setLocale(locale);

return {};
return i18n;
};
15 changes: 15 additions & 0 deletions examples/component-scoped-csr/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { loadTranslations, translations } from '$lib/translations';

/** @type {import('@sveltejs/kit').ServerLoad} */
export const load = async ({ url }) => {
const { pathname } = url;

const initLocale = 'en'; // get from cookie / user session etc...

await loadTranslations(initLocale, pathname); // keep this just before the `return`

return {
i18n: { locale: initLocale, route: pathname },
translations: translations.get(), // `translations` on server contain all translations loaded by different clients
};
};
2 changes: 1 addition & 1 deletion examples/component-scoped-ssr/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const load = async ({ url }) => {

return {
i18n: { locale: initLocale, route: pathname },
translations: translations.get(),
translations: translations.get(), // `translations` on server contain all translations loaded by different clients
};
};
14 changes: 8 additions & 6 deletions examples/fallback-locale/src/routes/+layout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { loadTranslations } from '$lib/translations';
import { addTranslations, setLocale, setRoute } from '$lib/translations';

/** @type {import('@sveltejs/kit').Load} */
export const load = async ({ url }) => {
const { pathname } = url;
export const load = async ({ data }) => {
const { i18n, translations } = data;
const { locale, route } = i18n;

const initLocale = 'cs'; // get from cookie, user session, ...
addTranslations(translations);

await loadTranslations(initLocale, pathname); // keep this just before the `return`
await setRoute(route);
await setLocale(locale);

return {};
return i18n;
};
15 changes: 15 additions & 0 deletions examples/fallback-locale/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { loadTranslations, translations } from '$lib/translations';

/** @type {import('@sveltejs/kit').ServerLoad} */
export const load = async ({ url }) => {
const { pathname } = url;

const initLocale = 'en'; // get from cookie / user session etc...

await loadTranslations(initLocale, pathname); // keep this just before the `return`

return {
i18n: { locale: initLocale, route: pathname },
translations: translations.get(), // `translations` on server contain all translations loaded by different clients
};
};
2 changes: 1 addition & 1 deletion examples/locale-param/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const load = async ({ url, cookies }) => {

return {
i18n: { locale: initLocale, route: pathname },
translations: translations.get(),
translations: translations.get(), // `translations` on server contain all translations loaded by different clients
};
};
2 changes: 1 addition & 1 deletion examples/multi-page/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const load = async ({ url }) => {

return {
i18n: { locale: initLocale, route: pathname },
translations: translations.get(),
translations: translations.get(), // `translations` on server contain all translations loaded by different clients
};
};

0 comments on commit edd416a

Please sign in to comment.