Globalize : how to detect if a translated text is available


#1

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 :
<removed_email_address@domain.invalid { | 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


removed_email_address@domain.invalid


#2

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…)”%>


#3

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)
".t
else
ret+="(No translation available)
".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…