All Projects → oliviertassinari → I18n Extract

oliviertassinari / I18n Extract

Licence: mit
Manage localization with static analysis. 🔍

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects

Projects that are alternatives of or similar to I18n Extract

React I18nify
Simple i18n translation and localization components and helpers for React.
Stars: ✭ 123 (-19.08%)
Mutual labels:  translation, i18n, localization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+167.76%)
Mutual labels:  translation, i18n, localization
Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+2037.5%)
Mutual labels:  translation, i18n, localization
Traduora
Ever® Traduora - Open-Source Translation Management Platform
Stars: ✭ 1,580 (+939.47%)
Mutual labels:  translation, localization, i18n
Punic
PHP translation and localization made easy!
Stars: ✭ 133 (-12.5%)
Mutual labels:  translation, i18n, localization
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (-28.29%)
Mutual labels:  translation, i18n, localization
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-17.76%)
Mutual labels:  translation, i18n, localization
labels
Bolt Labels extension - Translatable labels for Bolt
Stars: ✭ 18 (-88.16%)
Mutual labels:  i18n, translation, localization
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+410.53%)
Mutual labels:  translation, i18n, localization
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+323.68%)
Mutual labels:  translation, i18n, localization
Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (+90.79%)
Mutual labels:  translation, i18n, localization
Atom I18n
:atom: One Atom i18n Package for Any Locale 🌏 🌎 🌍
Stars: ✭ 56 (-63.16%)
Mutual labels:  translation, i18n, localization
Tower
i18n & L10n library for Clojure/Script
Stars: ✭ 264 (+73.68%)
Mutual labels:  translation, i18n, localization
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (-25.66%)
Mutual labels:  translation, i18n, localization
Mojito
An automation platform that enables continuous localization.
Stars: ✭ 256 (+68.42%)
Mutual labels:  translation, i18n, localization
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+152.63%)
Mutual labels:  translation, i18n, localization
plate
Internationalization library for Python
Stars: ✭ 31 (-79.61%)
Mutual labels:  i18n, translation, localization
i18n-tag-schema
Generates a json schema for all i18n tagged template literals in your project
Stars: ✭ 15 (-90.13%)
Mutual labels:  i18n, translation, localization
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+309.21%)
Mutual labels:  translation, i18n, localization
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+536.18%)
Mutual labels:  translation, i18n, localization

i18n-extract

Manage localization with static analysis.

npm version npm downloads Build Status

Dependencies DevDependencies

Installation

npm install --save-dev i18n-extract

The problem solved

This module analyses code statically for key usages, such as i18n.t('some.key'), in order to:

  • Report keys that are missing
  • Report keys that are unused.
  • Report keys that are highly duplicated.

E.g. This module works well in conjunction with:

Supported keys

  • static:
i18n('key.static')
  • string concatenation:
i18n('key.' + 'concat')
  • template string:
i18n(`key.template`)
  • dynamic:
i18n(`key.${dynamic}`)
  • comment:
/* i18n-extract key.comment */

API

extractFromCode(code, [options])

Parse the code to extract the argument of calls of i18n(key).

  • code should be a string.
  • Return an array containing keys used.
Example
import {extractFromCode} from 'i18n-extract';
const keys = extractFromCode("const followMe = i18n('b2b.follow');", {
  marker: 'i18n',
});
// keys = ['b2b.follow']

extractFromFiles(files, [options])

Parse the files to extract the argument of calls of i18n(key).

  • files can be either an array of strings or a string. You can also use a glob.
  • Return an array containing keys used in the source code.
Example
import {extractFromFiles} from 'i18n-extract';
const keys = extractFromFiles([
  '*.jsx',
  '*.js',
], {
  marker: 'i18n',
});

Options

  • marker: The name of the internationalized string marker function. Defaults to i18n.
  • keyLoc: An integer indicating the position of the key in the arguments. Defaults to 0. Negative numbers, e.g., -1, indicate a position relative to the end of the argument list.
  • parser: Enum indicate the parser to use, can be typescript or flow. Defaults to flow.
  • babelOptions: A Babel configuration object to allow applying custom transformations or plugins before scanning for i18n keys. Defaults to a config with all babylon plugins enabled.

findMissing(locale, keysUsed)

Report the missing keys. Those keys should probably be translated.

  • locale should be a object containing the translations.
  • keysUsed should be an array. Containes the keys used in the source code. It can be retrieve with extractFromFiles our extractFromCode.
  • Return a report.
Example
import {findMissing} from 'i18n-extract';
const missing = findMissing({
  key1: 'key 1',
}, ['key1', 'key2']);

/**
 * missing = [{
 *   type: 'MISSING',
 *   key: 'key2',
 * }];
 */

Plugins

findUnused(locale, keysUsed)

Report the unused key. Those keys should probably be removed.

  • locale should be a object containing the translations.
  • keysUsed should be an array. Containes the keys used in the source code. It can be retrieve with extractFromFiles our extractFromCode.
  • Return a report.
Example
import {findUnused} from 'i18n-extract';
const unused = findUnused({
  key1: 'key 1',
  key2: 'key 2',
}, ['key1']);

/**
 * unused = [{
 *   type: 'UNUSED',
 *   key: 'key2',
 * }];
 */

findDuplicated(locale, keysUsed, options)

Report the duplicated key. Those keys should probably be mutualized. The default threshold is 1, it will report any duplicated translations.

  • locale should be a object containing the translations.
  • keysUsed should be an array. Containes the keys used in the source code. It can be retrieve with extractFromFiles our extractFromCode.
  • options should be an object. You can provide a threshold property to change the number of duplicated value before it's added to the report.
  • Return a report.
Example
import {findDuplicated} from 'i18n-extract';
const duplicated = findDuplicated({
  key1: 'Key 1',
  key2: 'Key 2',
  key3: 'Key 2',
});

/**
 * unused = [{
 *   type: 'DUPLICATED',
 *   keys: [
 *     'key2',
 *     'key3',
 *   ],
 *   value: 'Key 2',
 * }];
 */

forbidDynamic(locale, keysUsed)

Report any dynamic key. It's arguably more dangerous to use dynamic key. They may break.

  • locale should be a object containing the translations.
  • keysUsed should be an array. Containes the keys used in the source code. It can be retrieve with extractFromFiles our extractFromCode.
  • Return a report.
Example
import {forbidDynamic} from 'i18n-extract';
const forbidDynamic = forbidDynamic({}, ['key.*']);

/**
 * forbidDynamic = [{
 *   type: 'FORBID_DYNAMIC',
 *   key: 'key.*',
 * }];
 */

flatten(object)

Flatten the object.

  • object should be a object.
Example
import {flatten} from 'i18n-extract';
const flattened = flatten({
  key2: 'Key 2',
  key4: {
    key41: 'Key 4.1',
    key42: {
      key421: 'Key 4.2.1',
    },
  },
});

/**
 * flattened = {
 *   key2: 'Key 2',
 *   'key4.key41': 'Key 4.1',
 *   'key4.key42.key421': 'Key 4.2.1',
 * };
 */

mergeMessagesWithPO(messages, poInput, poOutput)

Output a new po file with only the messages present in messages. If a message is already present in the poInput, we keep the translation. If a message is not present, we add a new empty translation.

  • messages should be an array.
  • poInput should be a string.
  • poOutput should be a string.
Example
import {mergeMessagesWithPO} from 'i18n-extract';

const messages = ['Message 1', 'Message 2'];
mergeMessagesWithPO(messages, 'messages.po', 'messages.output.po');

/**
 * Will output :
 * > messages.output.po has 812 messages.
 * > We have added 7 messages.
 * > We have removed 3 messages.
 */

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].