All Projects → jwbay → i18next-json-sync

jwbay / i18next-json-sync

Licence: MIT license
Keep i18next JSON resource files in sync

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to i18next-json-sync

i18next-fetch-backend
Fetch i18next translations with the fetch API
Stars: ✭ 39 (-11.36%)
Mutual labels:  i18next
i18next-http-backend
i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
Stars: ✭ 270 (+513.64%)
Mutual labels:  i18next
react-i18next-phraseapp
Library support to use react-i18next with the Phrase In-Context Editor - DEPRECATED
Stars: ✭ 14 (-68.18%)
Mutual labels:  i18next
website
The Algorithms website providing GitHub's largest open-source algorithm library.
Stars: ✭ 616 (+1300%)
Mutual labels:  i18next
ad localize
ADLocalize is a simple way to manage your localization files. Supported wording sources : CSVs and Google Sheets. Localization file generation available for iOS, Android, JSON (i18next), YAML and Java properties
Stars: ✭ 22 (-50%)
Mutual labels:  i18next
nextjs-movie-browser
A NextJS implementation of the themoviedb.org website
Stars: ✭ 45 (+2.27%)
Mutual labels:  i18next
i18next-fs-backend
i18next-fs-backend is a backend layer for i18next using in Node.js and for Deno to load translations from the filesystem.
Stars: ✭ 67 (+52.27%)
Mutual labels:  i18next
Next I18next
The easiest way to translate your NextJs apps.
Stars: ✭ 2,818 (+6304.55%)
Mutual labels:  i18next
I18n Ally
🌍 All in one i18n extension for VS Code
Stars: ✭ 1,931 (+4288.64%)
Mutual labels:  i18next
React I18next
Internationalization for react done right. Using the i18next i18n ecosystem.
Stars: ✭ 6,942 (+15677.27%)
Mutual labels:  i18next
i18next-scanner-typescript
Typescript transform for i18next-scanner
Stars: ✭ 21 (-52.27%)
Mutual labels:  i18next
movies
Real world isomorphic application for movies search, based on Webpack 5 / Express / React 17 + Redux-Saga / Bootstrap 4.6 + CSS Modules / i18next / SSR
Stars: ✭ 20 (-54.55%)
Mutual labels:  i18next
web-starter-kit
An opinionated starter kit with styled-system, graphql-hooks, mobx and nextjs (PWA)
Stars: ✭ 17 (-61.36%)
Mutual labels:  i18next
react-native-boilerplate-starter-app
📱🚀A POWERFUL React Native starter kit to bootstrap the start of your mobile app development
Stars: ✭ 202 (+359.09%)
Mutual labels:  i18next
react-sendbird-messenger
ReactJS (React-router-dom v6 + Antdesign + Firebase + Sendbird + Sentry) codebase containing real world examples (CRUD, auth, advanced patterns, etc).
Stars: ✭ 39 (-11.36%)
Mutual labels:  i18next
marko-i18next
Components to use i18next in Marko templates.
Stars: ✭ 13 (-70.45%)
Mutual labels:  i18next
gatsby-i18n
Gatsby plugin that provides i18n support
Stars: ✭ 25 (-43.18%)
Mutual labels:  i18next

Build Status npm

i18next-json-sync

Keeps i18next JSON resource files in sync against a primary language, including plural forms. When hooked up to a build process/CI server, ensures keys added/removed from one language are correctly propagated to the other languages, reducing the chance for missing or obselete keys, merge conflicts, and typos.

Example

Given these files:

 locales
 ├── en.json
 ├── fr.json
 └── ru.json
en.json
{
  "key_one": "value",
  "book": "book",
  "book_plural": "books"
}

fr.json
{
  "key_one": "french value"
}

ru.json
{
  "extra_key": "extra value"
}

fr.json and ru.json can be synced against en.json:

import sync from 'i18next-json-sync'
sync({
  files: 'locales/*.json',
  primary: 'en'
});

resulting in:

en.json
{
  "key_one": "value",
  "book": "book",
  "book_plural": "books"
}

fr.json
{
  "key_one": "french value",
  "book": "book",
  "book_plural": "books"
}

ru.json
{
  "key_one": "value",
  "book_0": "books",
  "book_1": "books",
  "book_2": "books"
}

key_one was left alone in fr.json since it's already localized, but book and book_plural were copied over. An extraneous key in ru.json was deleted and keys from en.json copied over. Plurals are mapped between languages according to the i18next suffix rules.

Note: Languages with only one suffix shared for singular and plural forms will not provide plural mappings if they are used as the primary language.

This works on one folder at a time, but can deal with whatever the files glob returns. Files are grouped into directories before processing starts. Folders without a 'primary' found are ignored.

Usage

$ npm install i18next-json-sync --save-dev

In node.js

import sync from 'i18next-json-sync';
//or in ES5 world:
//const sync = require('i18next-json-sync').default;

//defaults are inline:
sync({
  /** Audit files in memory instead of changing them on the filesystem and
    * throw an error if any changes would be made */
  check: false,
  /** Glob pattern for the resource JSON files */
  files: '**/locales/*.json',
  /** An array of glob patterns to exclude from the files search */
  excludeFiles: ['**/node_modules/**'],
  /** Primary localization language. Other language files will be changed to match */
  primary: 'en',
  /** Language files to create if they don't exist, e.g. ['es, 'pt-BR', 'fr'] */
  createResources: [],
  /** Space value used for JSON.stringify when writing JSON files to disk */
  space: 4,
  /** Line endings used when writing JSON files to disk. Either LF or CRLF */
  lineEndings: 'LF',
  /** Insert a final newline when writing JSON files to disk */
  finalNewline: false,
  /** Use empty string for new keys instead of the primary language value */
  newKeysEmpty: false
})

CLI

It can be installed globally and run with sync-i18n, but package.json scripts are a better fit.

{
  "name": "my-app",
  "scripts": {
    "i18n": "sync-i18n --files '**/locales/*.json' --primary en --languages es fr ja zh ko --space 2",
    "check-i18n": "npm run i18n -- --check"
  }
}

Then use npm run i18n to sync on the filesystem and npm run check-i18n to validate.

All options are available via CLI. Use -h or --help to get help output.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].