Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zuoez02/http-code-translator

Translate http error code into your language
https://github.com/zuoez02/http-code-translator

Last synced: about 1 month ago
JSON representation

Translate http error code into your language

Awesome Lists containing this project

README

        

# Http code translator

Translate http code into your languange.

## Install

```bash
npm install --save http-code-translator
```
or
```bash
yarn add http-code-translator
```

## Usage

```javascript
// load the module
const HttpCodeTranslator = require('http-code-translator');

// current support language is English and Chinese
const codeTranslator = new HttpCodeTranslator('en');

// load language manually
// Language code is ISO 639-1
codeTranslator.loadLanguage('zh');
// or load the translation map
codeTranslator.loadTranslation({
// must have a default value when code not found
defaultValue: 'Unknown value',
200: 'OK',
});

// translate code
codeTranslator.translate(200); // OK
codeTranslator.translate("200"); // OK
codeTranslator.translate("299"); // Unkonw value

// Set default value
codeTranslator.setDefaultValue("The code is unknown");
codeTranslator.translate("299"); // The code is unknown
```

## Typings

Typings is set in `index.d.ts` for typescript or code in VS code.

## LICENSE

MIT