Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify Rails I18n locale an attribute translation common for all models?

I have in my es.ymllocale the following code:

es:
  activerecord:
    models:
      courier:
        one: Repartidor
        other: Repartidores
      admin_user:
        one: Administrador
        other: Administradores
    attributes:
      courier:
        ci: Cédula
        first_name: Nombre
        last_name: Apellido
        password: Contraseña
        password_confirmation: Confirmación de contraseña
        sign_in_count: Veces que inició sesión
        created_at: Fecha de creación
        updated_at: Última actualización
      admin_user:
        email: Email
        last_sign_in_ip: Útima IP utilizada
        last_sign_in_at: Útimo inicio de sesión
        current_sign_in_ip: Actual IP
        current_sign_in_at: Actual inicio de sesión
        sign_in_count: Veces que inició sesión
        created_at: Fecha de creación
        updated_at: Última actualización
        password: Contraseña
        password_confirmation: Confirmación de contraseña

However, you might have seen that a lot of attributes are common for more than one model like the timestamps and password. How can I tell the locale to translate that for every model so I don't have to repeat the translations of the attributes for each model?

Thank you!

like image 936
Leticia Esperon Avatar asked Oct 20 '25 04:10

Leticia Esperon


1 Answers

You just move attributes one level to the left, something like this

es:
  attributes:
    password: Contraseña
    name: Nombre
  activerecord:
    attributes:
      user:
        license_number: Numero de licencia
like image 109
xploshioOn Avatar answered Oct 21 '25 19:10

xploshioOn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!