How to use the svelte-i18n.register function in svelte-i18n

To help you get started, we’ve selected a few svelte-i18n examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caos / zitadel / site / src / i18n.js View on Github external
import { LANGUAGES } from '../config.js';
import { getCookie, setCookie } from './modules/cookie.js';

export const INIT_OPTIONS = {
    fallbackLocale: 'en',
    initialLocale: 'en',
    loadingDelay: 200,
    formats: {},
    warnOnMissingMessages: true,
    localeOptions: LANGUAGES,
};

let currentLocale = null;

register('en', () => import('./messages/en.json'));
register('de', () => import('./messages/de.json'));

$locale.subscribe((value) => {
    if (value == null) return;

    currentLocale = value;

    // if running in the client, save the language preference in a cookie
    if (typeof window !== 'undefined') {
        setCookie('locale', value);
    }
});

// initialize the i18n library in client
export function startClient() {
    console.log('nav', getLocaleFromNavigator());
    init({
github caos / zitadel / site / src / i18n.js View on Github external
import { LANGUAGES } from '../config.js';
import { getCookie, setCookie } from './modules/cookie.js';

export const INIT_OPTIONS = {
    fallbackLocale: 'en',
    initialLocale: 'en',
    loadingDelay: 200,
    formats: {},
    warnOnMissingMessages: true,
    localeOptions: LANGUAGES,
};

let currentLocale = null;

register('en', () => import('./messages/en.json'));
register('de', () => import('./messages/de.json'));

$locale.subscribe((value) => {
    if (value == null) return;

    currentLocale = value;

    // if running in the client, save the language preference in a cookie
    if (typeof window !== 'undefined') {
        setCookie('locale', value);
    }
});

// initialize the i18n library in client
export function startClient() {
    console.log('nav', getLocaleFromNavigator());

svelte-i18n

Internationalization library for Svelte

MIT
Latest version published 7 months ago

Package Health Score

64 / 100
Full package analysis