0.7.0 • Published 10 years ago

derby-lang v0.7.0

Weekly downloads
5
License
MIT
Repository
github
Last release
10 years ago

Derby Lang

A translation library for Derby JS that uses messageformat.js.
Refer to the messageformat.js docs on how to format translation strings.

Build Status

Installation

$ npm install derby-lang --save

Server Usage

In your server file, add the middleware:

var lang = require('derby-lang').server;

expressApp
  // ...
  // ...
  .use(lang())

Add a dictionary:

// ..
// ..
.use(function (req, res, next) {
  var model = req.getModel();
  model.set('$lang.dict.strings', {
    en: {'Hello world.': 'Hello world.'},
    es: {'Hello world.': 'Hola mundo.'},
    fr: {'copyright': '© {year}'},
    it: {'foo': {'bar': 'baz'}}
  });
  next();
});

Optionally, use derby-lang-fs to define a dictionary with *.json files.

App Usage

In your view functions:

var lang = require('derby-lang').app;
app.proto.t = lang.translate();

In your view:

<p>{{t($lang.dict, 'en', 'Hello world.')}}</p>
<p>{{t($lang.dict, 'fr', 'copyright.', {year: 2014})}}</p>
<p>{{t($lang.dict, 'it', ['foo', 'bar'])}}

Locales

It's up to you to manage what locale to display. You can use derby-locale to automatically select the best locale for a user given the ones you support, their browser preference, etc.

Dictionaries

A dictionary is just an object with translation strings. It can be stored in the database rather than set during a middleware route. You could subscribe to a dictionary and use ShareJS views to return only relevant languages.

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago