mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding documentation for ActiveModel::Translation
This commit is contained in:
parent
71328a9856
commit
91c38403be
2 changed files with 26 additions and 2 deletions
|
@ -167,3 +167,12 @@ functionality from the following modules:
|
||||||
|
|
||||||
{Learn more}[link:classes/ActiveModel/StateMachine.html]
|
{Learn more}[link:classes/ActiveModel/StateMachine.html]
|
||||||
|
|
||||||
|
* Integrating with Rail's internationalization (i18n) handling through
|
||||||
|
ActiveModel::Translations...
|
||||||
|
|
||||||
|
class Person
|
||||||
|
extend ActiveModel::Translation
|
||||||
|
end
|
||||||
|
|
||||||
|
{Learn more}[link:classes/ActiveModel/Translation.html]
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
require 'active_support/core_ext/hash/reverse_merge'
|
require 'active_support/core_ext/hash/reverse_merge'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|
||||||
|
# ActiveModel::Translation provides integration between your object and
|
||||||
|
# the Rails internationalization (i18n) framework.
|
||||||
|
#
|
||||||
|
# A minimal implementation could be:
|
||||||
|
#
|
||||||
|
# class TranslatedPerson
|
||||||
|
# extend ActiveModel::Translation
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# TranslatedPerson.human_attribute_name('my_attribue')
|
||||||
|
# #=> "My attribute"
|
||||||
|
#
|
||||||
|
# This also provides the required class methods for hooking into the
|
||||||
|
# Rails internationalization API, including being able to define a
|
||||||
|
# class based i18n_scope and lookup_ancestors to find translations in
|
||||||
|
# parent classes.
|
||||||
module Translation
|
module Translation
|
||||||
include ActiveModel::Naming
|
include ActiveModel::Naming
|
||||||
|
|
||||||
|
@ -18,8 +35,6 @@ module ActiveModel
|
||||||
|
|
||||||
# Transforms attributes names into a more human format, such as "First name" instead of "first_name".
|
# Transforms attributes names into a more human format, such as "First name" instead of "first_name".
|
||||||
#
|
#
|
||||||
# Example:
|
|
||||||
#
|
|
||||||
# Person.human_attribute_name("first_name") # => "First name"
|
# Person.human_attribute_name("first_name") # => "First name"
|
||||||
#
|
#
|
||||||
# Specify +options+ with additional translating options.
|
# Specify +options+ with additional translating options.
|
||||||
|
|
Loading…
Reference in a new issue