Forum: Ruby on Rails Globalize : how to detect if a translated text is available

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
912b664b56818fd36821d006577ff3aa?d=identicon&s=25 Gerard de Brieder (Guest)
on 2006-04-20 10:42
(Received via mailing list)
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
912b664b56818fd36821d006577ff3aa?d=identicon&s=25 Gerard de Brieder (Guest)
on 2006-04-20 11:31
(Received via mailing list)
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...)"%>
912b664b56818fd36821d006577ff3aa?d=identicon&s=25 Gerard de Brieder (Guest)
on 2006-04-20 12:05
(Received via mailing list)
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...
This topic is locked and can not be replied to.