Module: LocalizationHelper

Defined in:
app/helpers/localization_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_change_country?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


6
7
8
# File 'app/helpers/localization_helper.rb', line 6

def canada?
  %i[en-CA fr-CA].include?(I18n.locale)
end

#company_localeObject



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

  (:span, inline_svg_tag("svgs/custom/#{svg_filename}"), { class: 'my-auto me-1' })
end

#locale_country_nameObject



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_languageObject



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, wrapper_options = nil)
  render partial: '/inputs/multi_locale_input', locals: { f: f, attr_name: attr_name, wrapper_options: wrapper_options }
end

#usa?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'app/helpers/localization_helper.rb', line 2

def usa?
  I18n.locale == :'en-US'
end