# loctus

> Simple localization for JavaScript applications.

Latest version **0.0.13** (published 2020-11-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.13 |
| Published | 2020-11-09 |
| First published | 2018-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 36.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Tornike Tsomaia |
| Maintainers | majestyx |

## Links

- npm: https://www.npmjs.com/package/loctus
- npm.io page: https://npm.io/package/loctus

## Recent versions

- 0.0.13 (latest) — 2020-11-09
- 0.0.12 — 2020-11-09
- 0.0.11 — 2020-11-09
- 0.0.10 — 2020-07-28
- 0.0.9 — 2020-07-28
- 0.0.8 — 2020-07-28
- 0.0.7 — 2019-02-08
- 0.0.6 — 2019-02-08
- 0.0.5 — 2019-01-30
- 0.0.4 — 2018-11-27
- 0.0.3 — 2018-11-27
- 0.0.2 — 2018-10-30
- 0.0.1 — 2018-10-30

## README

Simple and easy-to-use localization for JavaScript applications.

### Set up

Create localize function as follows:

    const localize = createLocalizerFactory({
        en: {
            greetGuest: 'Greetings, Guest',
            greetUser: params => `Greetings, ${params.firstName}`,
            greetClient: (params, localize) => params ? localize('greetUser', params) : localize('greetGuest'),
        ka: {
            greetGuest: 'გამარჯობა სტუმარო',
            greetUser: params => `გამარჯობა ${params.firstName}`,
            greetClient: (params, localize) => params ? localize('greetUser', params) : localize('greetGuest'),
        },
    })('en')

Above, createLocalizerFactory takes an object where keys are mapped to objects containing translations.
Translation can either be static or dynamic.
- Static translations are plain strings.
- Dynamic translations take payload and `localize` function and return string.

`createLocalizerFactory` returns memoized function which in turn takes default locale
and when called, returns localize function.

### Usage

Considering the above set-up:

- `localize('greetGuest')` returns "Greetings, Guest" - because default locale is "en".
- `localize('gretGuestt')` returns "gretGuestt" - because neither there is such key as "gretGuestt" under "en" translations above, nor a fallback is specified.
- `localize('gretGuestt', null, 'Hey there')` returns "Hey there" - because, although there is no such key as "gretGuestt" under "en" translations above, but "Hey there" is specified as a fallback.
- `localize('greetGuest', 'ka')` returns "გამარჯობა სტუმარო" - because, although default locale is "en", a custom "ka" locale is passed to `localize` as a fourth argument.
- `localize('greetGuest', null, '', 'ka')` returns "გამარჯობა სტუმარო" - because, although default locale is "en", a custom "ka" locale is passed to `localize` as a fourth argument.
- `localize('greetClient')` returns "Greetings, Guest" when the underline function evaluates.
- `localize('greetClient', { firstName: 'user123' })` returns "Greetings, user123" when the underline function evaluates.

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