ruby-on-railsactiontextmobility

Rails translate rich text with Mobility and ActionText as backend?


Mobility has a syntax to translate Rails ActiveRecord strings and text:

class Word < ApplicationRecord
  extend Mobility
  translates :content
end

On the other hand, here is the syntax to declare rich text with ActionText:

class Word < ApplicationRecord
  has_rich_text :content
end

How can these be combined to efficiently translate rich text with Mobility? Ideally I want to avoid doing a double-join as suggested here in the context of Globalize, i.e. avoiding needing to join a translation table then joining a rich-text table.

There seems to be an opportunity to combine both steps using the ActionText table, which is already a polymorphic relationship similar to the key-value backend, so that the translation would be available "for free" with no performance impact compared to untranslated rich text.


Solution

  • This is now possible with Mobility Action Text.