Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-parser

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-parser

Command Line tool for i18next

  • 8.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
224K
increased by4.45%
Maintainers
1
Weekly downloads
 
Created

What is i18next-parser?

i18next-parser is a tool that extracts translation keys from your source code to JSON, allowing you to manage and maintain your internationalization (i18n) files more efficiently. It supports various file formats and can be integrated into your build process.

What are i18next-parser's main functionalities?

Extract Translation Keys

This feature allows you to extract translation keys from your source code files and generate JSON files for each locale. The code sample demonstrates how to use i18next-parser to parse JavaScript files in the 'src' directory and output the translations to 'locales/en/translation.json' and 'locales/fr/translation.json'.

const parser = require('i18next-parser');
const fs = require('fs');

const options = {
  locales: ['en', 'fr'],
  output: 'locales/$LOCALE/$NAMESPACE.json'
};

parser.parseFiles('src/**/*.js', options, (err, translations) => {
  if (err) throw err;
  fs.writeFileSync('locales/en/translation.json', JSON.stringify(translations.en, null, 2));
  fs.writeFileSync('locales/fr/translation.json', JSON.stringify(translations.fr, null, 2));
});

Support for Multiple File Formats

i18next-parser supports multiple file formats including JavaScript, JSX, TypeScript, and TSX. The code sample shows how to configure the parser to handle these different file types and extract translations from them.

const parser = require('i18next-parser');
const options = {
  input: ['src/**/*.js', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.tsx'],
  output: 'locales/$LOCALE/$NAMESPACE.json'
};

parser.parseFiles(options.input, options, (err, translations) => {
  if (err) throw err;
  console.log('Translations extracted successfully');
});

Customizable Output

You can customize the output path and separators for namespaces and keys. The code sample demonstrates how to set a custom output path and define custom separators for namespaces and keys.

const parser = require('i18next-parser');
const options = {
  locales: ['en', 'de'],
  output: 'custom_locales/$LOCALE/$NAMESPACE.json',
  namespaceSeparator: ':',
  keySeparator: '.'
};

parser.parseFiles('src/**/*.js', options, (err, translations) => {
  if (err) throw err;
  console.log('Custom output path and separators applied');
});

Other packages similar to i18next-parser

Keywords

FAQs

Package last updated on 07 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc