Module: Tolk::ApplicationHelper
- Defined in:
- app/helpers/tolk/application_helper.rb
Instance Method Summary collapse
- #boolean_warning ⇒ Object
- #format_i18n_text_area_value(value) ⇒ Object
- #format_i18n_value(value) ⇒ Object
- #highligh_interpolations(value) ⇒ Object
- #highlight_linebreaks(value) ⇒ Object
- #scope_selector_for(locale) ⇒ Object
- #tolk_locale_selection ⇒ Object
- #yaml_value(value) ⇒ Object
Instance Method Details
#boolean_warning ⇒ Object
31 32 33 |
# File 'app/helpers/tolk/application_helper.rb', line 31 def boolean_warning '<span class="boolean">(Do not translate -- Enter true or false)</span>'.html_safe end |
#format_i18n_text_area_value(value) ⇒ Object
17 18 19 |
# File 'app/helpers/tolk/application_helper.rb', line 17 def format_i18n_text_area_value(value) yaml_value(value).to_s.force_encoding("UTF-8") end |
#format_i18n_value(value) ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/tolk/application_helper.rb', line 3 def format_i18n_value(value) value = h(yaml_value(value)) value = highlight_linebreaks(value) value = highligh_interpolations(value) end |
#highligh_interpolations(value) ⇒ Object
13 14 15 |
# File 'app/helpers/tolk/application_helper.rb', line 13 def highligh_interpolations(value) value.gsub(/%{\w+}/, '<span class="interpolation" title="Leave this word untranslated">\0</span>').html_safe end |
#highlight_linebreaks(value) ⇒ Object
9 10 11 |
# File 'app/helpers/tolk/application_helper.rb', line 9 def highlight_linebreaks(value) value.gsub(/\n/, '<span class="carriage_return" title="Line break"><br /></span>').html_safe end |
#scope_selector_for(locale) ⇒ Object
42 43 44 45 |
# File 'app/helpers/tolk/application_helper.rb', line 42 def scope_selector_for(locale) select_tag 'scope', ([[Tolk::Locale.primary_locale.language_name, "origin"], [locale.language_name, "target"]], params[:scope]) end |
#tolk_locale_selection ⇒ Object
35 36 37 38 39 40 |
# File 'app/helpers/tolk/application_helper.rb', line 35 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
21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/tolk/application_helper.rb', line 21 def yaml_value(value) if value.present? unless value.is_a?(String) || value.is_a?(TrueClass) || value.is_a?(FalseClass) value = value.respond_to?(:ya2yaml) ? value.ya2yaml(:syck_compatible => true) : value.to_yaml end end value end |