Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I hover over a <a> the site language changes to the default language. #227

Open
PoolFlamingo opened this issue Aug 30, 2023 · 1 comment

Comments

@PoolFlamingo
Copy link

Describe the bug
When I hover over a link element that points to a subpage of my web domain other than the one I'm currently on, the website translation returns to its default language (English). However, if I hover over a link that refers to the same page or hover over a link that has target="_blank" or target="_self", this bug does not happens.

Logs
There are no logs, nor any type of error.

To Reproduce

  • Create a project as specified on the sveltekit page.
  • Install the "svelte-i18n" module.
  • Create a script called i18n.ts/i18n.js, like this:
import {
    _,
    register,
    init
} from 'svelte-i18n';
  
function setupI18n({withLocale: _locale, pageName=undefined} = {withLocale: 'en', pageName:'index'}) 
{
    register('en', () => import('../../json/lang/en.json'));
    register('es', () => import('../../json/lang/es.json'));
 
    return init({
        // fallback to english if the current locale is not in the dictionary
        fallbackLocale: 'en',
        initialLocale: 'en',
    });
}
export {
    _,
    setupI18n
};
  • Create 2 jsons with languages (English and your native language).
  • Create one or two more pages, and add translated text to them.
  • Create an element to be able to change languages.
  • When hovering over a link that points to another of the pages created by you without the "target" attribute, the default language should be set to "en".

Expected behavior
This behavior should not occur under any circumstances. And although I have tried adding 'target="_self"' and this problem has stopped occurring, I have noticed that when changing pages, it no longer has the dynamism and fast loading that it had before, so I preferred to avoid it.

Information about your project:

  • I'm using typescript.

  • svelte-i18n version: 3.7.0

  • My project uses Vite.

@brunnerh
Copy link

brunnerh commented Sep 3, 2023

You did not specify where setupI18n is called.
I suspect you use it in the wrong place, e.g. the page, so it may end up being called multiple times.

If you set up localization in the root +layout.svelte, there should not be any such issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants