All Projects → mxmvshnvsk → i18n-unused

mxmvshnvsk / i18n-unused

Licence: MIT license
The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project

Programming Languages

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

Projects that are alternatives of or similar to i18n-unused

Svelte I18n
Internationalization library for Svelte
Stars: ✭ 433 (+469.74%)
Mutual labels:  i18n, internationalization, svelte
awesome-i18n
🌍 A curated list of i18n resources for all kind of languages and frameworks
Stars: ✭ 205 (+169.74%)
Mutual labels:  i18n, internationalization
doorkeeper-i18n
Translation files for Doorkeeper OAuth 2 provider
Stars: ✭ 30 (-60.53%)
Mutual labels:  i18n, internationalization
ember-i18n-cp-validations
ember-i18n support for ember-cp-validations
Stars: ✭ 20 (-73.68%)
Mutual labels:  i18n, internationalization
mini i18n
🌐 Minimalistic I18n library for Ruby
Stars: ✭ 93 (+22.37%)
Mutual labels:  i18n, internationalization
react-mobx-router
Create React App with React Router 4 and MobX + Internationalization
Stars: ✭ 90 (+18.42%)
Mutual labels:  i18n, internationalization
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (-76.32%)
Mutual labels:  i18n, internationalization
Flutter translate
Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
Stars: ✭ 245 (+222.37%)
Mutual labels:  i18n, internationalization
i18n lazy scope
Use lazy lookup with custom i18n scopes.
Stars: ✭ 11 (-85.53%)
Mutual labels:  i18n, internationalization
figma-static-localizer
A Figma plugin for static localization
Stars: ✭ 30 (-60.53%)
Mutual labels:  i18n, internationalization
android-studio-plugin
Integrate your Android project with Crowdin
Stars: ✭ 52 (-31.58%)
Mutual labels:  i18n, internationalization
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 (-71.05%)
Mutual labels:  i18n, internationalization
laminas-i18n
Provide translations for your application, and filter and validate internationalized values
Stars: ✭ 40 (-47.37%)
Mutual labels:  i18n, internationalization
pH7-Internationalization
🎌 pH7CMS Internationalization (I18N) package 🙊 Get new languages for your pH7CMS website!
Stars: ✭ 17 (-77.63%)
Mutual labels:  i18n, internationalization
React Native Globalize
Internationalization (i18n) for React Native
Stars: ✭ 246 (+223.68%)
Mutual labels:  i18n, internationalization
typesafe-i18n
A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.
Stars: ✭ 1,227 (+1514.47%)
Mutual labels:  i18n, internationalization
go-localize
i18n (Internationalization and localization) engine written in Go, used for translating locale strings.
Stars: ✭ 45 (-40.79%)
Mutual labels:  i18n, internationalization
L10ns
Internationalization workflow and formatting
Stars: ✭ 234 (+207.89%)
Mutual labels:  i18n, internationalization
A18n
Automated I18n solution for JavaScript/TypeScript/React
Stars: ✭ 244 (+221.05%)
Mutual labels:  i18n, internationalization
rails
Rails translation made _('simple').
Stars: ✭ 65 (-14.47%)
Mutual labels:  i18n, internationalization

i18n-unused

npm npm

The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project.

Installation

With npm:

npm install --save-dev i18n-unused

With yarn:

yarn add --dev i18n-unused

Configuration

Add config i18n-unused.config.js to your root folder:

module.exports = {
  localesPath: 'src/locales',
  srcPath: 'src',
};

Configuration options

Option name
Description
Required Type
Default value
localesPath path to search for locales yes string -
localesExtensions allowed file extensions for locales no string[] if not set localeNameResolver: ['json']
localeNameResolver file name resolver for locales no RegExp, (name: string) => boolean -
localeFileParser resolve locale imports, for example if you use named imports from locales files, just wrap it to your own resolver no (module) => module fn, return module.default or module
localeFileLoader load the locale file manually (e.g. for using your own parser) no (filePath) => object -
srcPath path to search for translations no string '' (same as run folder)
srcExtensions allowed file extensions for translations no string[] ['js', 'ts', 'jsx', 'tsx', 'vue']
ignorePaths ignored paths, eg: ['src/ignored-folder'], should start similarly srcPath no string[] -
translationKeyMatcher matcher to searching for translation keys in files no RegExp RegExp, match $_, $t, t, $tc, tc and i18nKey
excludeKey doesn't process translations that include passed key(s), for example if you set excludeKey: '.props.', script will ignore Button.props.value. no string, string[] -
ignoreComments Ignore code comments in src files. no boolean false
marker special string to mark unused translations, it'll added via mark-unused no string '[UNUSED]'
gitCheck show git state change tree no boolean false
context use i18n context, (eg: plurals) no boolean true
flatTranslations use flat translations, (eg: Flat JSON) no boolean false
translationSeparator separator for translations using in code no string '.'
translationContextSeparator separator for i18n context (see context option) no string '_'

Usage

Get help:

i18n-unused -h

Display unused translations:

i18n-unused display-unused

Mark unused translations via [UNUSED] or marker from config (works only with json for now):

i18n-unused mark-unused

Remove unused translations (works only with json for now):

i18n-unused remove-unused

Sync translations (works only with json for now):

i18n-unused sync <source> <target>

Display missed translations:

i18n-unused display-missed

Usage in code

collectUnusedTranslations

If you use tool in code, you can run async function collectUnusedTranslations:

import { collectUnusedTranslations } from 'i18n-unused';

const handleTranslations = async () => {
  const unusedTranslations = await collectUnusedTranslations(
    localesPaths, // paths to locale files
    srcFilesPaths, // paths to src files
    {
      localeFileParser: (module) => module, // optional, resolver for module
      excludeTranslationKey: ['.props.'], // optional, special string or sting[] to exclude flat translations
    },
  );
};

It'll return to you follow collect:

{
  translations: [
    {
      localePath: 'locale_file_path',
      keys: ['unused_key'],
      count: 1,
    },
  ],
  totalCount: 1,
}

collectMissedTranslations

If you use tool in code, you can run async function collectMissedTranslations:

import { collectMissedTranslations } from 'i18n-unused';

const handleTranslations = async () => {
  const missedTranslations = await collectMissedTranslations(
    localesPaths, // paths to locale files
    srcFilesPaths, // paths to src files
    {
      localeFileParser: (module) => module, // optional, resolver for module
      excludeTranslationKey: ['.props.'], // optional, special string or sting[] to exclude flat translations
      translationKeyMatcher: /(?:[$ .](_|t|tc))\(.*?\)/ig, // optional, match translation keys in files
    },
  );
};

You'll get the following collection:

{
  translations: [
    {
      filePath: 'src_file_path',
      staticKeys: ['missed_key'], // keys without ${} syntax
      dynamicKeys: ['missed_key'], // keys with ${} syntax
      staticCount: 1,
      dynamicCount: 1,
    },
  ],
  totalStaticCount: 1,
  totalDynamicCount: 1,
}

generateFilesPaths

Available as async function generateFilesPaths:

import { generateFilesPaths } from 'i18n-unused';

const handleFilesPaths = async () => {
  // return array of full paths to files
  const filesPaths = await generateFilesPaths(
    srcPath, // path where search files, example: 'src/locales'
    {
      srcExtensions, // allowed file extensions, example: ['js', 'ts']
      fileNameResolver, // resolver for file name, see more info about 'localeNameResolver' option
    },
  );
};

Action results

Next actions return unusedTranslations:

  • displayUnusedTranslations
  • removeUnusedTranslations
  • markUnusedTranslations

Next actions return missedTranslations:

  • displayMissedTranslations

What else?

If the tool helped you, please rate it on github, thx. I'll be glad to your PRs =)

License

MIT License. Maxim Vishnevsky

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