Module: LocalizationHelper
- Defined in:
- app/helpers/localization_helper.rb
Overview
View helper: localization.
Instance Method Summary collapse
- #can_change_country? ⇒ Boolean
- #canada? ⇒ Boolean
- #company_locale ⇒ Object
- #flag_image(country_iso3) ⇒ Object
- #locale_country_name ⇒ Object
- #locale_language ⇒ Object
- #localize_content(raw_html) ⇒ Object
- #multi_locale_input(f, attr_name, wrapper_options = nil) ⇒ Object
- #usa? ⇒ Boolean
Instance Method Details
#can_change_country? ⇒ Boolean
12 13 14 15 16 17 |
# File 'app/helpers/localization_helper.rb', line 12 def can_change_country? return false if bot_request? return true unless @context_user @context_user.can_change_country? end |
#canada? ⇒ Boolean
8 9 10 |
# File 'app/helpers/localization_helper.rb', line 8 def canada? %i[en-CA fr-CA].include?(I18n.locale) end |
#company_locale ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/helpers/localization_helper.rb', line 19 def company_locale case I18n.locale when :'en-CA', :'fr-CA' 'WarmlyYours Canada' else 'WarmlyYours' end end |
#flag_image(country_iso3) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/localization_helper.rb', line 28 def flag_image(country_iso3) return if country_iso3.blank? # Map country ISO3 codes to SVG filenames svg_filename = case country_iso3.downcase when 'usa', 'us' 'us.svg' when 'can', 'ca' 'ca.svg' else return # No flag available for this country end content_tag(:span, inline_svg_tag("svgs/custom/#{svg_filename}"), { class: 'my-auto me-1' }) end |
#locale_country_name ⇒ Object
48 49 50 |
# File 'app/helpers/localization_helper.rb', line 48 def locale_country_name LocaleUtility.locale_to_country_iso_short_name(I18n.locale) end |
#locale_language ⇒ Object
44 45 46 |
# File 'app/helpers/localization_helper.rb', line 44 def locale_language I18n.locale.to_s.first(2) end |
#localize_content(raw_html) ⇒ Object
52 53 54 |
# File 'app/helpers/localization_helper.rb', line 52 def localize_content(raw_html) raw_html&.gsub(/\{\{\s*locale\s*\}\}/, I18n.locale.to_s)&.html_safe end |
#multi_locale_input(f, attr_name, wrapper_options = nil) ⇒ Object
56 57 58 |
# File 'app/helpers/localization_helper.rb', line 56 def multi_locale_input(f, attr_name, = nil) render partial: '/inputs/multi_locale_input', locals: { f: f, attr_name: attr_name, wrapper_options: } end |
#usa? ⇒ Boolean
4 5 6 |
# File 'app/helpers/localization_helper.rb', line 4 def usa? I18n.locale == :'en-US' end |