Is there a commonly accepted method for translating user input using
I18n ? I would like users to be able to enter the names of books in an
entry form in their own language. The list of books is large but
finite (definitely no more than 500 book titles).
I have .yml files with all the book names as english keys: For
example, in my ‘es.yml’ I have
txt:
book:
Lord of the Rings: “El Señor de los Anillos”
If someone enters ‘El Señor de los Anillos’ how do I translate this
back to English? I’ve tried:
I18n.backend.send(:translations).index(“El Señor de los Anillos”)
HI
i have the same problem and would like to apply your solution, but
how to install FastBackend in Rails 2.3.3
I tried by just adding I18n.backend = I18n::Backend::Fast.new in a
initializer file 8new_rails_deafult) but that failed
Read about some problems installing it in Rails >2.5 ???
Hans M.
St: Larsgatan 50, 58224 Linköping, Sweden
Phone: +46708371202
Hi Sven
I try to do the same as Veet, that is to find the inverse translation
I followed your advices, but it fails
I my case I have in the yaml file
sv:
enumerations:
parenthood:
parent_role:
father: far
I am trying to find the key corresponding to ‘far’ by the following
expression
I18n.backend.send(:translations)[:sv][:enumerations][:parenthood]
[:parent_role].index(‘far’)
It looks as the solution proposed by you and applied successfully by
Veet, but it returns the error
NoMethodError (You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]):
What is wrong with my attempt ??
Hans M.
St: Larsgatan 50, 58224 Linköping, Sweden
Phone: +46708371202
You might need to call #init_translations first so your translations
will be actually loaded.
Please, everybody keep in mind that all of this is wild hackery. It
reaches deep into the backend and uses things that might change at any
point of time.
Maybe someone could come up with some plugin for Backend::Simple that
(still monkeypatches but) hides some of the complexity here?
Sven
Thanks but I tried both I18n.init_translations and
I18n.backend,init_translations but they will not work for me
The former is an undefined method and the latter a protected method
So you may be right, tthis may not be a very reliable way to solve the
problem
Hans M.
St: Larsgatan 50, 58224 Linköping, Sweden
Phone: +46708371202
Thanks for the insight, Sven. It’s always good to know when you’re
teetering on the edge. It seems as though rudimentary reverse
translation to enable users to input data in their own language is
important so hopefully this will be a part of I18n that will be
fleshed out in future.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.