Socket
Socket
Sign inDemoInstall

@startupjs/babel-plugin-i18n-extract

Package Overview
Dependencies
1
Maintainers
6
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @startupjs/babel-plugin-i18n-extract

Extract translation keys


Version published
Maintainers
6
Install size
1.36 MB
Created

Readme

Source

@startupjs/babel-plugin-i18n-extract

Babel Plugin for i18n Automation

This is a Babel plugin that automates i18n tasks by extracting translation keys and default values from your source code. It processes files with the following extensions: js, jsx, ts, tsx, mjs, cjs, web.js, web.jsx, web.ts, web.tsx, web.mjs, and web.cjs.

Installation

To use this plugin, first install it as a dependency:

npm install --save-dev @startupjs/babel-plugin-i18n-extract

Then, add the plugin to your Babel configuration:

{
  "plugins": ["@startupjs/babel-plugin-i18n-extract"]
}

Usage

This plugin looks for the t function imported from the following libraries:

  • startupjs
  • startupjs/i18n
  • @startupjs/i18n

The t function is used to mark strings for translation. It should be called with two string literal arguments: the translation key and the default value.

For example:

import { observer, t } from 'startupjs';

export default observer(function App() {
  return <span>{t('key', 'defaultValue')}</span>;
});

During the build process, the plugin will extract the keys and default values and save them in a translations.json file.

Configuration Options

The plugin accepts an optional collectTranslations configuration option:

{
  "plugins": [
    ["@startupjs/babel-plugin-i18n-extract", { "collectTranslations": true }]
  ]
}

When collectTranslations is set to true, the plugin will merge the translations from different file extensions (web, android, ios) into a single translation object.

Tests

The plugin includes tests to ensure it works correctly. The __tests__/translations.spec.js file checks if the generated translations.json file matches the expected content. The __tests__/index.spec.js file contains various test cases to ensure the plugin behaves as expected.

To run the tests, simply execute:

npm test

License

This plugin is licensed under the MIT License.

Keywords

FAQs

Last updated on 16 Dec 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc