intl-gen
TypeScript icon, indicating that this package has built-in type declarations

1.3.5 • Public • Published

NPM Version license Downloads

IntlGen

IntlGen is a utility that automates the process of translating language files for internationalization (i18n) in your application. It reads a default language file, translates it into multiple target languages, and outputs the translated files into the specified directory structure.

Installation

npm install intl-gen

CLI Usage

  1. Create config file intl.config.mjs

      /** @type {import('intl-gen').Options} */
      export const config = {
          ext: 'json',
          filename: 'translation',
          directory: ['locales'],
          languages: ['en-US', 'id-ID'],
          baseLanguage: 'en-US',
          ignoreExists: true,
          enableSubdirectory: true,
          override: (code) => `translation_${code}`,
      }
  2. Execute bash command

    npx intl-gen -c intl.config.mjs

Options Configuration

The Options interface includes the following fields:

  • directory (string[]): Array of directories where translation files are stored.
  • languages (Language[]): List of languages to translate into, each with a code (ISO 639-1) and title.
  • filename (string): Filename of the default language file.
  • default_language (string): Language code of the base language to translate from.
  • auto_override (boolean, optional): If true, overrides existing translations.
  • skip_region (boolean, optional): If true, skips region-based translations.
  • exclude (string[], optional): Array of language codes to exclude from translation.
  • override_output (ResultCallback, optional): Function to override output filenames.
  • locale_directory (boolean, optional): If true, outputs files directly by language directory.

Example

  • Structure Output Directory

    project-root/
    └── locales/
        ├── en/
        │   └── translation.json
        ├── es/
        │   └── translation_es.json
        └── fr/
            └── translation_fr.json
    
  • Default Language File (translation.json)

    {
      "hello": "Hello",
      "welcome": "Welcome to our application!"
    }
  • Translated Output (translation_es.json)

    {
      "hello": "Hola",
      "welcome": "¡Bienvenido a nuestra aplicación!"
    }

    note: It is recommended to check the results again, and correct them manually if they do not match.

Package Sidebar

Install

npm i intl-gen

Weekly Downloads

2

Version

1.3.5

License

MIT

Unpacked Size

24.6 kB

Total Files

11

Last publish

Collaborators

  • trackingx