How to use the svelte-i18n.init 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
export function i18nMiddleware() {
    // initialLocale will be set by the middleware
    init(INIT_OPTIONS);

    return (req, res, next) => {
        const isDocument = DOCUMENT_REGEX.test(req.originalUrl);
        // get the initial locale only for a document request
        if (!isDocument) {
            next();
            return;
        }

        let locale = getCookie('locale', req.headers.cookie);

        // no cookie, let's get the first accepted language
        if (locale == null) {
            if (req.headers['accept-language']) {
                const headerLngs = req.headers['accept-language'].split(',');
                const headerLngCodes = headerLngs.map(lng => lng.split(';')[0].trim());
github caos / zitadel / site / src / i18n.js View on Github external
export function startClient() {
    console.log('nav', getLocaleFromNavigator());
    init({
        ...INIT_OPTIONS,
        initialLocale: getCookie('locale') || INIT_OPTIONS.localeOptions.find(option => option == cropCountryCode(getLocaleFromNavigator())) || INIT_OPTIONS.initialLocale,
    });
}

svelte-i18n

Internationalization library for Svelte

MIT
Latest version published 8 months ago

Package Health Score

66 / 100
Full package analysis