Module: Tolk::ApplicationHelper

Includes:
Pagination::ViewHelper
Defined in:
app/helpers/tolk/application_helper.rb

Instance Method Summary collapse

Methods included from Pagination::ViewHelper

#tolk_paginate

Instance Method Details

#boolean_warningObject



35
36
37
# File 'app/helpers/tolk/application_helper.rb', line 35

def boolean_warning
  '<span class="boolean">(Do not translate -- Enter true or false)</span>'.html_safe
end

#format_i18n_text_area_value(value) ⇒ Object



21
22
23
# File 'app/helpers/tolk/application_helper.rb', line 21

def format_i18n_text_area_value(value)
  yaml_value(value).to_s.force_encoding("UTF-8")
end

#format_i18n_value(value) ⇒ Object



7
8
9
10
11
# File 'app/helpers/tolk/application_helper.rb', line 7

def format_i18n_value(value)
  value = h(yaml_value(value))
  value = highlight_linebreaks(value)
  value = highligh_interpolations(value)
end

#highligh_interpolations(value) ⇒ Object



17
18
19
# File 'app/helpers/tolk/application_helper.rb', line 17

def highligh_interpolations(value)
  value.gsub(/%{\w+}/, '<span class="interpolation" title="Leave this word untranslated">\0</span>').html_safe
end

#highlight_linebreaks(value) ⇒ Object



13
14
15
# File 'app/helpers/tolk/application_helper.rb', line 13

def highlight_linebreaks(value)
  value.gsub(/\n/, '<span class="carriage_return" title="Line break"><br /></span>').html_safe
end

#scope_selector_for(locale) ⇒ Object



46
47
48
49
# File 'app/helpers/tolk/application_helper.rb', line 46

def scope_selector_for(locale)
  select_tag 'scope', options_for_select([[Tolk::Locale.primary_locale.language_name, "origin"],
                                          [locale.language_name, "target"]], params[:scope])
end

#tolk_locale_selectionObject



39
40
41
42
43
44
# File 'app/helpers/tolk/application_helper.rb', line 39

def tolk_locale_selection
  existing_locale_names = Tolk::Locale.all.map(&:name)

  pairs = Tolk.config.mapping.to_a.map(&:reverse).sort_by(&:first)
  pairs.reject {|pair| existing_locale_names.include?(pair.last) }
end

#yaml_value(value) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/helpers/tolk/application_helper.rb', line 25

def yaml_value(value)
  if value.present?
    unless value.is_a?(String) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
      value = Tolk::YAML.dump(value)
    end
  end

  value
end