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

Cannot get this to work... #38

Open
cyphix333 opened this issue Nov 23, 2016 · 4 comments
Open

Cannot get this to work... #38

cyphix333 opened this issue Nov 23, 2016 · 4 comments

Comments

@cyphix333
Copy link

Ok since my other questions I have been testing this out and I cannot seem to get it to work in any manner using a .json file included as per the instructions under the Usage section, it seems to take no notice of it whatsoever.

I then tried the way it was done in the Demo section and I got it to work, however it doesn't seem to honor country code locales, eg:

With that in mind I'm unsure you even set the Language/locale you wish to use if you aren't using the link tag such as:

<link rel="localization" hreflang="en-US" href="american-english.json" type="application/vnd.oftn.l10n+json"/>

Does the script look at the value of the lang attribute of the html tag?

Anyway, I have it set as such:

<html lang="en-GB">

...and then I have included the main library followed by a .js file with this inside it:

String.toLocaleString({
    "en": {
        "Hello!": "Hello!!!!!!!!"
    },
    "en-GB": {
        "Hello!": "Hola!"
    },
    "en-AU": {
        "Hello!": "Hola!!!!!!!!!!!"
    }
});

When I do any translations this will output: Hello!!!!!!!! when it should output Hola!

If I only include the en-GB locale such as:

String.toLocaleString({
    "en-GB": {
        "Hello!": "Hola!"
    }
});

Then it doesn't do anything and just outputs the same text as I passed in.

Can you please advise?

Thanks!

@eligrey
Copy link
Owner

eligrey commented Nov 23, 2016

Anyway, I have it set as such:

<html lang="en-GB">

This has no effect on the user language. If you are debugging and want to test out how your site react to people with different locales, you need to manually define String.locale prior to your localization calls.

E.g. to test en-GB, even if your browser is en-US, you do String.locale = "en-GB";.

@cyphix333
Copy link
Author

Well my main purpose for using something like this is to be able to localize to a language I set it to, not to the users locale set in their browser; so I guess to be able to do that I would have to always set String.locale ?

@eligrey
Copy link
Owner

eligrey commented Nov 23, 2016

Yes, that is correct.

@cyphix333
Copy link
Author

Ok, thank you!

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