sveltekit-i18n / lib

Internationalization library built for SvelteKit.
MIT License
447 stars 28 forks source link

Advanced router (default locale no prefix) with static adapter? #167

Open kratos-digital opened 5 months ago

kratos-digital commented 5 months ago

How to use static adapter with example in locale-router-advanced? What I need is to have my default locale without prefix, but files should be built statically. Static adapter works with locale-router-static, but every language has prefix there and the index.html only has JS redirection to default locale.

In svelte.config.js I have this:

const config = {
    kit: {
        adapter: adapter({
            pages: 'build',
            assets: 'build',
            fallback: undefined,
            precompress: false,
            strict: true
        }),
        prerender: {
            // This works when all locales are prefixed
            // entries: ['/'].concat(supportedLocales.reduce((acc, locale) => [...acc, `/${locale}`], ['*']))
            entries: ['*', '/', '/en'] // throws error below (hr default locale, en secondary locale)
            // entries: ['*', '/en'] // generates only files for english locale, and nothing for default
        }
    },
    preprocess: vitePreprocess(),
    compilerOptions: {
        customElement: true
    }
};

All I get is this useless error:

node:internal/event_target:1083
  process.nextTick(() => { throw err; });
                           ^
Error: 500 /
ansbr commented 5 months ago

I can't find example without prefix for default locale in repository, that's very sad. If someone can make example, it will be really cool...

kikky7 commented 5 months ago

There is example https://github.com/sveltekit-i18n/lib/tree/master/examples/locale-router-advanced, but it doesn't work with static adapter.

To make it work with static adapter, check out locale-router-static example and set lang param as optional (double square brackets). Then the default locale will be created both in root and language folder. And on server you can use rewrite rules to redirect default locale folder to root.