cloak.i18n
Cloak.js is a collection of modules for building modern web applications. Each module is designed to work with the others, but are decoupled to allow you pick and choose which ones you need. Want views but don't need to deal with models or a complex router? You can do that! First, make sure you have cloak.core
which contains some basic utilities for each module. Then, install the modules you want.
$ npm install --save cloak.core$ npm install --save cloak.view
Then, in your JavaScript, just start using the components. Cloak is designed to work in a CommonJS environment, so any tools that do so will work (like common.js or browserify).
var View = ; var MyView = moduleexports = View;
Cloak modules
- cloak.core - The cloak core: tiny, but used by all the cloak modules
- cloak.view - Provides the
View
class - cloak.model - Provides the
Model
andCollection
classes for handling data - cloak.router - Provides the
Router
class for all you app routing needs - cloak.controller - Provides a super-minimal
Controller
class for transitioning displaying views - cloak.xhr - Provides an easy interface for making HTTP requests by
XMLHttpRequest
; Also provides an interface to define XHR methods on theModel
andController
classes - cloak.localstorage - Provides an easy interface for storing data in local storage; Also provides an interface to use local storage as your main app storage for
Model
andCollection
classes - cloak.i18n - Provides a simple internationalization interface for storing translated phrases and determining a client's language
- cloak.socketio - Provides a socket.io interface for models based on the dagger.js websocket api
Usage
$ npm install --save cloak.core cloak.i18n
The cloak.i18n
module provides a really basic internationalization interface. It enables you to store translations in simple JS files and then have the correct translation selected.
Your file structure will look something like this:
app
|-- i18n
| |-- index.js
| `-- en-us.js
|-- app.js
i18n/en-us.js
moduleexports = auth: login: 'Please login' bad_password: 'Password was incorrect, please try again' ;
i18n/index.js
exports'en-us' = ;
app.js
// Load the modulevar i18n = ; // Include our translations stored in the i18n directoryi18n; // Translate some stuffi18n; // returns "Please login"
Once your translations are setup, the module will determine the best language to use based on browser settings and previous user selections. To change the language manually, you can use i18n.lang()
, like so:
// This will use the "en-gb" (english, great britain) lanuage and store that// preference in local storage for later usesi18nlang'en-gb';