explaingit

fnando/i18n-js

3,798RubyAudience · developerComplexity · 3/5Setup · moderate

TLDR

A Ruby library that exports Rails translation strings from YAML files into JSON so your browser-side JavaScript can use the same translations, with CLI tools for export, linting, and coverage checking.

Mindmap

mindmap
  root((i18n-js))
    What it does
      Exports Rails translations
      YAML to JSON conversion
      Shared translations
    Tech Stack
      Ruby
      Rails
      JavaScript
      npm companion package
    Features
      CLI interface
      Wildcard filters
      Plugin system
      Cache-busting hashes
    Use Cases
      Rails plus JS frontend
      Translation coverage
      Fallback translations
    Audience
      Rails developers
      Full-stack devs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Export Rails i18n YAML translations to JSON files so your React or Vue frontend can display translated strings without an extra API call.

USE CASE 2

Use wildcard patterns in the config to export only the translations your frontend needs, skipping server-only error messages.

USE CASE 3

Run the CLI linter to find missing translations across locales before they cause blank text in production.

USE CASE 4

Enable the fallback plugin so that missing translations in a non-default language gracefully fall back to the default language string.

Tech stack

RubyRailsJavaScriptYAMLJSONERB

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a Ruby/Rails project, also needs the separate npm companion package installed for the browser-side JavaScript usage.

License information is not mentioned in the explanation.

In plain English

This is a Ruby library that exports translation strings from Rails (a popular Ruby web framework) into JSON files that can be loaded and used in JavaScript running in the browser. The core problem it solves is that Rails stores its translations in YAML files on the server, but the front-end JavaScript code cannot read those directly, so this tool converts them into a format that both sides can share. You configure which translations to export using a YAML config file. Patterns let you include or exclude specific groups of translations using wildcards, so you can, for example, export everything except database-level error messages that the browser will never need. The output filenames can include placeholders for the language code and a checksum hash, which is useful for cache-busting when files change. The tool ships with a command-line interface that handles initialization, export, linting for missing translations, and checking translation coverage. You can also call it programmatically from Ruby code. A plugin system allows you to extend the export process. Two built-in plugins cover common needs: one embeds fallback translations from the default language so that missing phrases gracefully fall back, and another allows exporting to file formats other than JSON, such as TypeScript, by running translations through an ERB template. The companion JavaScript package for loading and using these exported translations in the browser is published separately on npm. The README notes the library works for projects that do not use Ruby at all, as long as they can generate the JSON files another way.

Copy-paste prompts

Prompt 1
I have a Rails app with i18n YAML files and I want to share those translations with my JavaScript frontend using i18n-js. Walk me through the setup from gem install to first JSON export.
Prompt 2
How do I configure i18n-js to export only the translations under the 'en.ui' namespace and skip everything under 'en.activerecord'?
Prompt 3
I want to add cache-busting to my i18n-js exported JSON files so browsers reload them when translations change. How do I configure the checksum hash in the output filename?
Prompt 4
How do I use the i18n-js CLI to check which translation keys are missing across my supported locales and get a coverage report?
Open on GitHub → Explain another repo

← fnando on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.