[Ruby] state_machine の国際化対応 (i18n)
state_machine の国際化対応 (i18n)の方法をメモ。
・pluginaweek/state_machine · GitHub
■ config/locales/model.ja.yml
ja: activerecord: state_machines: order: state: states: accepted: 注文受付 firmed: 注文確定 cancelled: 注文キャンセル delivered: 発送完了 events: accept: 注文 cancel: キャンセル deliver: 発送 errors: models: order: attributes: state: invalid_transition: "%{value}状態では%{event}処理はできません。" |
そんでもって、human_state_name で使う。
o.human_state_name # => "発送完了" |
【参考】
・I18n documentation is missing · Issue #114 · pluginaweek/state_machine