Module: I18nLanguageSelect::InstanceTag

Defined in:
lib/i18n_language_select/instance_tag.rb

Instance Method Summary collapse

Instance Method Details

#language_code_select(priority_languages, options, html_options) ⇒ Object

Adapted from Rails language_select. Just uses language codes instead of full names.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/i18n_language_select/instance_tag.rb', line 13

def language_code_select(priority_languages, options, html_options)
  selected = object.send(@method_name) if object.respond_to?(@method_name)

  languages = ""

  if options.present? and options[:include_blank]
    option = options[:include_blank] == true ? "" : options[:include_blank]
    languages += "<option>#{option}</option>\n"
  end

  if priority_languages
    languages += options_for_select(priority_languages, selected)
    languages += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
  end

  languages = languages + options_for_select(language_translations, selected)

  html_options = html_options.stringify_keys
  add_default_name_and_id(html_options)

  (:select, languages.html_safe, html_options)
end

#language_translationsObject



36
37
38
39
40
41
42
# File 'lib/i18n_language_select/instance_tag.rb', line 36

def language_translations
  I18n.t(I18nLanguageSelect.configuration.namespace.to_s).map do |pairing|
    [pairing[1], pairing[0]] if pairing[0] && pairing[1]
  end.compact.sort_by do |pairing|
    pairing[0] # sort by language name alphabetical
  end
end

#to_language_code_select_tag(priority_languages, html_options = {}, options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/i18n_language_select/instance_tag.rb', line 4

def to_language_code_select_tag(priority_languages, html_options = {}, options = {})
  # Rails 4 stores options sent when creating an InstanceTag.
  # Let's use them!
  options = @options if defined?(@options)

  language_code_select(priority_languages, options, html_options)
end