Skip to content

MrOnlineCoder/aztec.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aztec.js

Travis CI Build Status

A lightweight Javascript library for localizing pages.

Getting Aztec.js

You can always get Aztec.js using next links:

Normal

Minified

Getting started

Aztec.js is easy-to-use library, and you will see it!

First, connect Aztec.js to your page:

<script src="path to your aztec.js"></script>

Now we are ready to use Aztec.js!

All library functions are located in Aztec object.

Aztec.js works like template engine, you specify the object with keys and values, and then engine renders it.

Make a script for setting up Aztec.js:

Aztec.addLocale("english", {country: "England", locale: "English"});

Aztec.setLocale("english");

Here, we added a new language with english key, and object with keys.

Then, we set english as current language.

Now, let's move to HTML:

<p render="Hello, I am from {%country%}. The current locale is {%locale%}"></p>

So, what we did in this part of code?

1.We added a render attribute to our p element, so Aztec.js now know that this element should be rendered.

2.Added the template tags: country and locale. The values for that tags are taken from object passed to addLocale method.

And the final step:

call .render() function to render elements.

Aztec.render();

The result will be:

Hello, I am from England. The current locale is English!

You can also get translation from Javascript:

Aztec.translate("country"); // => "England"

Documentation:

Aztec.debug (Boolean) - should Aztec.js actions be logged in console?

Aztec.translateAttr (String) - a attribute for elements which should be rendered. Default: render

Aztec.addLocale(name, keys) (Function) - adds the language. name is the name for locale, and keys is object with translations.

Aztec.setLocale(name) (Function) - sets the current language. Please, add the language before setting it as current.

Aztec.render(element) (Function) - renders the page/element. If element is not specified, then whole page will be rendered.

License: MIT

Author: MrOnlineCoder (Nikita Kogut)

About

A lightweight Javascript library for localizing pages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published