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



33
34
35
# File 'app/helpers/tolk/application_helper.rb', line 33

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

#format_i18n_text_area_value(value) ⇒ Object



19
20
21
# File 'app/helpers/tolk/application_helper.rb', line 19

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

#format_i18n_value(value) ⇒ Object



5
6
7
8
9
# File 'app/helpers/tolk/application_helper.rb', line 5

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

#highligh_interpolations(value) ⇒ Object



15
16
17
# File 'app/helpers/tolk/application_helper.rb', line 15

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

#highlight_linebreaks(value) ⇒ Object



11
12
13
# File 'app/helpers/tolk/application_helper.rb', line 11

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

#scope_selector_for(locale) ⇒ Object



44
45
46
47
# File 'app/helpers/tolk/application_helper.rb', line 44

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



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

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



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

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