Lingo.dev + .yaml (Rails)
Lingo.dev CLIはRuby on RailsのYAML i18nファイルをRailsの標準国際化ワークフローに合わせたロケールベースのルートキーを使用して翻訳します。CLIはすべてのRails翻訳を一元化されたロケールファイルで管理し、モデル/ビュー/コントローラー用のRailsのネストされたキー規則を維持し、YAMLアンカーとエイリアスがロケール間で機能することを保証し、Railsのt()
ヘルパーとシームレスに統合し、Railsのi18nベストプラクティスに正確に従います。
クイックセットアップ
Railsロケールファイル用の設定:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"yaml-root-key": {
"include": ["config/locales/*.yml"]
}
}
}
Rails i18nファイルの翻訳
npx lingo.dev@latest i18n
YAML構造とRails i18n規則を保持しながら、ルートキーの下にあるRailsロケール固有のコンテンツを管理します。
Rails i18n構造
標準的なRails構成
# config/locales/en.yml
en:
hello: "Hello world"
# モデル翻訳
activerecord:
models:
user: "User"
post: "Post"
attributes:
user:
name: "Name"
email: "Email Address"
# ビュー翻訳
layouts:
application:
title: "My Rails App"
# コントローラー/アクション固有
users:
index:
title: "All Users"
new_user: "New User"
show:
edit: "Edit User"
delete: "Delete User"
es:
hello: "Hola mundo"
activerecord:
models:
user: "Usuario"
post: "Publicación"
attributes:
user:
name: "Nombre"
email: "Dirección de Correo"
layouts:
application:
title: "Mi Aplicación Rails"
users:
index:
title: "Todos los Usuarios"
new_user: "Nuevo Usuario"
show:
edit: "Editar Usuario"
delete: "Eliminar Usuario"
Railsバリデーションメッセージ
en:
activerecord:
errors:
messages:
blank: "can't be blank"
too_short: "is too short (minimum is %{count} characters)"
too_long: "is too long (maximum is %{count} characters)"
taken: "has already been taken"
es:
activerecord:
errors:
messages:
blank: "no puede estar en blanco"
too_short: "es demasiado corto (mínimo %{count} caracteres)"
too_long: "es demasiado largo (máximo %{count} caracteres)"
taken: "ya está en uso"
Rails 統合機能
ヘルパーメソッドの互換性
Rails i18n ヘルパーとシームレスに連携します:
t('users.index.title')
I18n.t('hello')
<%= t('.edit') %>
(遅延ルックアップ)User.model_name.human
補間サポート
en:
welcome_message: "Welcome, %{name}!"
items_count:
zero: "No items"
one: "One item"
other: "%{count} items"
es:
welcome_message: "¡Bienvenido, %{name}!"
items_count:
zero: "Sin artículos"
one: "Un artículo"
other: "%{count} artículos"
高度な設定
複数のRailsロケールファイル
"yaml-root-key": {
"include": [
"config/locales/*.yml",
"config/locales/**/*.yml"
]
}
Railsシステムキーのロック
"yaml-root-key": {
"include": ["config/locales/*.yml"],
"lockedKeys": ["number", "time", "date", "datetime"]
}