Module: FbLocalizer::FbLocalizerHelpers

Defined in:
lib/fb-localizer.rb

Instance Method Summary collapse

Instance Method Details

#get_fb_locale(ruby_locale = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fb-localizer.rb', line 13

def get_fb_locale(ruby_locale = nil)
  ruby_locale ||= I18n.locale
  ruby_locale = ruby_locale.to_sym if ruby_locale.is_a? String

  candidates = FbLocalizer::FbLocalizerHelpers::FB_LOCALES.select{ |l| l.match(/^#{ruby_locale}/)}
  return "en_US" if candidates.empty? # return American English if no candidates at all

  priorized = FbLocalizer.priorized[ruby_locale] # get priorized locale for that one
  if priorized && candidates.include?(priorized) # if available, get that one
    priorized
  else # if not, just get the first available
    candidates.first
  end
end