# resource-bundle

> resource-bundle is a locale-specific resource loader.

Latest version **0.1.2** (published 2014-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install resource-bundle
pnpm add resource-bundle
yarn add resource-bundle
bun add resource-bundle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-08-29 |
| First published | 2014-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.11.9 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | rocksonzeta |
| Keywords | resource, bundle, resourcebundle, resource bundle, i18n, l10n, locale, localization, internationalize, international, internationalization, nodejs |

## Links

- npm: https://www.npmjs.com/package/resource-bundle
- Repository: https://github.com/RocksonZeta/resource-bundle
- Issues: https://github.com/RocksonZeta/resource-bundle/issues
- npm.io page: https://npm.io/package/resource-bundle

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-08-29
- 0.1.1 — 2014-08-29
- 0.1.0 — 2014-08-29
- 0.0.4 — 2014-08-29
- 0.0.3 — 2014-08-27
- 0.0.2 — 2014-08-27
- 0.0.1 — 2014-08-27

## README

resource-bundle
===============
[![Build Status](https://travis-ci.org/RocksonZeta/resource-bundle.svg?branch=master)](https://travis-ci.org/RocksonZeta/resource-bundle)
[![Coverage Status](https://img.shields.io/coveralls/RocksonZeta/resource-bundle.svg)](https://coveralls.io/r/RocksonZeta/resource-bundle)
[![NPM version](https://badge.fury.io/js/resource-bundle.svg)](http://badge.fury.io/js/resource-bundle)
[![Dependency Status](https://david-dm.org/RocksonZeta/resource-bundle.svg)](https://david-dm.org/RocksonZeta/resource-bundle)

resource-bundle is a locale-specific resource loader based on co.

## NOTE:
Resource-bundle must be used in [co](https://github.com/visionmedia/co) enviroment,such as [koa](https://github.com/koajs/koa).


##Installation
```
$ npm install resource-bundle
```

## Examples
```js
'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
```javascript
module.exports = {
	key:"value",
	intro:"my name is %s,in class %d",
	mk:"%s%s%s"
}
```

## API
### loader
```js
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.

### ResourceBundle Methods

#### get(key,[...])
Returns a corresponding format value. format method ref [util.format](http://nodejs.org/api/util.html#util_util_format_format).

---
_Source: https://npm.io/package/resource-bundle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
