# @ewb/translate-minify

> Minified version of @ewb/translate. This should be used in production instead.

Latest version **2.0.1** (published 2022-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ewb/translate-minify
pnpm add @ewb/translate-minify
yarn add @ewb/translate-minify
bun add @ewb/translate-minify
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-11-29 |
| First published | 2019-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Emils Webbod |
| Maintainers | emilswebbod |
| Keywords | typescript, npm, translate, easy, small, minfied, lazy |

## Links

- npm: https://www.npmjs.com/package/@ewb/translate-minify
- Repository: https://github.com/EmilsWebbod/translate-minify
- Homepage: https://github.com/EmilsWebbod/translate-minify#readme
- Issues: https://github.com/EmilsWebbod/translate-minify/issues
- npm.io page: https://npm.io/package/@ewb/translate-minify

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-11-29
- 2.0.0 — 2022-11-28
- 1.3.7 — 2022-10-30
- 1.3.6 — 2022-10-29
- 1.3.5 — 2022-10-29
- 1.3.4 — 2022-10-29
- 1.3.3 — 2021-08-16
- 1.3.2 — 2020-11-10
- 1.3.1 — 2020-10-08
- 1.3.0 — 2020-10-08
- 1.2.4 — 2020-08-25
- 1.2.3 — 2020-01-21
- 1.2.2 — 2019-09-21
- 1.2.1 — 2019-09-21
- 1.2.0 — 2019-09-20
- … 1 more at https://npm.io/package/@ewb/translate-minify/versions

## README

# Translate library minify

[![npm version](https://badge.fury.io/js/%40ewb%2Ftranslate-minify.svg)](https://badge.fury.io/js/%40ewb%2Ftranslate-minify)
[![CircleCI](https://circleci.com/gh/EmilsWebbod/translate-minify.svg?style=svg)](https://circleci.com/gh/EmilsWebbod/translate-minify)
[![Coverage Status](https://coveralls.io/repos/github/EmilsWebbod/translate-minify/badge.svg?branch=master)](https://coveralls.io/github/EmilsWebbod/translate-minify?branch=master)
[![GZIP](https://badgen.net/badge/gzip/723B/green)]()

Minified version of [@ewb/translate](https://github.com/EmilsWebbod/translate)  
This should be used in production instead of @ewb/translate  
Supports lazy loaded `words` and `texts` with 4 new functions. `addWords` `addTexts` `addWordsTranslations` `addTextsTranslations`

This library is much faster to lookup but has no add functions that changes your json files.

## Install

```
yarn add @ewb/translate

npm install -s @ewb/translate
```

## Quick guide

```
import TranslateMinify from '@ewb/translate-minify';
import words from './words.json';
import texts from './texts.json';

const translate = new TranslateMinify({
    defaultLocale: 'en',
    locale: 'no',
    words,
    texts
});

translate.word('Hello') // Hei
translate.text('Hello to you too') // Hei, til deg også

translate.setLocale('sv')
translate.w('Hello') // Hej
translate.t('Hello to you too') // Hej, till dig också

translate.w('Hello', 'no') // Hei
translate.t('Are you {{age}} years old?', { age: 10 }) // Är du 10 år gammal?
translate.t('Are you {{age}} years old?', { locale: 'no', age: 10 }) // Er du 10 år gammel?
```

## Lazy load

Added mass loading of new `words` or `texts` with new functions `addWords` and `addTexts`  
And translations with functions `addWordsTranslations` and `addTextsTranslations`

Lazy load then from disk or get them from a database. Your choice.

## Interfaces

```
interface WordTranslations {
  [word: string]: {
    [translation: string]: string;
  };
}

interface TranslateMinifyOptions {
  defaultLocale: string;
  locale: string;
  words?: WordTranslations;
  texts?: WordTranslations;
}

interface Variables {
  [variable: string]: string | number | undefined;
}

interface TextOptions extends Variables {
  locale?: string;
}
```

## Class definitions

```
export default class TranslateMinify {

  constructor(opts: TranslateMinifyOptions) : void;

  public w(word: string, locale?: string): string;
  public word(word: string, locale?: string): string;

  public t(text: string, opts?: TextOptions): string;
  public text(text: string, opts?: TextOptions): string;

  public setLocale(locale: string): void;

  public addWords(newWords: WordTranslations): void;
  public addTexts(newTexts: WordTranslations): void;

  public addWordsTranslations(translations: WordTranslations): void;
  public addTextsTranslations(translations: WordTranslations): void;
}
```

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