# displaykey

> Enables you to localize your content by storing each locale-specific version of it in a separate JSON file.

Latest version **0.2.2** (published 2015-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install displaykey
pnpm add displaykey
yarn add displaykey
bun add displaykey
```

## 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.2.2 |
| Published | 2015-11-13 |
| First published | 2015-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gavin Flood |
| Maintainers | gavinflud |
| Keywords | displaykey, localization, localize, language, region, different |

## Links

- npm: https://www.npmjs.com/package/displaykey
- Repository: https://github.com/gavinflud/displaykey
- Homepage: https://github.com/gavinflud/displaykey#readme
- Issues: https://github.com/gavinflud/displaykey/issues
- npm.io page: https://npm.io/package/displaykey

## Recent versions

- 0.2.2 (latest) — 2015-11-13
- 0.2.1 — 2015-11-13
- 0.0.2 — 2015-11-12

## README

# displaykey

[![Build Status](http://ec2-52-30-212-133.eu-west-1.compute.amazonaws.com/jenkins/buildStatus/icon?job=displaykey%20(Build))](http://ec2-52-30-212-133.eu-west-1.compute.amazonaws.com/jenkins/job/displaykey%20(Build)/)

Simple text localization for your node.js application.

## Example

```javascript
var displaykey = require('displaykey');

var pathToLocaleFiles = require('path').join(__dirname, 'path/to/locale/files');
var refreshInterval = 30000;
displaykey.setup(pathToLocaleFiles, refreshInterval, function() {
    var value = displaykey.get('some.value.in.json.file', 'en');
});
```

## Installation

```
$ npm install displaykey
```

## Usage

### Locale Files

displaykey loads in the different locale-specific values from JSON files. You need to create a directory to store these
JSON files (it cannot contain anything other than these files). The format of the files should be similar to the
following:

```json
{
    "key": "value",
    "some": {
        "nested": {
            "key": "some nested value"
        }
    }
}
```

You should have one of these files created for each locale you plan to support. Name them appropriately, since the name
you use will be used as the locale code that is passed into the `get()` function (minus the '.json' extension).

### Setting Up

After installing using npm, you must setup displaykey to load in locale-specific JSON files from the correct directory
and tell it how often to check for changes to these files and load them in. To do this, it exposes the `setup()`
function.

```javascript
var displaykey = require('displaykey');

// Set an absolute path to the locale-specific JSON files.
var pathToLocaleFiles = require('path').join(__dirname, 'path/to/locale/files');

// Set the refresh interval in milliseconds.
var refreshInterval = 30000;

// Call the setup function, passing in these values.
// It will invoke the callback function when all displaykeys are loaded.
displaykey.setup(pathToLocaleFiles, refreshInterval, function() {
    // Now you can use the get() function to get any displaykey from any locale.
});
```

### Getting Values

Now that everything is set up, you are able to use the displaykey module in all it's glory. The `get()` function
provides you with the ability to get the value of something for a specific locale. You can use it as follows:

```javascript
displaykey.get('some.nested.key', 'en');
```

where `'some.nested.key'` is a nested key in each of the locale files, and `'en'` is the name of the locale file to retrieve
the value from.

Therefore, if you have two locale files like so:

#### en.json
```json
{
    "key": "english value",
    "some": {
        "nested": {
            "key": "some nested english value"
        }
    }
}
```

#### fr.json
```json
{
    "key": "french value",
    "some": {
        "nested": {
            "key": "some nested french value"
        }
    }
}
```

The call to `get()` above would return `'some nested english value'`.

## License

MIT &copy; 2015 Gavin Flood

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