administrate icon indicating copy to clipboard operation
administrate copied to clipboard

I18n translations for nested resources on custom designs not working

Open 5minpause opened this issue 2 years ago • 3 comments

Thank you for this wonderful gem.

  • What were you trying to do? I customized the designs to use TailwindCSS. Everything is working, but the translation for nested records does not work. The same models have their translations on their own index and show pages.

  • What did you end up with (logs, or, even better, example apps are great!)?

We are looking at a custom show page. Bildschirmfoto 2022-05-02 um 13 54 31 The nested Address record has no localized labels. The same view for the same record on its own SHOW page: Bildschirmfoto 2022-05-02 um 13 57 55

And the Addresses INDEX page: Bildschirmfoto 2022-05-02 um 13 58 04

The code to render the attributes on the SHOW page:

I believe it is almost the same as the original one.

<% page.attributes.each do |attribute| %>
  <div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
    <dt class="text-sm font-medium text-gray-500" id="<%= attribute.name %>">
      <%= t(
        "helpers.label.#{resource_name}.#{attribute.name}",
        default: page.resource.class.human_attribute_name(attribute.name),
      ) %>
    </dt>
    <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
      <%= render_field attribute, page: page %>
    </dd>
  </div>
<% end %>

Do I need to edit some other files to achieve this?

  • What versions are you running?
    • Rails 7.0.2.4
    • administrate 0.17.0

5minpause avatar May 02 '22 12:05 5minpause

Thank you for raising this issue. I had a look and I can see it's indeed a bug. Would you be able to try out this branch and see if it works for you? https://github.com/thoughtbot/administrate/compare/main...pablobm:has-one-translations

pablobm avatar May 13 '22 06:05 pablobm

Thank you for raising this issue. I had a look and I can see it's indeed a bug. Would you be able to try out this branch and see if it works for you? main...pablobm:has-one-translations

I can report back that your branch works for me. I can now define the translations for the models where they belong. 🎉

5minpause avatar May 23 '22 12:05 5minpause

Perfect, thank you! I'll create a PR.

pablobm avatar May 26 '22 13:05 pablobm