Skip to content

lingodotdev/ruby-on-rails-localization-example

Repository files navigation

Ruby on Rails Localization Example

Demonstrates automated localization for a Ruby on Rails app that authors UI strings in config/locales YAML files, using Lingo.dev CLI and GitHub Actions.

Full walkthrough: lingo.dev/en/guides/ruby-on-rails-localization

What's inside

  • config/locales/en.yml – source UI strings (English)
  • config/locales/{es,fr,de}.yml – translated catalogs, generated by Lingo.dev
  • app/controllers/application_controller.rbswitch_locale around_action that picks from URL param or Accept-Language
  • app/views/home/index.html.erb – view demonstrating t() interpolation and pluralization
  • i18n.json – Lingo.dev CLI configuration (yaml-root-key bucket)
  • .github/workflows/translate.yml – GitHub Actions workflow

Quick start

  1. Fork this repo
  2. Add LINGODOTDEV_API_KEY to Settings > Secrets and variables > Actions
  3. Push a change to config/locales/en.yml
  4. Translations appear automatically via commit to main

How it works

The Lingo.dev CLI reads config/locales/en.yml, identifies new or changed entries using a lockfile, translates the delta through a configured localization engine, and writes per-locale files (es.yml, fr.yml, de.yml) alongside the source. The locale root key (en:es:), nested namespaces, %{name} interpolation, and plural categories (zero, one, other) are preserved – only translatable text changes. The GitHub Actions workflow runs this on every push to main.

Rails' built-in i18n API loads every YAML file under config/locales/ at boot. ApplicationController#switch_locale picks the request locale from a URL parameter or the Accept-Language header and wraps the action in I18n.with_locale, so views render translations with t() and l() helpers without leaking the locale across requests.

Locales

  • Source: en
  • Targets: es, fr, de

Running locally

bundle install
bin/rails server

Open http://localhost:3000 – visit /en, /es, /fr, or /de to switch locale.

To translate locally:

npm install -g lingo.dev
lingo.dev run

Links

About

Demonstrates automated localization for a Rails app using Lingo.dev CLI and GitHub Actions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors