Sha256: 3e7a500be4afa547e7574de21f0a9ffaa763ccea3e12f252e4f5e12f1244e565
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require "rexml" # Produces `<brut-i18n-translation>` entries for the given values class Brut::FrontEnd::Components::I18nTranslations < Brut::FrontEnd::Component def initialize(i18n_key_root) @i18n_key_root = i18n_key_root end def render values = ::I18n.t(@i18n_key_root) if values.kind_of?(String) values = { "" => values } end values.map { |key,value| if !value.kind_of?(String) raise "Key #{key} under #{@i18n_key_root} maps to a #{value.class} instead of a String. For #{self.class} to work, the value must be a String" end i18n_key = if key == "" @i18n_key_root else "#{@i18n_key_root}.#{key}" end attributes = [ REXML::Attribute.new("key",i18n_key), REXML::Attribute.new("value",value.to_s), ] if !Brut.container.project_env.production? attributes << REXML::Attribute.new("show-warnings",true) attributes << REXML::Attribute.new("id","brut-18n-#{key}") end attribute_string = attributes.map(&:to_string).join(" ") %{<brut-i18n-translation #{attribute_string}></brut-i18n-translation>} }.join("\n") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
brut-0.0.1 | lib/brut/front_end/components/i18n_translations.rb |