lib/fb-localizer.rb in fb-localizer-0.1.3 vs lib/fb-localizer.rb in fb-localizer-0.2.0
- old
+ new
@@ -3,23 +3,26 @@
module FbLocalizer
DEFAULT_PRIORITIES = { :en => "en_US", :es => "es_ES", :pt => "pt_PT", :zh => "zh_CN" }
mattr_accessor :priorized
+ @@skip_loading = false
+ @@skip_loading = true if defined?(Rails) && Rails.env.development?
+ mattr_accessor :skip_loading
+
module FbLocalizerHelpers
def get_fb_locale(ruby_locale = nil)
- ruby_locale = ruby_locale.to_sym if ruby_locale.is_a? String
ruby_locale ||= I18n.locale
- fb_candidate_locales = FbLocalizer::FbLocalizerHelpers::FB_LOCALES.select{ |l| l.match(/^#{ruby_locale}/)}
- if fb_candidate_locales.any?
- priorized = FbLocalizer.priorized[ruby_locale] # get priorized locale for that one
- if priorized && fb_candidate_locales.include?(priorized) # if available, get that one
- priorized
- else # if not, just get the first available
- fb_candidate_locales[0]
- end
- else
- "en_US" # US english by default
+ 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
end
def self.configure