LoginSignup
4
1

More than 5 years have passed since last update.

ActiveHash (ActiveYaml) を i18n 対応する

Last updated at Posted at 2019-02-02

ApplicationRecord と同じように i18n できなかったのでメモしておく。

config/application.rb
# ...
Bundler.require(*Rails.groups)

class ActiveHash::Base
  extend ActiveModel::Translation
end

module YourAppName
  class Application < Rails::Application
# ...
config/locales/ja.yml
ja:
  activemodel:
    models:
      model_name: モデル名

これをやらずとも、 https://github.com/zilkey/active_hash/pull/170 がマージされれば、ロケールを設定するだけでよくなる。

効用

class MyModel < ActiveYaml::Base
end

# これで、以下のメソッドたちの返り値をロケールから変更できる
MyModel.model_name.human
MyModel.human_attribute_name(:column_name)
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1