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

Components that inherit the i18n scope of their parent #2

@dhnaranjo

Description

@dhnaranjo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions