# @zjkuang/i18next-wizard

> This package generates [i18next](https://yarnpkg.com/package/i18next) strings for your app.

Latest version **0.0.18** (published 2022-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zjkuang/i18next-wizard
pnpm add @zjkuang/i18next-wizard
yarn add @zjkuang/i18next-wizard
bun add @zjkuang/i18next-wizard
```

Provides the command `i18next-wizard`.

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.18 |
| Published | 2022-12-30 |
| First published | 2022-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Zhengqian Kuang |
| Maintainers | zjkuang |
| Keywords | i18next, generate, generation |

## Links

- npm: https://www.npmjs.com/package/@zjkuang/i18next-wizard
- Repository: https://github.com/zjkuang/i18next-wizard
- npm.io page: https://npm.io/package/@zjkuang/i18next-wizard

## Dependencies (3)

- [yargs](https://npm.io/package/yargs.md) ^17.6.2
- [app-root-dir](https://npm.io/package/app-root-dir.md) ^1.0.2
- [python-shell](https://npm.io/package/python-shell.md) ^3.0.1

## 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

- 0.0.18 (latest) — 2022-12-30
- 0.0.17 — 2022-12-30
- 0.0.16 — 2022-12-27
- 0.0.15 — 2022-12-27
- 0.0.14 — 2022-12-27
- 0.0.13 — 2022-12-27
- 0.0.12 — 2022-12-26
- 0.0.11 — 2022-12-26
- 0.0.10 — 2022-12-26
- 0.0.9 — 2022-12-26
- 0.0.8 — 2022-12-26
- 0.0.7 — 2022-12-26
- 0.0.6 — 2022-12-26
- 0.0.5 — 2022-12-26
- 0.0.4 — 2022-12-25
- … 3 more at https://npm.io/package/@zjkuang/i18next-wizard/versions

## README

# i18next-wizard

This package generates [i18next](https://yarnpkg.com/package/i18next) strings for your app.

## How to use

(1) Create a folder `yaml` in your app, and define your strings in yaml file(s) in this `yaml` folder. (You can have multiple files for different groups of strings.)  
(2) Run this package as an npx command, providing the input and output path as command line arguments. (The input path defaults to './yaml' and the output path defaults to './generated')

## Example

The yaml script for generating i18next strings should be looking like this:  
`statements.yaml`
```
group: Statements
entries:
  - key: ICameFrom
    translations:
      en: I came from Canada.
      zh_CN: 我来自大陆。
      zh_HK: 我來自香港。
      zh_TW: 我來自台灣。
  - key: ISawGoose
    args:
      - name: count
        type: number
    counted: true
    zero:
      translations:
        en: I saw no goose.
        zh_CN: 我没有看到鹅。
        zh_HK: 我沒有看到鵝。
        zh_TW: 我沒有看到鵝。
    one:
      translations:
        en: I saw a goose.
    other:
      translations:
        en: I saw ${count} geese.
    pluraless:
      translations:
        zh_CN: 我看到${count}只鹅。
        zh_HK: 我看到${count}隻鵝。
        zh_TW: 我看到${count}隻鵝。
```

Note that
```
 - For languages (such as English) in which a noun has different forms for singular and plural, (e.g. "book" and "books",) define `zero`, `one`, `other` for each case.

 - For languages (such as Chinese) in which a noun has the same form for singular and plural, define `zeor` and `pluraless` for each case.
```

Now suppose I have saved this statements.yaml file in `$APP_ROOT/src/assets/strings/yaml`.

To generate the i18next strings, I could run this package from `$APP_ROOT`:
```
npx @zjkuang/i18next-wizard --input src/assets/strings/yaml --output src/assets/strings/generated
```

If everything goes well, you will find the generated i18next strings and functions in the output folder. (`src/assets/strings/generated` for the above example.) The generated folder `.../generated/translations/` contains files for different languages. There is a single file `.../generated/i18nextStrings.ts` looking like this:
```
// Generated file. Don't edit.

import i18next from 'i18next';

export const i18nextStrings = {
  Statements: {
    ICameFrom: () => {
      return i18next.t('Statements.ICameFrom');
    },
    ISawGoose: (count: number) => {
      return i18next.t('Statements.ISawGoose', {
        count,
      });
    },
  },
};
```

Then in your app, you can use them simply by
```
i18nextStrings.Statements.ICameFrom()
```
or
```
i18nextStrings.Statements.ISawGoose(numberOfGeese)
```

The first time you run this npx command, you will be asked
```
Need to install the following packages:
  @zjkuang/i18next-wizard@0.0.14
Ok to proceed? (y) 
```
and you will have to press Enter for the default answer `yes`. But if you are doing a CI/CD, this keyboard interaction will break the automation. To avoid answering the default `yes`, you can do
```
echo y | npx @zjkuang/i18next-wizard
```
And here is an example of adding this npx command to the app's `package.json` "script"
package.json
```
{
  ...
  "scripts": {
    ...
    "string-gen": "cd src/assets/strings && echo y | npx @zjkuang/i18next-wizard && cd ../../..",
    ...
  },
  ...
}
```

## Trouble-shooting

### (1) npx is running the old version
Clean npx cache by
```
rm -rf ~/.npm/_npx
```

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