Module: LocalizedLanguageSelect
- Defined in:
- lib/generators/localized_language_select/locales/locales_generator.rb,
lib/localized_language_select.rb
Overview
require ‘rails/generators/base’ require ‘sugar-high/array’ require ‘active_support/inflector’ require ‘rails3_artifactor’ require ‘logging_assist’
Defined Under Namespace
Modules: Generators
Class Method Summary collapse
- .include_language?(key, options) ⇒ Boolean
-
.localized_languages_array(options = {}) ⇒ Object
Returns array with codes and localized language names (according to
I18n.locale
) for<option>
tags. -
.priority_languages_array(language_codes = []) ⇒ Object
Return array with codes and localized language names for array of language codes passed as argument == Example priority_languages_array([:de, :fr, :en]) # => [ [‘German’, ‘de’], [‘French’, ‘fr’], [‘English’, ‘en’] ].
Class Method Details
.include_language?(key, options) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'lib/localized_language_select.rb', line 36 def include_language?(key, ) if [:only] return [:only].include?(key) end if [:except] return ![:except].include?(key) end true end |
.localized_languages_array(options = {}) ⇒ Object
Returns array with codes and localized language names (according to I18n.locale
) for <option>
tags
28 29 30 31 32 33 34 |
# File 'lib/localized_language_select.rb', line 28 def localized_languages_array = {} res = [] list = I18n.translate(:languages).each do |key, value| res << [value, key.to_s.upcase] if include_language?(key.to_s, ) end res.sort_by { |country| country.first.parameterize } end |
.priority_languages_array(language_codes = []) ⇒ Object
Return array with codes and localized language names for array of language codes passed as argument
Example
priority_languages_array([:de, :fr, :en])
# => [ ['German', 'de'], ['French', 'fr'], ['English', 'en'] ]
51 52 53 54 |
# File 'lib/localized_language_select.rb', line 51 def priority_languages_array(language_codes=[]) languages = I18n.translate(:languages) language_codes.map { |code| [languages[code], code.to_s.downcase] } end |