Administrate: Text in links not fully translated

Created on 25 Jan 2018  路  9Comments  路  Source: thoughtbot/administrate

In /app/views/administrate/application/index.html.erb every links is not translated fully.

For example, when generating a link to create a new resource from a model named SubCategory:

  <div>
    <%= link_to(
      t(
        "administrate.actions.new_resource",
        name: page.resource_name.titleize.downcase
      ),
      [:new, namespace, page.resource_path],
      class: "button",
    ) if valid_action?(:new) && show_action?(:new, new_resource) %>
  </div>

in french, this will output something like this:
<a class="button" href="/admin/sub_categories/new">Cr茅ation sub category</a>

The word create will be translated correctly, but not the resource name sub category.
The very useful display_resource_name helper, which calls human which itself calls translate could help achieve that.

      t(
        "administrate.actions.new_resource",
        name: display_resource_name(resource_name).downcase
      )

output in french:
<a class="button" href="/admin/sub_categories/new">Cr茅ation sous cat茅gorie</a>
Hooray!

That way, if our resource name is translated in your_locale.activerecord.models.your_model, it will be translated correctly and we can still handle format in your_locale.administrate.actions.new_resource.

I haven't had time to check the other views yet, but would you be interested in a pull request? I'm running a similar fix using 0.8.1 in production, it probably won't introduce breaking change on master.

Have a nice day and thanks for this gem, it works great!

bug i18n

Most helpful comment

Difficult to say at this point, but most likely.

Was fixed by providing the missing definitions in my own en.yml:

en:
  administrate:
    actions:
      new: "New"
      show: "Show"

All 9 comments

Hi @Na0na0!

Thank you for your detailed issue. This sort of explanation really helps me understand where we're lacking when it comes to i18n.

A PR for this would be great, if you're still able to!

Hello @nickcharlton!

Sorry I was away for a few days, I saw you released 0.9.0 so I'll have to give it a look first but if not much changed I think I'll have time to make the PR next week.

I was kind of afraid to over-detail the issue but glad the way I detailed things was actually useful haha! :)

@nickcharlton Unsure if what I'm experiencing is related to this PR - or if belongs under a separate issue - but on version 0.9.0 I'm getting translation missing classes on my New and Show buttons:

screen shot 2018-03-09 at 12 33 39 pm

Ah, interesting!

It's possible that they might have the same underlying cause, although they do look slightly different.

Were you previously running 0.8.1?

Difficult to say at this point, but most likely.

Was fixed by providing the missing definitions in my own en.yml:

en:
  administrate:
    actions:
      new: "New"
      show: "Show"

Ah, interesting. Are those missing from the ones provided by administrate itself? Are you doing any other localisation overrides?

The only other localization file I have in the project is the one provided by Clearance.

_clearance.en.yml_

---
en:
  clearance:
    models:
      clearance_mailer:
        change_password: Change your password
  clearance_mailer:
    change_password:
      closing: If you didn't request this, ignore this email. Your password has
        not been changed.
      link_text: Change my password
      opening: "Someone, hopefully you, requested we send you a link to change
        your password:"
  flashes:
    failure_after_create: Bad email or password.
    failure_after_update: Password can't be blank.
    failure_when_forbidden: Please double check the URL or try submitting
      the form again.
    failure_when_not_signed_in: Please sign in to continue.
  helpers:
    label:
      password:
        email: Email address
      password_reset:
        password: Choose password
    submit:
      password:
        submit: Reset password
      password_reset:
        submit: Save this password
      session:
        submit: Sign in
      user:
        create: Sign up
  layouts:
    application:
      sign_in: Sign in
      sign_out: Sign Out
  passwords:
    create:
      description: You will receive an email within the next few minutes. It
        contains instructions for changing your password.
    edit:
      description: Your password has been reset. Choose a new password below.
      title: Change your password
    new:
      description: To be emailed a link to reset your password, please enter
        your email address.
      title: Reset your password
  sessions:
    form:
      forgot_password: Forgot password?
      sign_up: Sign up
    new:
      title: Sign in
  users:
    new:
      sign_in: Sign in
      title: Sign up

Oh, I think I can see what might have happened now.

We replaced new/edit with new_resource/edit_resource respectively to improve the translations. I suspect that if you update your views this will sort it out.

If there's any plugins affected by this, it might be worth opening PRs against them, too.

Closing as solved in #1777.

Was this page helpful?
0 / 5 - 0 ratings