Search code examples
ruby-on-railsrails-i18n

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!


Solution

  • 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