Class: Brut::FrontEnd::Components::I18nTranslations

Inherits:
Brut::FrontEnd::Component show all
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:

“‘ruby I18nTranslations.new(“cv.cs”) “`

At runtime, this will produce this:

“‘html <brut-i18n-translation

key="cv.cs.badInput"
value="%{field} is the wrong type of data">

</brut-i18n-translation> <brut-i18n-translation

key="cv.cs.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` `cv.cs.badInput` and find the `value` to produce the string “This field is the wrong type of data”.

Instance Method Summary collapse

Methods inherited from Brut::FrontEnd::Component

#around_template, component_name, #component_name

Methods included from Brut::FrontEnd::Component::Helpers

#entity, #global_component, #inline_svg

Methods included from I18n::ForHTML

#html_escape, #t

Methods included from I18n::BaseMethods

#l, #t, #t_direct, #this_field_value

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Constructor Details

#initialize(i18n_key_root) ⇒ I18nTranslations

Create the component for all keys under the given root

Parameters:

  • i18n_key_root (String)

    A prefix or full key for the i18n messages to render. For example, if you have ‘cv.cs.valueMissing` and `cv.cs.badInput`, an `i18n_key_root` value of `“cv.cs”` will result in both of those keys being rendered.



31
32
33
# File 'lib/brut/front_end/components/i18n_translations.rb', line 31

def initialize(i18n_key_root)
  @i18n_key_root = i18n_key_root
end