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

Update I18n.svelte #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Blackspirits
Copy link

No description provided.

@aleksilassila
Copy link
Owner

I wasn't able to get this working, seems like svelte i18n doesn't have support for differentiating between brazil and portuguese dialects yet. Did you get this to work?

@ivandiazmolina
Copy link

Checking the Files changed you can see the following lines

import it from '../../lang/pt_PT.json';
import it from '../../lang/pt_BR.json';

addMessages('pt_PT', pt_PT);
addMessages('pt_BR', pt_BR);

I think that it would be like this:

import pt_PT from '../../lang/pt_PT.json';
import pt_BR from '../../lang/pt_BR.json';

addMessages('pt_PT', pt_PT);
addMessages('pt_BR', pt_BR);

Could you test it?

@aleksilassila
Copy link
Owner

aleksilassila commented Jun 17, 2024

addMessages('pt_PT', pt_PT);
addMessages('pt_BR', pt_BR);

This doesn't work either. I tried all kinds of combinations for the language codes, no success. Might be that the selte i18l doesn't support this, I didn't try updating the version.

@ivandiazmolina
Copy link

@aleksilassila I have cloned your repo and deploy it locally. I get the correct translations when I create both en-EN and en-US with the following lines.

import enUS from '../../lang/en-US.json';
import enEN from '../../lang/en-EN.json';

addMessages('en-EN', enEN);
addMessages('en-US', enUS);

But your main problem is in this line

initialLocale: $settings.language

I am not expert in web development but I think that $settings is a var to store the user preferences. Maybe it is not working fine, but if you replace the previous line with this

import { addMessages, init, locale, getLocaleFromNavigator } from 'svelte-i18n';
....
init({
   initialLocale: getLocaleFromNavigator(),
   fallbackLocale: 'en-EN'
});

You get the locale from the navigator and the correct translation

en-EN

image

en-US

image

@aleksilassila
Copy link
Owner

@ivandiazmolina I'm confused, are you working with the version 1.0 or 2.0? 2.0 doesn't have translations yet, but your reply seems to contain code from v1 and screenshot from v2. Also I'm sure that it recognizes en-us and en-gb, but have you got it to recognize both pt-pt and pt-br? The problem I ran into earlier was getting them both to show up in the v1 language menu.

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

Successfully merging this pull request may close these issues.

3 participants