Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 8, 2017. It is now read-only.

keithamus/R.js

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

No Longer Actively Maintained

If someone would like to take over maintainence, feel free to get in touch (@keithamus on twitter). I'll happily transfer this over.

R.js

Sponsor

R.js is a simple i18n framework for Javascript, using CommonJS. R.js should work in both browsers, and on Node.js, providing internationalisation capabilities to both.

R.js is tiny, at less than 900 bytes minified and gzipped (<2kb minified). R.js has no dependencies, but can be used easily with any other libraries you wish. R.js binds itself to window.R, or global.R on the server side.

Soon, R.js will be able to convert from XLIFF format, into R.js files, which can be easily compacted with R.js to provide one single small file for all your i18n needs.


To use R.js, simply register a language file like so:

R.registerLocale('en-GB', { string: 'I am a string'});

Now you can set the locale to en-GB (which will automatically be picked up by the browser by the way), and get on with translating:

R.setLocale('en-GB');
R('string');
    -> "I am a string"

Of course, R.js has an advanced string-replacement engine which lets you replace integers, strings and named arguments inside your i18n strings. Lets have a look:

R.registerLocale('en-GB', { items: 'There are %i %s on the %(place)' })
R.setLocale('en-GB');
R('items', 4, 'books', { place: 'shelf' });
    -> "There are 4 books on the shelf";
R('items', [99, 'bottles of beer'], { place: 'wall' });
    -> "There are 99 bottles of beer on the wall";
R('items', { i: 8, s: 'rashers of bacon', place: 'narwhal' });
    -> "There are 8 rashers of bacon on the narwhal";

R.js also can be used as an advanced sprintf engine, as by default if it cannot find the locale string, it will return the string you supplied it, like so:

R('This %s doesnt exist', 'string');
    -> "This string doesnt exist";

About

Internationalisation Library for Javascript

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.