0.55.8 • Published 4 months ago

@startupjs/babel-plugin-i18n-extract v0.55.8

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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

0.56.0-alpha.0

4 months ago

0.55.7

5 months ago

0.55.8

5 months ago

0.55.1

6 months ago

0.55.0-alpha.1

7 months ago

0.55.0

6 months ago

0.54.1

7 months ago

0.53.0

9 months ago

0.54.0

7 months ago

0.52.1

12 months ago

0.51.0

12 months ago

0.52.0

12 months ago

0.50.13

1 year ago

0.50.12

1 year ago

0.50.5

1 year ago

0.48.0

2 years ago

0.49.0

1 year ago

0.47.0

2 years ago

0.46.0

2 years ago

0.45.0

2 years ago

0.44.0

2 years ago

0.42.0

2 years ago

0.43.0

2 years ago

0.41.2

2 years ago

0.41.0

2 years ago

0.43.1

2 years ago

0.39.11

3 years ago

0.40.0

3 years ago

0.39.0

3 years ago

0.38.3

3 years ago

0.38.0

3 years ago

0.37.7

3 years ago

0.37.6

3 years ago

0.37.0

3 years ago

0.36.0

3 years ago