sveltekit-i18n / lib

Internationalization library built for SvelteKit.
MIT License
491 stars 32 forks source link

Does this library support cultures. Like en-uk and en-us? #142

Closed juanjoseluisgarcia closed 1 year ago

juanjoseluisgarcia commented 1 year ago

I found out that culture is a very sensitive issue and different cultures like to see things in their own 'flavour' of the language and syntax. Is it possible to have different loaders based on this?

Nycolaide commented 1 year ago

Hello , i use sveltekit-i18n in my project and yes sveltekit-i18n support cultures. /** @type {import('sveltekit-i18n').Config} */ const config = { fallbackLocale: defaultLocale, translations: { 'en-US': { languages }, 'fr-FR': { languages } }, loaders: [...translateEn, ...translateFr] };

And my loaders :)

Screenshot 2023-09-06 at 11 13 14

Sorry for my English , i'm french :/

juanjoseluisgarcia commented 1 year ago

Apologies for the question. Would you mind to give me a schema on how the translateEn functions looks like? Thanks

Nycolaide commented 1 year ago

Oh yes!

index.ts

const locale = 'en-us';
const translations = [
    {
        locale: locale,
        key: 'common',
        loader: async () => (await import('./common.json')).default
    },
    {
        locale: locale,
        key: 'global',
        loader: async () => await import('./global.json')
    },
    {
        locale: locale,
        key: 'auth',
        loader: async () => (await import('./auth.json')).default
    },
    {
        locale: locale,
        key: 'legal',
        loader: async () => (await import('./legal.json')).default
    }
];

export default translations;

I call translate in my +page.svelte => $t('auth.password')