Module: I18nLanguageSelect::InstanceTag
- Defined in:
- lib/i18n_language_select/instance_tag.rb
Instance Method Summary collapse
-
#language_code_select(priority_languages, options, html_options) ⇒ Object
Adapted from Rails language_select.
- #language_translations ⇒ Object
- #to_language_code_select_tag(priority_languages, html_options = {}, options = {}) ⇒ Object
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, , ) selected = object.send(@method_name) if object.respond_to?(@method_name) languages = "" if .present? and [:include_blank] option = [:include_blank] == true ? "" : [:include_blank] languages += "<option>#{option}</option>\n" end if priority_languages languages += (priority_languages, selected) languages += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" end languages = languages + (language_translations, selected) = .stringify_keys add_default_name_and_id() content_tag(:select, languages.html_safe, ) end |
#language_translations ⇒ Object
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, = {}, = {}) # Rails 4 stores options sent when creating an InstanceTag. # Let's use them! = @options if defined?(@options) language_code_select(priority_languages, , ) end |