0

我正在使用 Mobility gem (v0.4.3 - https://github.com/shioyama/mobility ) 和 Rails 5.2,目前要设置后备,我必须在模型中进行设置:

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

主要问题是后备哈希是静态的,在我的应用程序中,哈希可能会根据客户端配置而改变。

有什么方法可以动态设置后备哈希?

4

1 回答 1

0

您可以在阅读时传递回退

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

像这样读

client.translate(fallback: [:ja, :es])
于 2018-03-23T07:34:02.130 回答