Method: LOLspeak::Tranzlator#translate_xml_element!
- Defined in:
- lib/lolspeak.rb
#translate_xml_element!(xml_element, &filter) ⇒ Object
Translates the REXML::Text parts of a single REXML::Element. The element is modified in place.
If a block is given, it is called to transform each individual word. By default, each word is XML escaped, so this transform applies on top of that.
:call-seq:
translate_xml_element!(xml_element)
translate_xml_element!(xml_element) { |word| transform }
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/lolspeak.rb', line 161 def translate_xml_element!(xml_element, &filter) xml_element.texts.each do |text| string = REXML::Text::unnormalize(text.to_s) string = self.translate_words(string) do |w| w = REXML::Text::normalize(w) w = filter.call(w) if !filter.nil? w end new_text = REXML::Text.new(string, true, nil, true) text.replace_with(new_text) end end |