DailyJS

DailyJS

The JavaScript blog.


Taginternationalisation
Featured

node modules WebSocket internationalisation

Node Roundup: SocketCluster, i18n-generator, generator-gulp-angular

Posted on .

SocketCluster

SocketCluster (GitHub: TopCloud / socketcluster, npm: socketcluster) is a WebSocket server designed with clustering in mind. The developers have tested for memory leaks and included benchmarks. It handles client reconnection if a server crashes, and has a clustered memory store for temporary session data.

SocketCluster lets you store session data using the socket.session object. This object gives you access to a cluster of in-memory stores called nData. You can effectively invoke any of the methods documented here to store and retrieve session data: https://github.com/topcloud/ndata

Basic usage looks like this:

var SocketCluster = require('socketcluster').SocketCluster;

var socketCluster = new SocketCluster({  
  workers: [9100, 9101, 9102],
  stores: [9001, 9002, 9003],
  balancerCount: 1,
  port: 8000,
  appName: 'myapp',
  workerController: 'worker.js',
  rebootWorkerOnError: false,
  addressSocketLimit: 50
});

The project is built with iocluster and loadbalancer, by the same authors.

i18n-generator

i18n-generator (GitHub: huei90 / i18n-generator, License: MIT, npm: i18n-generator) by Huei Tan is a library for converting i18n text files into JSON.

For example, given this input:

i18n=> | en | zh_TW | de | my  
you | you | 你 | Du | kamu  
I | I | 我 | ich | Saya  
love | love | 喜歡 | liebe | cinta  
eat | eat | 吃 | essen | makan  
ilovegithub | i love github | 我愛 Github | ich liebe Github | Saya cinta pada Github  

It would generate this:

{"you":"you","I":"I","love":"love","eat":"eat","ilovegithub":"i love github"}

for each language. It comes with tests and browser support.

generator-gulp-angular

I find it difficult to work on MVVM projects without some sort of build system so I can at least structure the project with CommonJS or AMD. generator-gulp-angular gives you a Yeoman generator that uses Gulp, Bowser, and AngularJS.

This generator aims to takes the best from others generators like generator-angular, ngTailor and generator-gulp-webapp to offers the best workflow to start an application with AngularJS powered by Gulp!

generator-gulp-angular scaffolds out an AngularJS application with a full featured gulpfile.js which offers all the tasks for modern web development.

It seems like a good way to get started with Gulp and AngularJS, which can actually be a little bit daunting.

Featured

testing node modules npm internationalisation

Node Roundup: No More Force Publish, Counterpart, mock-fs

Posted on .

No More Force Publish

Isaac Z. Schlueter wrote on npm's blog that publish -f will no longer work:

If you publish foo@1.2.3, you can still un-publish foo@1.2.3. But then, you will not be able to publish something else to that same package identifier and version. Ever.

The common wisdom is changing the code that a version number describes is dangerous, so it's better to publish a new version. If you're a module author, you may feel that this is frustrating -- what if you just released something with a dangerous security flaw? In cases like this it may be best to remove the version and publish a new, fixed version.

Counterpart

Counterpart (GitHub: martinandert / counterpart, License: MIT, npm: counterpart) by Martin Andert is an internationalisation module based on Ruby's I18n gem:

translate('damals.about_x_hours_ago.one')          // => 'about one hour ago'  
translate(['damals', 'about_x_hours_ago', 'one'])  // => 'about one hour ago'  
translate(['damals', 'about_x_hours_ago.one'])     // => 'about one hour ago'  

You can write translation documents using JSON. Features include interpolation, pluralisation, and default fallbacks.

mock-fs

mock-fs (GitHub: tschaub / mock-fs, License: MIT, npm: mock-fs) by Tim Schaub is an API-compatible version of Node's fs module that essentially allows you to temporarily use an in-memory filesystem.

It provides a mock function that accepts a specification of the files you want to mock:

mock({  
  'path/to/fake/dir': {
    'some-file.txt': 'file content here',
    'empty-dir': {/** empty directory */}
  },
  'path/to/some.png': new Buffer([8, 6, 7, 5, 3, 0, 9]),
  'some/other/path': {/** another empty directory */}
});

You might find this useful if you want to write tests that avoid touching real files.