resource-bundle is a locale-specific resource loader.


resource-bundle is a locale-specific resource loader based on co.

Resource-bundle must be used in co enviroment,such as koa.


$ npm install resource-bundle
'use strict';
var co = require("co");
var loader = require('resource-bundle');
    var message = yield loader("en_US" ,__dirname+"/resources/i18n","message");
    var value = message.get('key');
    var intro = message.get('intro' , 'jim',1); // intro should be 'my name is jim,in class 1' 
    var mk = message.get('mk' , [1,2,3]); // mk should be '123' 

message_en_US.js like this

module.exports = {
    intro:"my name is %s,in class %d",
var loader = require('resource-bundle');
var bundle = loader(locale,dir,baseName);

loader will return ResourceBundle object ,if no resource matched ,it will return null.

  • locale - the locale of the resource. eg. "en_US",'zh_CN'.
  • dir - specify the root dir of the resource file. It is best to use absolute path.
  • baseName - the baseName of the resource.

Resource name should to be baseName_en_US.js or baseName_en_US.json or baseName_en.js or baseName_en.json or baseName.js or baseName.json format. if no locale resource matched,it will use baseName.js or baseName.json by default.

Returns a corresponding format value. format method ref util.format.