Module: Interage::TranslationHelper

Included in:
ApplicationHelper
Defined in:
lib/interage/translation_helper.rb

Instance Method Summary collapse

Instance Method Details

#translate_boolean(value) ⇒ Object Also known as: tb

Public: Translate a boolean attribute.

value: TrueClass or FalseClass.

Examples

<%= tb true %>
# => 'Sim'

<%= tb false %>
# => 'Nao'

Returns translated boolean’s attribute.



76
77
78
# File 'lib/interage/translation_helper.rb', line 76

def translate_boolean(value)
  value ? t('boolean.truly') : t('boolean.falsely')
end

#translate_boolean_in_check_box_icon(value) ⇒ Object Also known as: tbci

Public: Translate a boolean attribute in an icon.

value: TrueClass or FalseClass.

Examples

<%= tbci true %>
# => '<i class="fa fa-check-square-o text-default"></i>'

<%= tbci false %>
# => '<i class="fa fa-square-o text-default"></i>'

Returns translated boolean’s attribute in an icon.



118
119
120
121
122
123
124
# File 'lib/interage/translation_helper.rb', line 118

def translate_boolean_in_check_box_icon(value)
  if value
    app_icon('check', class: 'text-success')
  else
    app_icon('times', class: 'text-danger')
  end
end

#translate_boolean_in_icon(value) ⇒ Object Also known as: tbi

Public: Translate a boolean attribute in an icon.

value: TrueClass or FalseClass.

Examples

<%= tbi true %>
# => '<i class="fa fa-check text-success"></i>'

<%= tbi false %>
# => '<i class="fa fa-times text-danger"></i>'

Returns translated boolean’s attribute in an icon.



95
96
97
98
99
100
101
# File 'lib/interage/translation_helper.rb', line 95

def translate_boolean_in_icon(value)
  if value
    (:span, '', class: 'text-success')
  else
    (:span, '×', class: 'text-danger')
  end
end

#translate_model_attribute(model, attribute, count = 1) ⇒ Object Also known as: ta

Public: Translate a model attribute.

model: Model class. attribute: Attribute name. count: Count.

Examples

<%= ta Post, :title %>
# => 'Titulo'

<%= ta Post, :title, 2 %>
# => 'Titulos'

Returns translated model’s attribute.



57
58
59
# File 'lib/interage/translation_helper.rb', line 57

def translate_model_attribute(model, attribute, count = 1)
  model.human_attribute_name(attribute, count: count)
end

#translate_model_name(model, count = 1) ⇒ Object Also known as: tm

Public: Translate a model name.

model: Model class. count: Count.

Examples:

<%= tm Post %>
# => 'Artigo'

<%= tm Post, 2 %>
# => 'Artigos'

Returns translated model.



20
21
22
# File 'lib/interage/translation_helper.rb', line 20

def translate_model_name(model, count = 1)
  count.to_i > 1 ? model.model_name.human : model.model_name.human.pluralize
end

#translate_model_name_pluralized(model) ⇒ Object Also known as: tmp

Public: Translate a model name pluralized.

model: Model class.

Examples:

<%= tm Post %>
# => 'Artigos'

Returns translated model pluralized.



36
37
38
# File 'lib/interage/translation_helper.rb', line 36

def translate_model_name_pluralized(model)
  translate_model_name(model, 2)
end