Why this doesn''t work? <%= link_to ''in english'', :locale => ''en'' if I18n.locale != ''en'' %> And how to make it work? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 3, 2012, at 12:50 PM, Fresh Mix wrote:> Why this doesn''t work? > > <%= link_to ''in english'', :locale => ''en'' if I18n.locale != ''en'' %> > > And how to make it work?The answer to both is parentheses. Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis wrote in post #1049966:> On Mar 3, 2012, at 12:50 PM, Fresh Mix wrote: > >> Why this doesn''t work? >> >> <%= link_to ''in english'', :locale => ''en'' if I18n.locale != ''en'' %> >> >> And how to make it work? > > The answer to both is parentheses. > > Walter<%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> ? Doesn''t work! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 3, 2012, at 2:36 PM, Fresh Mix wrote:> Walter Davis wrote in post #1049966: >> On Mar 3, 2012, at 12:50 PM, Fresh Mix wrote: >> >>> Why this doesn''t work? >>> >>> <%= link_to ''in english'', :locale => ''en'' if I18n.locale != ''en'' %> >>> >>> And how to make it work? >> >> The answer to both is parentheses. >> >> Walter > > <%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> ? > > Doesn''t work!Then please define doesn''t work. The former would throw a concatenation error. The new version does exactly what that you don''t expect? Another hint -- what is the precise value of the locale (value AND format)? Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis wrote in post #1049973:> On Mar 3, 2012, at 2:36 PM, Fresh Mix wrote: > >>> >>> Walter >> >> <%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> ? >> >> Doesn''t work! > > > Then please define doesn''t work.Ok, this code: <%= I18n.locale %> <%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> returns this html: en <a href="/welcome/index?locale=en">in english</a> Why? If I18n.locale == ''en'' there should not be link. So why "if (I18n.locale != ''en'')" is true ? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 3, 2012, at 3:17 PM, Fresh Mix wrote:> Walter Davis wrote in post #1049973: >> On Mar 3, 2012, at 2:36 PM, Fresh Mix wrote: >> >>>> >>>> Walter >>> >>> <%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> ? >>> >>> Doesn''t work! >> >> >> Then please define doesn''t work. > > Ok, this code: > > <%= I18n.locale %> > <%= link_to(''in english'', :locale => ''en'') if (I18n.locale != ''en'') %> > > returns this html: > > en > <a href="/welcome/index?locale=en">in english</a> > > Why? If I18n.locale == ''en'' there should not be link. > > So why "if (I18n.locale != ''en'')" is true ?Have you followed these steps: http://guides.rubyonrails.org/i18n.html#setting-and-passing-the-locale I think that you''re missing the part where you take the params[:locale] and do something with it. Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis wrote in post #1049976:> On Mar 3, 2012, at 3:17 PM, Fresh Mix wrote: > >>> >> <a href="/welcome/index?locale=en">in english</a> >> >> Why? If I18n.locale == ''en'' there should not be link. >> >> So why "if (I18n.locale != ''en'')" is true ? > > Have you followed these steps:I made it like this: class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale def set_locale locale = params[:locale] || session[:locale] || extract_locale_from_accept_language_header if(locale.match /^(ru|en)$/) I18n.locale = locale session[:locale] = locale end end private def extract_locale_from_accept_language_header request.env[''HTTP_ACCEPT_LANGUAGE''].scan(/^[a-z]{2}/).first end end ---- And if <%= I18n.locale %> prints on page "en" so I18n.locale is set -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 3, 2012, at 3:41 PM, Fresh Mix wrote:> Walter Davis wrote in post #1049976: >> On Mar 3, 2012, at 3:17 PM, Fresh Mix wrote: >> >>>> >>> <a href="/welcome/index?locale=en">in english</a> >>> >>> Why? If I18n.locale == ''en'' there should not be link. >>> >>> So why "if (I18n.locale != ''en'')" is true ? >> >> Have you followed these steps: > > I made it like this: > > class ApplicationController < ActionController::Base > protect_from_forgery > > before_filter :set_locale > > def set_locale > locale = params[:locale] || session[:locale] || > extract_locale_from_accept_language_header > if(locale.match /^(ru|en)$/) > I18n.locale = locale > session[:locale] = locale > end > end > > private > > def extract_locale_from_accept_language_header > request.env[''HTTP_ACCEPT_LANGUAGE''].scan(/^[a-z]{2}/).first > end > > end > > > ---- > > And if <%= I18n.locale %> prints on page "en" so I18n.locale is setAnything you print all by itself inside an erb block gets an implicit conversion to string. But a comparison or concatenation isn''t going to do the same for you. ''en'' != :en, for example. You could try <%= I18n.locale == ''en'' ? ''true'' : ''false'' %> and compare what you get with <%= I18n.locale.to_s == ''en'' ? ''true'' : ''false'' %> to see if this is your issue. Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 3, 8:17 pm, Fresh Mix <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> returns this html: > > en > <a href="/welcome/index?locale=en">in english</a> > > Why? If I18n.locale == ''en'' there should not be link. > > So why "if (I18n.locale != ''en'')" is true ? >I18n.locale is a symbol and :en is not == to ''en'' Fred> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.