l10n.js icon indicating copy to clipboard operation
l10n.js copied to clipboard

Cannot get this to work...

Open cyphix333 opened this issue 8 years ago • 4 comments

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!

cyphix333 avatar Nov 23 '16 13:11 cyphix333

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";.

eligrey avatar Nov 23 '16 18:11 eligrey

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 ?

cyphix333 avatar Nov 23 '16 18:11 cyphix333

Yes, that is correct.

eligrey avatar Nov 23 '16 18:11 eligrey

Ok, thank you!

cyphix333 avatar Nov 23 '16 19:11 cyphix333