1

Im using the Mobility gem (v0.4.3 - https://github.com/shioyama/mobility) and Rails 5.2, and at the moment to set fallbacks I have to set up this in the model:

class Client < ApplicationRecord
  ....
  extend Mobility
  translates :title, type: :string, locale_accessors: true, fallbacks: { en: :es }
  ....
end

The main problem is that the fallback hash is static and in my app the hash could change depending the client configuration.

There is any way to set the fallback hash dynamically?

darkcode
  • 868
  • 12
  • 27

1 Answers1

1

You can pass the fallbacks while reading

class Client < ApplicationRecord
 ....
 extend Mobility
  translates :title, type: :string, fallbacks: true
 ....
 end

and read like this

client.translate(fallback: [:ja, :es])
Thollsten
  • 223
  • 1
  • 2
  • 6