rb

resource-bundle

resource-bundle is a locale-specific resource loader.

Showing:

Popularity

Downloads/wk

26

GitHub Stars

0

Maintenance

Last Commit

7yrs ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

resource-bundle

Build Status Coverage Status NPM version Dependency Status

NPM

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

NOTE:

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

##Installation

$ npm install resource-bundle

Examples

'use strict';
var co = require("co");
var loader = require('resource-bundle');
co(function*(){
    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 = {
    key:"value",
    intro:"my name is %s,in class %d",
    mk:"%s%s%s"
}

API

loader

var loader = require('resource-bundle');
var bundle = yield 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.

ResourceBundle Methods

get(key,[...])

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100