cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Localised urls #54

Closed alexauvray closed 1 year ago

alexauvray commented 1 year ago

How to get localised urls like you set on https://svelte-intl-precompile.com/en/docs/introduction ?

In order to have /en/docs and /es/docs.

multipliedtwice commented 1 year ago

@alexauvray just create folder [lang] and put your routes inside there. Then initialize the library from the URL parameter.

 export async function load({ params, fetch, url }: any) {
    const initialLocale= params.lang.substring(0, 2)}

      init({
        fallbackLocale: "en",
        initialLocale,
      })
      await waitLocale(initialLocale)
}

@cibernox I've another question related to the topic. How can I achieve the following structure:

  1. / - default language
  2. /es
  3. /de

So all 3 routes would open the main page but in different languages. And wouldn't break internal pages.

Thank you

cibernox commented 1 year ago

@thousandsofraccoons You can check how I did it in the documentation page: https://github.com/cibernox/svelte-intl-precompile-docs

tl;dr; Define the route as [...lang], so you have a nesting level that can take zero or more arguments.

cibernox commented 1 year ago

@thousandsofraccoons thanks for answering the question! I'm closing this now