A translation plugin for static GitHub Pages sites that use jQuery.
This is not meant to be used in production. This is just a newbie's attempt at creating a JS library. This plugin still needs a lot of work before it sees the light of an 'in production' day.
This is library depends on jQuery so make sure you have that included in your project.
Here are some basic steps to using the plugin:
4. Reference your main .js file afterward (you will importing global variables from the translation files).
var en = {
"key" : "translation",
"for_example" : "something like this",
...
};
var options = {
"English" : "en", // variables declared in files in ./i18n directory
"Spanish" : "es",
...
};
_t(options).translate("English");
This will initialize the plugin and set the language. Now to set up the HTML file...
Now that the plugin is set, we need to set up the HTML file to translate. You need to add the class 'i18n' to anything that needs to be translated, and add a 'data-say' attribute to the HTML element as well. Here is a sample:
<h2 data-say="some_text_key" class="i18n"></h2>
(NOTE): This will completely replace all contents inside the elements with the 'i18n' class, so structure the HTML accordingly.
Depending on how you want to trigger a translation, this is the command to do so:
_t.translate('Spanish');