• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    JavaScript
  • Created about 14 years ago
  • Updated over 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Translations for nodejs
       ,,    ,,             ,,
     `7MM    db           `7MM                    mm
       MM                   MM                    MM
  ,M""bMM  `7MM   ,6"Yb.    MM  .gP"Ya   ,p6"bo mmMMmm
,AP    MM    MM  8)   MM    MM ,M'   Yb 6M'  OO   MM
8MI    MM    MM   ,pm9MM    MM 8M"""""" 8M        MM
`Mb    MM    MM  8M   MM    MM YM.    , YM.    ,  MM
 `Wbmd"MML..JMML.`Moo9^Yo..JMML.`Mbmmd'  YMbmd'   `Mbmo

Dialect is a painless nodejs module to manage your translations.

Install

npm install dialect

Tutorial screencast

Dealing with translations in nodejs

Philosphy

  • Scalable: The translations should be available to any number of machines.
  • Fast: Getting translations from memory.
  • Reliable: Translations should be always available on a central repository/database.
  • Flexible: You should be able to use your favorite storage solution.

Example

var dialect = require('dialect').dialect({current_locale: 'es', store: {mongodb: {}}});

// connects to the store
dialect.connect(function () {

  // syncs the memory dictionaries with the store
  dialect.sync({interval:3600}, function (err, foo) {
    d.get('Hello World!'); // => Hola mundo
  });
});

Options

  • current_locale: Current locale used on your application.
  • base_locale: Base locale. Serves as keys on the dictionaries.
  • locales: Which locales are available on your application.
  • store: Object containing the store and their options

Store options

  • mongodb
    • database: dialect
    • host: 127.0.0.1
    • port: 27017
    • collection: translations
    • username (optional)
    • password (optional)
  • sqlite
    • database: dialect.db
    • table: dialect

API

  • config (key, value): Exposes configuration values.
  • get (query): Gets a translation cached in memory.
  • set (query, translation, callback): Sets a translation on the store.
  • approve (approve?, query, callback): Approve or rejects a translation.
  • sync (locale, repeat, callback): Syncs all the approved translations of the store to the memory cache.
  • connect (callback): Connects to the database store.

Plurals

Provide an array with the singular and plural forms of the string, the last element must contain a count param that will determine which plural form to use.

dialect.config('current_locale': 'sl'); // slovenian

[1, 2, 3].forEach(function (i) {
  dialect.get(['Beer', 'Beers', {count: i}]);
});

+---------------+-------------+
| found         | not found   |
+---------------+-------------+
| Pivo          | Beer        |
| Pivi          | Beers       |
| Piva          | Beers       |
+---------------+-------------+

You have an examle using plural forms in examples/plurals.js

Contexts

A context is a param that allows you to give a special meaning on a string. It helps the translator and it may generate diferent translations depending on the context.

dialect.config('current_locale': 'es'); // spanish

['female', 'male'].forEach(function (gender) {
  dialect.get(['My friends', gender]);
});

+---------------+-------------+
| found         | not found   |
+---------------+-------------+
| Mis amigos    | My friends  |
| Mis amigas    | My friends  |
+---------------+-------------+

You have an examle using contexts in examples/contexts.js

String interpolation

You can put any param you want on the translation strings surrounded by moustaches {}. Remember that count and context have a special meaning although they can also be used with interpolations.

[1, 2].forEach(function (count) {
  ['female', 'male'].forEach(function (gender) {
    dialect.get([
      'You have {count} friend called {name}',
      'You have {count} friends called {name}',
      {count: count, context: context, name: 'Anna'}
    ]);
  });
});

+---------------------------------------+-----------------------------------------+
| found                                 | not found                               |
+---------------------------------------+-----------------------------------------+
| Tienes 1 amiga que se llama Anna      | You have 1 friend called Anna           |
| Tienes 1 amigo que se llama Anna      | You have 1 friend called Anna           |
| Tienes 2 amigas que se llaman Anna    | You have 2 friends called Anna          |
| Tienes 2 amigos que se llaman Anna    | You have 2 friends called Anna          |
+---------------------------------------+-----------------------------------------+

You have an examle using contexts in examples/interpolation.js

Store translations

To store a new translation, use the method set.

dialect.set(
  {original: 'I love gazpacho', locale: 'es'},
  'Me encanta el gazpacho'
);

dialect-http

Do you need a nice environment for your translators?

dialect http is an amazing http server to manage your translations.

Test

Dialect is heavily tested using testosterone

make

Benchmarks

Dialect should not add an overhead to your application on getting translations. Please run/add benchmarks to ensure that this module performance rocks.

node benchmakrs/hello_world.js

License

(The MIT License)

Copyright (c) 2010-2011 Pau Ramon [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

mobx-rest

REST conventions for Mobx
TypeScript
187
star
2

mongolia

Flexible non-magical layer for the nodejs MongoDB driver
JavaScript
147
star
3

Backbone.Rel

Backbone.Rel extends your Backbone models with a lightweight relationships manager.
JavaScript
144
star
4

testosterone

Virile testing for http servers or any nodejs application.
JavaScript
82
star
5

whatajong

Open source multiplayer mahjong using HTML5 and nodejs + socket.io
JavaScript
77
star
6

Backbone.Subset

Provides a collection-like constructor that allows you create a collection that is subset from a parent one
JavaScript
75
star
7

facebook-js

Easy peasy facebook client for connect
JavaScript
63
star
8

linkedin-js

Easy peasy linkedin client for connect
JavaScript
43
star
9

tldextract

Extract domain, subdomain and tld from a url
JavaScript
38
star
10

connect-i18n

Middleware for connect to handle i18n
JavaScript
25
star
11

dialect-http

http client to manage your dialect translations
JavaScript
25
star
12

asereje

Forget about assets builds
JavaScript
23
star
13

twitter-js

Easy peasy twitter client for connect
JavaScript
23
star
14

Backbone.Aggregator

Provides a collection-like constructor that allows you create aggregators from different collections
JavaScript
19
star
15

funk

Asynchronous functions made funky!
JavaScript
17
star
16

express-dialect

Pluggable express app to handle i18n and L18n
JavaScript
16
star
17

transsiberian

nodejs boilerplate built upon Express and Mongolia
JavaScript
15
star
18

i-love-async

"Slides" from the little talk I gave on the Barcelona nodejs meetup
JavaScript
14
star
19

resting-ducks

REST conventions for single stores
JavaScript
11
star
20

node-brainfuck

Brainfuck interpreter for nodejs
JavaScript
10
star
21

mobx-rest-fetch-adapter

Fetch adapter for mobx-rest
JavaScript
9
star
22

backbone.partial-fetch

Allows you to do smart partial fetching
JavaScript
9
star
23

backbone.middleware

Backbone.middleware
JavaScript
9
star
24

jasmine-prototype

prototype matchers and fixture loader for Jasmine framework
JavaScript
8
star
25

paginate-js

Paginate whatever you want, client and server side
JavaScript
6
star
26

screamcasts

Stream GIFS like a boss
JavaScript
6
star
27

mobx-rest-example

Example project built with mobx-rest
JavaScript
4
star
28

php_mongo

Tiny wrapper of the php mongo client
4
star
29

haskell-socket.io

Implementation of the socket-io protocol
Haskell
3
star
30

j

The smallest testing library in nodejs
JavaScript
3
star
31

miniMarkdown

An easy to extend parser for a subset of markdown
JavaScript
3
star
32

crawlr

Grab content and let people vote it
Ruby
3
star
33

backbone-example

a backbone + nodejs example
3
star
34

dotfiles

Vim files
Vim Script
2
star
35

js-styler

A simple functionto do all kind of CSS styling in JS. Works great with React!
JavaScript
2
star
36

underscore.inflection

Better underscore inflection module
JavaScript
2
star
37

you-call-me-maybe

Painless maybe monad for ruby
Ruby
1
star
38

mobx-rest-jquery-adapter

jQuery adapter for mobx-rest
JavaScript
1
star
39

trimmer

Rack endpoint to make templates and i18n translations available in javascript
Ruby
1
star
40

hellog

Hellog is a centralized log server that supports different protocols.
JavaScript
1
star