views:

21

answers:

1

Hi guys, I am writing a helper for our app that will return if the page is not in english. At first this was my check:

!params[:lang].nil? || !cookies[:lang].nil? || !session[:lang].nil? || !session[:locale] || !params[:locale]

(i looked at params, cookies, and sessions) if any of them wasn't nil, then I'd immediately conclude that the user clicked on our translate link(which introduces the params[:lang] and add it to the session and cookie.

One thing I forgot is that if the user switched back to "en", then it would still be !nil. Is there a quick and easy way/call of checking if the page isn't in English? Or am i stuck with doing a lot of ifs for each params, cookies and sessions to check if they exist AND if they are in english?

A: 

Here's a few code snippets of what I did and some from refactormycode:

http://refactormycode.com/codes/1387-too-many-ifs-and-ands

def is_english?
  [params, cookies, session].each do |store|
    return (store[:lang].andand.to_s == "en" || store[:locale].andand.to_s == "eng")
  end

  false
end

Hope it helps anyone!

corroded