Lingo.dev + .yaml (Rails)
Lingo.dev CLI übersetzt Ruby on Rails YAML i18n-Dateien unter Verwendung von locale-basierten Root-Keys für Rails' standardisierten Internationalisierungs-Workflow. Die CLI verwaltet alle Rails-Übersetzungen in zentralisierten Locale-Dateien, behält Rails' verschachtelte Key-Konventionen für Models/Views/Controllers bei, stellt sicher, dass YAML-Anker und -Aliase über Locales hinweg funktionieren, integriert sich nahtlos mit Rails' t()
-Helpern und folgt exakt den Rails i18n Best Practices.
Schnelle Einrichtung
Konfiguration für Rails Locale-Dateien:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"yaml-root-key": {
"include": ["config/locales/*.yml"]
}
}
}
Rails i18n-Dateien übersetzen
npx lingo.dev@latest i18n
Verwaltet Rails' locale-spezifische Inhalte unter Root-Keys unter Beibehaltung der YAML-Struktur und Rails i18n-Konventionen.
Rails i18n-Struktur
Standard Rails-Organisation
# config/locales/en.yml
en:
hello: "Hello world"
# Model translations
activerecord:
models:
user: "User"
post: "Post"
attributes:
user:
name: "Name"
email: "Email Address"
# View translations
layouts:
application:
title: "My Rails App"
# Controller/action specific
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 Validierungsmeldungen
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-Integrationsfeatures
Kompatibilität mit Hilfsmethoden
Funktioniert nahtlos mit Rails i18n-Hilfsmethoden:
t('users.index.title')
I18n.t('hello')
<%= t('.edit') %>
(Lazy-Lookup)User.model_name.human
Interpolationsunterstützung
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"
Erweiterte Konfiguration
Mehrere Rails-Lokalisierungsdateien
"yaml-root-key": {
"include": [
"config/locales/*.yml",
"config/locales/**/*.yml"
]
}
Rails-Systemschlüssel sperren
"yaml-root-key": {
"include": ["config/locales/*.yml"],
"lockedKeys": ["number", "time", "date", "datetime"]
}