Class: Brut::FrontEnd::Components::I18nTranslations
- Inherits:
-
Brut::FrontEnd::Component
- Object
- Phlex::HTML
- Brut::FrontEnd::Component
- Brut::FrontEnd::Components::I18nTranslations
- Defined in:
- lib/brut/front_end/components/i18n_translations.rb
Overview
Produces <brut-i18n-translation>
entries for the given values. This is used for client-side constraint violation messaging with
JavaScript. The <brut-constraint-violation-message>
tag uses these keys to produce messages on the client.
The default layout included in new Brut apps includes this:
<%= component(
Brut::FrontEnd::Components::I18nTranslations.new(
"general.cv.fe"
)
) %>
At runtime, this will produce this:
<brut-i18n-translation
key="general.cv.fe.badInput"
value="%{field} is the wrong type of data">
</brut-i18n-translation>
<brut-i18n-translation
key="general.cv.fe.patternMismatch"
value="%{field} isn't in the right format">
</brut-i18n-translation>
<!-- etc -->
Thus, it will render the translations for all client side errors supported by the browser. This means that if a
client side ValidityState
returns true for, say, badInput
, JavaScript can look up by the key
general.cv.fe.badInput
and find the value
to produce the string "This field is the wrong type of data".
Instance Method Summary collapse
-
#initialize(i18n_key_root) ⇒ I18nTranslations
constructor
Create the component for all keys under the given root.
Methods inherited from Brut::FrontEnd::Component
component_name, #component_name
Methods included from Brut::FrontEnd::Component::Helpers
#global_component, #inline_svg
Methods included from I18n::ForHTML
Methods included from I18n::BaseMethods
#l, #t, #t_direct, #this_field_value
Methods included from Brut::Framework::Errors
Constructor Details
#initialize(i18n_key_root) ⇒ I18nTranslations
Create the component for all keys under the given root
35 36 37 |
# File 'lib/brut/front_end/components/i18n_translations.rb', line 35 def initialize(i18n_key_root) @i18n_key_root = i18n_key_root end |