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:

<%= 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

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

#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 en.cv.fe.valueMissing and en.cv.fe.badInput, an i18n_key_root value of "en.cv.fe" will result in both of those keys being rendered.



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