Module: LocalizationHelper
- Defined in:
- app/helpers/localization_helper.rb
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
10 11 12 13 14 15 |
# File 'app/helpers/localization_helper.rb', line 10 def can_change_country? return false if bot_request? return true unless @context_user @context_user.can_change_country? end |
#canada? ⇒ Boolean
6 7 8 |
# File 'app/helpers/localization_helper.rb', line 6 def canada? %i[en-CA fr-CA].include?(I18n.locale) end |
#company_locale ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/helpers/localization_helper.rb', line 17 def company_locale case I18n.locale when :'en-CA', :'fr-CA' 'WarmlyYours Canada' else 'WarmlyYours' end end |
#flag_image(country_iso3) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/localization_helper.rb', line 26 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
46 47 48 |
# File 'app/helpers/localization_helper.rb', line 46 def locale_country_name LocaleUtility.locale_to_country_iso_short_name(I18n.locale) end |
#locale_language ⇒ Object
42 43 44 |
# File 'app/helpers/localization_helper.rb', line 42 def locale_language I18n.locale.to_s.first(2) end |
#localize_content(raw_html) ⇒ Object
50 51 52 |
# File 'app/helpers/localization_helper.rb', line 50 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
54 55 56 |
# File 'app/helpers/localization_helper.rb', line 54 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
2 3 4 |
# File 'app/helpers/localization_helper.rb', line 2 def usa? I18n.locale == :'en-US' end |