@valueadd/translations-finder
TypeScript icon, indicating that this package has built-in type declarations

2.8.6 • Public • Published

Translations Finder

Finds missing translations in your project.

Installation

Install with npm

# Locally
npm i translations-finder

# Globally
npm i -g translations-finder

Usage

import { findMissingTranslations } from "translations-finder";

const missingTranslations = findMissingTranslations(
  definedTranslations,
  globFilePattern,
  regexTranslation,
  regexTranslationKey,
  directory
);

definedTranslations is an object of keys assigned to translations.

{
  common: {
    login: "Login",
    logout: "Logout",
    menu: {
      title: "The Boring Company"
    }
  }
}

globFilePattern is the glob matcher for files.

"{,!(node_modules)/**/}*.html";

regexTransaltion is a regular expression that is supposed to match the translation key or the text that includes the translation key.

// Matches {{ 'common.author' | translate }}
/('+[A-Za-z]+\.[A-Za-z]+')( \| translate)/g;

regexTranslationKey is a an optional parameter which can be used to extract the actual key from the found text.

// Extracts the key common.author from the previous matching.
/([A-Za-z]+(\.[A-Za-z]+)+)+/g;

directory is an optional parameter that is used as a root directory to search in. When not provided, the value is equal to process.cwt().

Example usage

import { findMissingTranslations } from "translations-finder";

preparedTranslations = {
  common: {
    login: "Login",
    logout: "Logout",
    menu: {
      title: "The Boring Company",
    },
  },
};

const missingTranslations = findMissingTranslations(
  preparedTranslations,
  "{,!(node_modules)/**/}*.html",
  /('+[A-Za-z]+\.[A-Za-z]+')( \| translate)/g,
  /([A-Za-z]+(\.[A-Za-z]+)+)+/g
);

Package Sidebar

Install

npm i @valueadd/translations-finder

Weekly Downloads

0

Version

2.8.6

License

MIT

Unpacked Size

116 kB

Total Files

25

Last publish

Collaborators

  • michal-valueadd
  • mateusz-dobrowolski-va
  • matelener
  • va-admin
  • krzysztofskorupkadev
  • valueadd-robot
  • sikora00
  • mateuszbasinski-va
  • mateusz.stefanczyk