# @tree-house/translations

> Import and use translations through json files

Latest version **3.0.0** (published 2023-11-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @tree-house/translations
pnpm add @tree-house/translations
yarn add @tree-house/translations
bun add @tree-house/translations
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-11-14 |
| First published | 2020-05-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.x |
| Dependencies | 1 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | bonsai-developers, knor-el-snor |
| Keywords | NodeJS, Treehouse, Json, Translations |

## Links

- npm: https://www.npmjs.com/package/@tree-house/translations
- Repository: https://github.com/ShopBonsai/tree-house
- Homepage: https://github.com/ShopBonsai/tree-house/tree/master/packages/core#readme
- Issues: https://github.com/ShopBonsai/tree-house/issues
- npm.io page: https://npm.io/package/@tree-house/translations

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ~4.17.21

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.0 (latest) — 2023-11-14
- 2.3.0 — 2022-07-07
- 2.2.0 — 2022-07-07
- 2.1.0 — 2022-07-07
- 2.0.1 — 2021-11-16
- 2.0.0 — 2021-10-02
- 1.2.0 — 2021-03-04
- 1.1.1 — 2020-07-26
- 1.1.0 — 2020-07-26
- 1.0.0 — 2020-05-20
- 0.0.0 — 2020-05-20

## README

# Tree House Translations

NodeJS tranlations utilities for JSON files.

## Installation

Install via npm

```shell
npm install @tree-house/translations
```

or via yarn

```shell
yarn add @tree-house/translations
```

## NodeJS

### getTranslator

Initialise a translator object pointing to the `.json` files where are translations are being stored and set a default locale. This object contains all functions which you can use after initialisation.

This becomes a singleton instance which will cache your translations globally. **It is not possible at the moment to store translations into different folders.**

```javascript
import { getTranslator } from '@tree-house/translations';

const translator = getTranslator('/locales', 'en');
translator.translate(...);
```

> The name of the translation file needs to match the language name.
> For example: /locales/en.json -> en

### .translate

After initialising the translator you can easily find a translation value by its key for the required language in your localisation files.

```javascript
translator.translate('key_to_translate', 'nl');
```

You can also replace values by using `{{}}` in your string values in the translation files.

```javascript
translator.translate('key_to_translate', 'en', { name: 'Brent' });
```

> This is my new sentence from {{name}} -> This is my new sentence from Brent

## Tests

- You can run `npm run test` to run all tests
- You can run `npm run test:coverage` to run all tests with coverage report

## Bugs

When you find issues, please report them:

- web: [https://github.com/ShopBonsai/tree-house/issues](https://github.com/ShopBonsai/tree-house/issues)

Be sure to include all of the output from the npm command that didn't work as expected. The npm-debug.log file is also helpful to provide.

## Authors

See the list of [contributors](https://github.com/ShopBonsai/tree-house/contributors) who participated in this project.

## License

This project is licensed under the ISC License - see the [LICENSE.md](LICENSE.md) file for details

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