Gerard de Brieder
2006-Apr-20 08:39 UTC
[Rails] Globalize : how to detect if a translated text is available ?
Hi all, I was wondering how one can detect if a translated text is available when using the globalize plugin. If this is possible , then I would like to make the following : For example, in your view you have : <%@menu.each { | item | %> <%=item.t%> <%}%> Now what I would like to happen is , when the menu item has no translation available , and when a admin is logged in (by checking the session vars) it shows a little icon which will be clickable to insert the translation of that item. Please share your thoughts on this, Gerard de Brieder. Govannon. tel : +31624739047 http://www.govannon.nl info@govannon.nl
Gerard de Brieder
2006-Apr-20 09:29 UTC
[Rails] Globalize : how to detect if a translated text is available ?
Hi all, Just sharing my findings in the mean while... I did find out that the object will have an attributed called <field_name>_not_base so you could make a condition like : <%="(Translated)" if @text.body_not_base rescue "(Translation not available...)"%> On 20-apr-2006, at 10:39 , 20-apr-2006, Gerard de Brieder wrote:> Hi all, > > I was wondering how one can detect if a translated text is > available when using the globalize plugin. > If this is possible , then I would like to make the following : > > For example, in your view you have : > <%@menu.each { | item | %> > <%=item.t%> > <%}%> > > Now what I would like to happen is , when the menu item has no > translation available , and when a admin is logged in (by checking > the session vars) it shows a little icon which will be clickable to > insert the translation of that item. > > > Please share your thoughts on this, > > Gerard de Brieder. > > > Govannon. > tel : +31624739047 > http://www.govannon.nl > info@govannon.nl > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Gerard de Brieder
2006-Apr-20 10:03 UTC
[Rails] Globalize : how to detect if a translated text is available ?
Current progress : I made an helper like this : def translate(object,attribute) unless object.nil? ret="" unless Locale.base? if object.send("#{attribute}_not_base") ret+="(Translated)<br>".t else ret+="(No translation available)<br>".t end end ret+=object.send("#{attribute}") else ret="Text not available".t end return ret end Which works quite well, ofcourse i can no extent it when the translation is not avaiable to make the controls to change it.... I would appreciate it if someone could show me how to beautify the piece of code above... On 20-apr-2006, at 11:29 , 20-apr-2006, Gerard de Brieder wrote:> Hi all, > > Just sharing my findings in the mean while... > > I did find out that the object will have an attributed called > <field_name>_not_base so you could make a condition like : > <%="(Translated)" if @text.body_not_base rescue "(Translation not > available...)"%> > > > > On 20-apr-2006, at 10:39 , 20-apr-2006, Gerard de Brieder wrote: > >> Hi all, >> >> I was wondering how one can detect if a translated text is >> available when using the globalize plugin. >> If this is possible , then I would like to make the following : >> >> For example, in your view you have : >> <%@menu.each { | item | %> >> <%=item.t%> >> <%}%> >> >> Now what I would like to happen is , when the menu item has no >> translation available , and when a admin is logged in (by checking >> the session vars) it shows a little icon which will be clickable >> to insert the translation of that item. >> >> >> Please share your thoughts on this, >> >> Gerard de Brieder. >> >> >> Govannon. >> tel : +31624739047 >> http://www.govannon.nl >> info@govannon.nl >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails