Skip to content

nikolas2145/i18nize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

i18nize

CI Gem Version

🧠 Automatically fills in missing I18n YAML keys using DeepL translation API. Designed to streamline multi-language support in Ruby and Rails projects.

✨ Features

  • Detects missing or empty translation keys in locale files
  • Supports multiple YAML files and nested directories (e.g. config/locales/api/en.yml)
  • Automatically translates from a source locale (default: en) to a target (e.g. cs)
  • Placeholder mode to fill only blank/missing keys without DeepL (--only_blank)
  • Integrates with DeepL API (Free or Pro)
  • Safely merges translations into corresponding *.yml files
  • Handles structural conflicts by overwriting target with source truth
  • Character count check with confirmation prompt
  • CLI (i18nize)

πŸ”§ Installation

Add this line to your application's Gemfile:

gem "i18nize"

Then run:

bundle install

Or install manually:

gem install i18nize

πŸš€ Usage

1. Set your DeepL API key

Create a .env file (loaded automatically if you use dotenv) or export it in your shell:

export DEEPL_API_KEY=your-api-key
export DEEPL_ENDPOINT=https://api.deepl.com/v2/translate # Only if you are using a DeepL Pro account

πŸ‘‰ You can use the Free DeepL API.

2. Run translations via CLI

# Translate from en β†’ cs
i18nize cs

# Translate from de β†’ fr
i18nize fr --from de

πŸ’¬ This will:

  • Scan config/locales/**/*en.yml (or your chosen source language)
  • Detect which cs.yml files are missing keys
  • Use DeepL to translate missing values
  • Write them to the appropriate files (creating them if needed)

3. Show missing keys only

# Missing cs keys (source en)
i18nize cs --missing

# Missing cs keys (source de)
i18nize cs --missing de

This mode only lists missing keys, no translations are written.

4. Fill placeholders for blank/missing keys (no DeepL)

# Insert placeholders instead of translating
i18nize cs --only_blank

This scans all keys in the source locale (default en) and, for any missing or blank value in the target locale, inserts a placeholder:

<locale>.<full.dot.key> missing

Example:

en:
  test:
    title: "Testing"
cs:
  test:
    title: "cs.test.title missing"

Existing non-blank values in the target are left untouched.

πŸ›‘οΈ Character limit check

Before translating, the CLI:

  • Counts the total number of characters
  • Warns if the count exceeds 500,000 (DeepL Free monthly limit)
  • Asks for confirmation:
[i18nize] Estimated character count: 43125
Proceed with translation? [y/N]:

πŸ—‚οΈ Locale file support

  • Files are matched by name:

    • config/locales/api/en.yml β†’ config/locales/api/cs.yml
    • config/locales/en.devise.yml β†’ config/locales/cs.devise.yml
  • Missing files are created automatically

  • If a scalar exists where a nested structure is required, it is overwritten by source locale structure

🧩 Example structure

config/locales/
β”œβ”€β”€ api/
β”‚   └── en.yml
β”œβ”€β”€ errors/
β”‚   β”œβ”€β”€ en.yml
β”‚   └── cs.yml

After running:

i18nize cs

the gem will create:

config/locales/api/cs.yml

With keys translated from api/en.yml.


πŸ“¦ Configuration

For now, configuration is via CLI flags and environment variables:

  • --from LANG (default en)
  • --missing [FROM] (list missing keys only)
  • --only_blank (fill only blank/missing keys with placeholders, no DeepL)
  • DEEPL_API_KEY (required for translation mode)
  • DEEPL_ENDPOINT (optional, only for Pro)
  • I18NIZE_ALLOW_EMPTY == "1" β†’ skip empty/whitespace-only values in the source when inserting or translating (i.e., if a source value is "" or " " it will be ignored and not propagated to the target)

πŸ” TODO

  • RSpec test suite
  • YAML key sorting / format preservation
  • Richer conflict resolution strategies (configurable overwrite / skip)
  • Use custom char limit

About

🧠 Automatically fills in missing I18n YAML keys using DeepL translation API. Designed to streamline multi-language support in Ruby and Rails projects.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors