I
I
Ivan Nesterovich2014-06-11 22:23:26
Ruby on Rails
Ivan Nesterovich, 2014-06-11 22:23:26

[Rails] Which gem should I choose for translating data in the database?

There is a need to organize a multilingual site. The main problem was the choice of a gem capable of organizing the translation of model attributes.
The main requirements are speed and direct access to model attributes. Then I will need to sort by these attributes (.order("name DESC")), make a selection (.select("name")), full-text search.
For example:
- hstore_translate. The gem seems to be good, but I don’t quite understand how, for example, I can sort by a field that has a translation?
- globalize. There are suspicions that the result will be very slow, because. if you make a selection from a database of 100 records, then for each one it will try to load the translation... And if we also connect links with translations, it will turn out to be two hundred requests... I could be wrong, of course, correct me.
Is there a gem that will answer my demand with "yes", or do I need to crutch something of my own ... Lately, there hasn't been at all, unfortunately.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Finist, 2014-06-12
@Finist

Unfortunately, I don’t know a ready-made solution, I solved this problem in this way, stored the translations in the database, forwarded them to redis, and pulled them from redis through the standard I18n. If there is no time for all this kitchen, I can advise something like https://phraseapp.com

I
Ivan Kryak, 2014-06-12
@sck_v

There are suspicions that the result will be very slow, because. if you make a selection from a database of 100 records, then for each one it will try to load the translation... And also if we connect the links with translations as well, it will turn out to be under two hundred requests... I could be wrong, of course, correct me.

N+1 same

D
Dimitriy, 2014-06-13
@Vakiliy

Well, in general, both of them have +/-, although the globalize example does joins and searches by locales, it does sorting by the main table, at least it was like that, as I haven’t checked it now, and also an overhead for sql queries, hstore ` there is no overhead, but search and sorting will look something like this:
and with FTS

WHERE to_tsvector('russian', i18n_field->'lang') @@ to_tsquery('russain, 'Запрос') 
ORDER BY i18n_field->'lang' ASC

All in all, it's not scary. FTS can, for example, be produced through sunspot .
When I chose for myself, for life simplification, I settled on this , in a slightly doped form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question