i18next-v4-format-converter

This package helps to convert old i18next translation resources to the new i18next v4 json format.

Usage no npm install needed!

<script type="module">
  import i18nextV4FormatConverter from 'https://cdn.skypack.dev/i18next-v4-format-converter';
</script>

README

Introduction

Actions Actions deno npm version

This package helps to convert old i18next translation resources to the new i18next v4 json format.

Online version

There's also a web version you can directly use here.

Getting started

Source can be loaded via npm.

# npm package
$ npm install i18next-v4-format-converter

Usage via code:

import { transformNamespace } from 'i18next-v4-format-converter'
const transformed = transformNamespace('en', {
  someKey: 'normal',
  different: 'normal two',
  myKey: 'singular key',
  myKey_plural: 'plural key'
})
// {
//   someKey: 'normal',
//   different: 'normal two',
//   myKey_one: 'singular key',
//   myKey_other: 'plural key'
// }

for Deno:

import { transformNamespace } from 'https://deno.land/x/i18next_v4_format_converter/index.js'
const transformed = transformNamespace('ar', {
  someKey: 'normal',
  different: 'normal two',
  myKey_0: 'no keys',
  myKey_1: 'one key',
  myKey_2: 'two keys',
  myKey_3: 'few {{count}} keys',
  myKey_4: 'many {{count}} keys',
  myKey_5: 'other {{count}} keys'
})
// {
//   someKey: 'normal',
//   different: 'normal two',
//   myKey_zero: 'no keys',
//   myKey_one: 'one key',
//   myKey_two: 'two keys',
//   myKey_few: 'few {{count}} keys',
//   myKey_many: 'many {{count}} keys',
//   myKey_other: 'other {{count}} keys'
// }

Usage via CLI:

npm install i18next-v4-format-converter -g

# -i is the input path
# -o is the output path
# if the output path is not provided the, it will save the result in the input path (replaces existing files)

i18next-v4-format-converter -i /Users/user/my/input -o /Users/user/my/output
# i18next-v4-format-converter /Users/user/my/input -o /Users/user/my/output
# i18next-v4-format-converter -o /Users/user/my/output
# i18next-v4-format-converter -i /Users/user/my/input
# i18next-v4-format-converter

Make sure your folder structure looks like this:

└── language
   └── namespace.json

i.e.

├── en
│  ├── translation.json
│  └── common.json
└── de
   ├── translation.json
   └── common.json

Gold Sponsors


From the creators of i18next: localization as a service - locize.com

A translation management system built around the i18next ecosystem - locize.com.

locize

With using locize you directly support the future of i18next.