Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Components that inherit the i18n scope of their parent #2

Open
dhnaranjo opened this issue Dec 2, 2022 · 0 comments
Open

Components that inherit the i18n scope of their parent #2

dhnaranjo opened this issue Dec 2, 2022 · 0 comments

Comments

@dhnaranjo
Copy link
Contributor

My own Form class, based on an earlier version of the one in phlex-rails now, has a label method that accepts label content but falls back to, tho really prefers, to use the i18n value for the field name within the scope of the view it's defined in.

# app/views/things/show.rb
class Views::Things::Show < Phlex::HTML
  def template
    render Form.new do |f|
      f.label :a_field # I display the i18n content at views.things.show.a_field
      f.input :a_field
      
      f.label :another_field, "Field content" # I display the text provided
      f.input :another_field
    end
  end
end

I do this by defining def t(...) = @_parent.translate(...) in my Form. I think this could be a useful feature to standardize in this library somehow. Maybe a class that inherits Phlex::Translation could call inherit_i18n_scope or something like that. Iunno.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant