Sha256: 4cc16bd2c842336787413286de536389b6e5cdaced03e20e1ca5b9effc175637
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
require 'hashie' require 'world_flags/core_ext' require 'world_flags/helpers' require 'world_flags/rails/engine' if defined?(::Rails::Engine) require 'world_flags/languages' require 'world_flags/countries' require 'world_flags/util' module WorldFlags class << self include Util attr_writer :active_locales attr_writer :locale_flag_map def label code = :us, options = {:language => :en} locale = extract_locale!(options) || default_locale_used || :en options[:country] ? country_label(code, locale) : language_label(code, locale) end def flag_code code = :us # ensure that 'en_US' becomes simply 'us' code = code.to_s.sub(/^\w+_/, '').downcase (locale_flag_map[code.to_sym] || code).to_sym end def locale code = :us flag_locale_map[code.to_sym] || code end # override using fx 'locale_to_country_code.json' file def locale_flag_map @locale_flag_map ||= keys_to_sym(locale_flag_hash) end # see core_ext def flag_locale_map locale_flag_map.hash_revert end protected def keys_to_sym hash hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} end def locale_flag_hash { :en => "us", :da => "dk", :sv => "se", :sq => "al", :nb => "no", :ja => "jp", :uk => "ua" } end def extract_locale! options options[:country] ? options.delete(:country) : options.delete(:language) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
world-flags-0.3.6 | lib/world-flags.rb |
world-flags-0.3.5 | lib/world-flags.rb |