开发者

rails check if page is translated

I am writing a helper for our app that will return if the page is not in english. At first th开发者_StackOverflow中文版is 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?


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜