From 558820f57311e925acaffc58accc1b3f89d697a6 Mon Sep 17 00:00:00 2001 From: Yuki INOUE Date: Sun, 3 Feb 2019 00:37:00 +0900 Subject: [PATCH 1/3] support i18n --- lib/active_hash/base.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_hash/base.rb b/lib/active_hash/base.rb index 7a65cd6d..62037b57 100644 --- a/lib/active_hash/base.rb +++ b/lib/active_hash/base.rb @@ -57,7 +57,11 @@ def normalize(v) end if Object.const_defined?(:ActiveModel) - extend ActiveModel::Naming + if Object.const_defined?(:I18n) + extend ActiveModel::Translation + else + extend ActiveModel::Naming + end include ActiveModel::Conversion else def to_param From f63a8a0fc4e3b1c7f7a3c934817b6d9dcf979278 Mon Sep 17 00:00:00 2001 From: Yuki INOUE Date: Mon, 4 Feb 2019 16:13:33 +0900 Subject: [PATCH 2/3] Simply use ActiveModel::Translation instead of Naming --- lib/active_hash/base.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/active_hash/base.rb b/lib/active_hash/base.rb index 62037b57..eeb347eb 100644 --- a/lib/active_hash/base.rb +++ b/lib/active_hash/base.rb @@ -57,11 +57,7 @@ def normalize(v) end if Object.const_defined?(:ActiveModel) - if Object.const_defined?(:I18n) - extend ActiveModel::Translation - else - extend ActiveModel::Naming - end + extend ActiveModel::Translation include ActiveModel::Conversion else def to_param From 1c4c9613844bb361228b9aff318056d9286944e5 Mon Sep 17 00:00:00 2001 From: Yuki INOUE Date: Mon, 4 Feb 2019 16:28:26 +0900 Subject: [PATCH 3/3] Update README for i18n --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index cf0d55d9..0a76203f 100644 --- a/README.md +++ b/README.md @@ -543,6 +543,20 @@ Constants are formed by first stripping all non-word characters and then upcasin The field specified as the _enum_accessor_ must contain unique data values. +## I18n + +ActiveHash supports i18n as ActiveModel. +Put following code in one of your locale file (e.g. `config/locales/LANGUAGE_CODE.yml`) + +```yaml +# for example, inside config/locales/ja.yml +ja: + activemodel: + models: + # `Country.model_name.human` will evaluates to "国" + country: "国" +``` + ## Contributing If you'd like to become an ActiveHash contributor, the easiest way it to fork this repo, make your changes, run the specs and submit a pull request once they pass.