# i18next-locales-sync

> Syncs i18next locale resource files against a primary language.

Latest version **2.1.1** (published 2025-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install i18next-locales-sync
pnpm add i18next-locales-sync
yarn add i18next-locales-sync
bun add i18next-locales-sync
```

Provides the command `i18next-locales-sync`.

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2025-02-26 |
| First published | 2021-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 5 |
| Unpacked size | 45.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | felixmosh |
| Maintainers | felixmosh |
| Keywords | i18next, locale, sync |

## Links

- npm: https://www.npmjs.com/package/i18next-locales-sync
- Repository: https://github.com/felixmosh/i18next-locales-sync
- Issues: https://github.com/felixmosh/i18next-locales-sync/issues
- npm.io page: https://npm.io/package/i18next-locales-sync

## Dependencies (5)

- [fdir](https://npm.io/package/fdir.md) ^6.1.1
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [yargs](https://npm.io/package/yargs.md) ^17.5.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [picomatch](https://npm.io/package/picomatch.md) ^4.0.2

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2025-02-26
- 2.1.0 — 2024-07-04
- 2.0.1 — 2022-08-10
- 2.0.0 — 2022-07-04
- 1.2.1 — 2022-06-24
- 1.2.0 — 2022-06-18
- 1.1.2 — 2022-04-28
- 1.1.1 — 2021-08-26
- 1.1.0 — 2021-06-01
- 1.0.4 — 2021-05-02
- 1.0.3 — 2021-02-12
- 1.0.2 — 2021-02-12
- 1.0.1 — 2021-02-11
- 1.0.0 — 2021-02-11

## README

# i18next-locales-sync

![CI](https://github.com/felixmosh/i18next-locales-sync/workflows/CI/badge.svg)
[![npm](https://img.shields.io/npm/v/i18next-locales-sync.svg)](https://www.npmjs.com/package/i18next-locales-sync)

Syncs [i18next](https://github.com/i18next/i18next) locale resource files against a primary language.

## Installation

```sh
$ npm install --save-dev i18next-locales-sync
```

## Features

1. Supports [namespaces](https://www.i18next.com/principles/namespaces).
2. Full plural support, based on the real [i18next pluralResolver](https://github.com/felixmosh/i18next-locales-sync/blob/master/src/i18next/PluralResolver.ts).
3. Supports JSON v4
4. Sorting secondary locale keys by primary language order.
5. Supports multiple locale folder structure, `{lng}/{namespace}`, `{namespace}/{lng}`.
6. Creates missing locale files.
7. Allows overriding plural rules.

## Usage

### 1. CLI

```sh
$ npx i18next-locales-sync -p he -s en de ja -l path/to/locales/folder --spaces 2
```

or using config file

```js
// localesSync.config.js
module.exports = {
  primaryLanguage: 'he',
  secondaryLanguages: ['en', 'de', 'ja'],
  localesFolder: './path/to/locales/folder',
  overridePluralRules: (pluralResolver) =>
    pluralResolver.addRule('he', pluralResolver.getRule('en')), // This is available only when using config file
  spaces: 2,
};
```

```sh
$ npx i18next-locales-sync -c ./localesSync.config.js
```

### 2. Node

```js
import { syncLocales } from 'i18next-locales-sync';
import path from 'path';

syncLocales({
  primaryLanguage: 'en',
  secondaryLanguages: ['en', 'de', 'ja'],
  localesFolder: path.resolve('./path/to/locales/folder'),
  overridePluralRules: (pluralResolver) =>
    pluralResolver.addRule('he', pluralResolver.getRule('en')),
});
```

## Options

| Key                 | Type                                                  | Default value   |
| ------------------- |-------------------------------------------------------|-----------------|
| primaryLanguage     | `string`                                              |                 |
| secondaryLanguages  | `string[]`                                            |                 |
| localesFolder       | `string`                                              |                 |
| outputFolder        | `string?`                                             | `localesFolder` |
| overridePluralRules | `(pluralResolver: PluralResolver)? => PluralResolver` |                 |
| useEmptyString      | `boolean`                                             | `false`         |
| spaces              | `number`                                              | `2`             |
| compatibilityJSON   | `string`                                              | `v4`            |

Currently, the lib supports only `.json` locale files, PRs are welcome :].

## Example

Given these files:

```sh
examples
├── en
│   └── namespace.json
├── he
│   └── namespace.json
└── ja
    └── namespace.json
```

```json
// en/namespace.json
{
  "foo_male": "bar-male-en",
  "room_one": "room",
  "room_other": "rooms"
}
```

```json
// he/namespace.json
{
  "room": "חדר",
  "foo_male": "bar-male-he",
  "room_few": "חדרים"
}
```

```json
// ja/namespace.json
{
  "foo_male": "bar-male-ja",
  "room": "部屋",
  "room_other": "部屋"
}
```

Syncying `he` & `ja` against `en`

```sh
$ npx i18next-locales-sync -p en -s he ja -l ./examples/
```

Will result with

```json
// en/namespace.json

// `en` remains untouched
{
  "foo_male": "bar-male-en",
  "room_one": "room",
  "room_other": "rooms"
}
```

```json
// he/namespace.json

// sorted based on the primary lang file
// keeps existing plural form (room_3)
// added missing plural forms
{
  "foo_male": "bar-male-he",
  "room_one": "חדר",
  "room_two": "חדרים",
  "room_few": "rooms",
  "room_other": "rooms"
}
```

```json
// ja/namespace.json

// keeps exising fields
// removed plural form since there is no plural form in Japanese
{
  "foo_male": "bar-male-ja",
  "room": "部屋"
}
```

### Prior art

1. [i18next-json-sync](https://github.com/jwbay/i18next-json-sync)

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