class Array
Public Instance Methods
translate(description = '', options = {})
click to toggle source
translate array values
# File lib/tr8n_core/ext/array.rb, line 57 def translate(description = '', options = {}) return [] if empty? collect do |opt| if opt.is_a?(String) opt.translate(description, {}, options) else opt end end end
translate_sentence(description = '', options = {})
click to toggle source
creates a sentence with tr “and” joiner
# File lib/tr8n_core/ext/array.rb, line 70 def translate_sentence(description = '', options = {}) return "" if empty? return first if size == 1 elements = translate(description, options) options[:separator] ||= ', ' options[:joiner] ||= 'and' result = elements[0..-2].join(options[:separator]) result << ' ' << options[:joiner].translate('List elements joiner', {}, options) << ' ' result << elements.last result.tr8n_translated end
translated_and_join(separator = '', description = '', options = {})
click to toggle source
translates and joins all elements
# File lib/tr8n_core/ext/array.rb, line 52 def translated_and_join(separator = '', description = '', options = {}) self.translate(description, options).join(separator).tr8n_translated end
tro(description = '', options = {})
click to toggle source
translates an array of options for a select tag
# File lib/tr8n_core/ext/array.rb, line 35 def tro(description = '', options = {}) return [] if empty? options = options.merge(:skip_decorations => true) collect do |opt| if opt.is_a?(Array) and opt.first.is_a?(String) [opt.first.translate(description, {}, options), opt.last] elsif opt.is_a?(String) [opt.translate(description, {}, options), opt] else opt end end end