lib/world_flags/helper/locale.rb in world-flags-0.4.0 vs lib/world_flags/helper/locale.rb in world-flags-0.4.1
- old
+ new
@@ -11,22 +11,34 @@
else
WorldFlags.valid_locales
end
end
+ # ensure all country/language/domain types are mapped to their equivalent locale code
def locales
- [params[:locale], extract_locale_from_tld, browser_locale, ip_country_code, I18n.default_locale].downcase
+ locale_sources.downcase.map {|loc| WorldFlags.locale(loc) }
end
+
+ def locale_sources
+ [params[:locale], extract_locale_from_tld, browser_locale, ip_country_code, I18n.default_locale]
+ end
# Get locale from top-level domain or return nil if such locale is not available
# You have to put something like:
# 127.0.0.1 application.com
# 127.0.0.1 application.it
# 127.0.0.1 application.pl
# in your /etc/hosts file to try this out locally
def extract_locale_from_tld
- parsed_locale = request.host.split('.').last
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
end
+
+ def parsed_locale
+ WorldFlags.locale(parsed_domain)
+ end
+
+ def parsed_domain
+ request.host.split('.').last
+ end
end
end
end
\ No newline at end of file