Module: WorldFlags::Helper::Locale
- Defined in:
- lib/world_flags/helper/locale.rb
Instance Method Summary collapse
-
#extract_locale_from_tld ⇒ Object
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.
- #locales ⇒ Object
- #set_locale ⇒ Object
- #valid_locales ⇒ Object
Instance Method Details
#extract_locale_from_tld ⇒ Object
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
26 27 28 29 |
# File 'lib/world_flags/helper/locale.rb', line 26 def extract_locale_from_tld parsed_locale = request.host.split('.').last I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil end |
#locales ⇒ Object
16 17 18 |
# File 'lib/world_flags/helper/locale.rb', line 16 def locales [params[:locale], extract_locale_from_tld, browser_locale, ip_country_code, I18n.default_locale].downcase end |
#set_locale ⇒ Object
4 5 6 |
# File 'lib/world_flags/helper/locale.rb', line 4 def set_locale I18n.locale = locales.select_first_in(valid_locales.downcase) end |
#valid_locales ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/world_flags/helper/locale.rb', line 8 def valid_locales if I18n.respond_to?(:available_locales) && I18n.available_locales.present? I18n.available_locales else WorldFlags.valid_locales end end |