Open jonalxh opened 5 years ago
Hi there,
I should update the documentation to explain better what you could pass as options
.
If you look here, you could override these options: domain
, locale
, ctxt_delimiter
. These are not settings you want to often override.
What I think you want is to load translations catalogue like this:
// i18n.setMessages(domain, locale, messages, plural_form);
i18n.setMessages('messages', 'fr', {
"Welcome": "Bienvenue",
"There is %1 apple": [
"Il y a %1 pomme",
"Il y a %1 pommes"
]
}, 'nplurals=2; plural=n>1;');
or with a JSON:
// i18n.loadJSON(jsonData /*, domain */);
var json = {
"": {
"language": "fr",
"plural-forms": "nplurals=2; plural=n>1;"
},
"Welcome": "Bienvenue",
"There is %1 apple": [
"Il y a %1 pomme",
"Il y a %1 pommes"
]
};
i18n.loadJSON(json, 'messages');
Then call i18n.setLocale('fr');
to use the catalog you just loaded, and try i18n.gettext('Welcome');
, you'll see French! ;-)
If you are satisfied with the defaults do you still need a statement similar to:
var i18n = window.i18n
before loading the json?
Can one put either:
<script src="/path/to/dist/gettext.iife.js" type="text/javascript"></script>
or
<script src="/path/to/dist/gettext.js" type="text/javascript"></script>
in the webpage header and then access i18n
in other scripts?
I need to translate something in an existing script and have added this to the script:
var i18n = window.i18n
i18n.setMessages('messages', 'fr', {
Welcome: 'Bienvenue',
contents: 'Sur cette page...',
'There is %1 apple': [
'Il y a %1 pomme',
'Il y a %1 pommes',
],
}, 'nplurals=2; plural=n>1;')
But I am getting a console error Uncaught TypeError: e.setMessages is not a function
I don't know that that e is or where it is comming from. Is there something I may have missed?
note: the linter wanted me to put strings in single quotes.
Hi.
I was reading the documentation but I'm not able to find how to set the options parameter to begin getting texts.
var i18n = window.i18n(options);
I think it is just a JSON with some values, but I don't know what key, value pairs.
I hope you could help me.