Basically I want to use i18next without jQuery. I could write my own code for this but was hoping i18n had the same built in way of doing this without jQuery. Using jQuery I can just call i18n on the body (e.g. $('body').i18n()) and every element with data-i18n on it will be translated.
Can you do this without jQuery using already built in options of i18n or do I need to do a query selector all for all the elements with that attribute and loop and translate each one myself?
Also all the other attribute translation happens using jquery too (e.g. [title]somekey;). Without jquery do I have to do all this manually.
all you need todo is rebuild this https://github.com/i18next/i18next/blob/master/src/i18next.jquery.js without using jquery...
i myself never had the need, as i used the t function inside some template engine.
if you go up the way to implement this not depending on jquery a PR contributing it back would be very welcome.
So I wrote the code to do it without jquery but I am not super familiar with your entire code base so there may be some things I missed but as of now replacing the addJqueryFunct gives me the jQuery like functionality without jQuery, minus the useDataAttrOptions stuff. Had to modify some other code a bit to make it call the addJqueryFunct even if jquery didn't exist of course but it does work so it would be nice to have this baked in to i18next without any fiddling. The system I work only supports the most modern browsers as well so my code is more suited to them (IE < 10, I'm looking at you) but it shouldn't be hard to add in the equivalent code supporting old browser versions. If you are interested in having the code at least as a starting point to add this functionality to i18next I would be happy to provide it.
PR will be merged
sorry for bump
I'm using this
for (i = 0; i < document.querySelectorAll('[data-i18n]').length; i++) {
document.querySelectorAll('[data-i18n]')[i].innerHTML = i18next.t(document.querySelectorAll('[data-i18n]')[i].getAttribute("data-i18n"));
}
Most helpful comment
sorry for bump
I'm using this
for (i = 0; i < document.querySelectorAll('[data-i18n]').length; i++) { document.querySelectorAll('[data-i18n]')[i].innerHTML = i18next.t(document.querySelectorAll('[data-i18n]')[i].getAttribute("data-i18n")); }