=>
+ alternates(path)?.reduce((result, alt) => {
+ result[alt.match(/^\/([a-z]{2})(\/|$)/)?.[1] || defaultLocale] = alt;
+ return result;
+ }, {})
+);
+
+export const l = derived(
+ [localizedPaths, locale],
+ ([localizedPaths, locale]) => (path: string): string => localizedPaths(path)?.[locale] || path
+);
+
+export { l as localize };
diff --git a/packages/create-svelte/templates/default/svelte.config.js b/packages/create-svelte/templates/default/svelte.config.js
index 3315cb538d642..a84d610428d00 100644
--- a/packages/create-svelte/templates/default/svelte.config.js
+++ b/packages/create-svelte/templates/default/svelte.config.js
@@ -1,4 +1,5 @@
import preprocess from 'svelte-preprocess';
+import { localizeRoutes } from './i18n.config.js';
const adapter = process.env.ADAPTER;
const options = JSON.parse(process.env.OPTIONS || '{}');
@@ -11,7 +12,9 @@ const config = {
kit: {
// hydrate the element in src/app.html
- target: '#svelte'
+ target: '#svelte',
+
+ alternateRoutes: localizeRoutes
}
};