From 9bd91b00b85c77bc294ae2a99beae203cc163227 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Mon, 3 May 2010 16:44:32 +1000 Subject: Favor %{} in all code instead of (deprecated) {{}} as interpolation syntax for I18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../activerecord_validations_callbacks.textile | 24 +++++++++++----------- railties/guides/source/i18n.textile | 10 ++++----- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 126a6efff5..97915d5d55 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -234,7 +234,7 @@ This helper validates that the attributes' values are not included in a given se class Account < ActiveRecord::Base validates_exclusion_of :subdomain, :in => %w(www), - :message => "Subdomain {{value}} is reserved." + :message => "Subdomain %{value} is reserved." end @@ -262,7 +262,7 @@ This helper validates that the attributes' values are included in a given set. I class Coffee < ActiveRecord::Base validates_inclusion_of :size, :in => %w(small medium large), - :message => "{{value}} is not a valid size" + :message => "%{value} is not a valid size" end @@ -290,12 +290,12 @@ The possible length constraint options are: * +:in+ (or +:within+) - The attribute length must be included in a given interval. The value for this option must be a range. * +:is+ - The attribute length must be equal to the given value. -The default error messages depend on the type of length validation being performed. You can personalize these messages using the +:wrong_length+, +:too_long+, and +:too_short+ options and {{count}} as a placeholder for the number corresponding to the length constraint being used. You can still use the +:message+ option to specify an error message. +The default error messages depend on the type of length validation being performed. You can personalize these messages using the +:wrong_length+, +:too_long+, and +:too_short+ options and %{count} as a placeholder for the number corresponding to the length constraint being used. You can still use the +:message+ option to specify an error message. class Person < ActiveRecord::Base validates_length_of :bio, :maximum => 1000, - :too_long => "{{count}} characters is the maximum allowed" + :too_long => "%{count} characters is the maximum allowed" end @@ -307,8 +307,8 @@ class Essay < ActiveRecord::Base :minimum => 300, :maximum => 400, :tokenizer => lambda { |str| str.scan(/\w+/) }, - :too_short => "must have at least {{count}} words", - :too_long => "must have at most {{count}} words" + :too_short => "must have at least %{count} words", + :too_long => "must have at most %{count} words" end @@ -337,11 +337,11 @@ end Besides +:only_integer+, the +validates_numericality_of+ helper also accepts the following options to add constraints to acceptable values: -* +:greater_than+ - Specifies the value must be greater than the supplied value. The default error message for this option is "_must be greater than {{count}}_". -* +:greater_than_or_equal_to+ - Specifies the value must be greater than or equal to the supplied value. The default error message for this option is "_must be greater than or equal to {{count}}_". -* +:equal_to+ - Specifies the value must be equal to the supplied value. The default error message for this option is "_must be equal to {{count}}_". -* +:less_than+ - Specifies the value must be less than the supplied value. The default error message for this option is "_must be less than {{count}}_". -* +:less_than_or_equal_to+ - Specifies the value must be less than or equal the supplied value. The default error message for this option is "_must be less or equal to {{count}}_". +* +:greater_than+ - Specifies the value must be greater than the supplied value. The default error message for this option is "_must be greater than %{count}_". +* +:greater_than_or_equal_to+ - Specifies the value must be greater than or equal to the supplied value. The default error message for this option is "_must be greater than or equal to %{count}_". +* +:equal_to+ - Specifies the value must be equal to the supplied value. The default error message for this option is "_must be equal to %{count}_". +* +:less_than+ - Specifies the value must be less than the supplied value. The default error message for this option is "_must be less than %{count}_". +* +:less_than_or_equal_to+ - Specifies the value must be less than or equal the supplied value. The default error message for this option is "_must be less or equal to %{count}_". * +:odd+ - Specifies the value must be an odd number if set to true. The default error message for this option is "_must be odd_". * +:even+ - Specifies the value must be an even number if set to true. The default error message for this option is "_must be even_". @@ -469,7 +469,7 @@ The +:allow_nil+ option skips the validation when the value being validated is + class Coffee < ActiveRecord::Base validates_inclusion_of :size, :in => %w(small medium large), - :message => "{{value}} is not a valid size", :allow_nil => true + :message => "%{value} is not a valid size", :allow_nil => true end diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index dcad451e23..bb383d3cf9 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -531,7 +531,7 @@ In many cases you want to abstract your translations so that *variables can be i All options besides +:default+ and +:scope+ that are passed to +#translate+ will be interpolated to the translation: -I18n.backend.store_translations :en, :thanks => 'Thanks {{name}}!' +I18n.backend.store_translations :en, :thanks => 'Thanks %{name}!' I18n.translate :thanks, :name => 'Jeremy' # => 'Thanks Jeremy!' @@ -547,7 +547,7 @@ The +:count+ interpolation variable has a special role in that it both is interp I18n.backend.store_translations :en, :inbox => { :one => '1 message', - :other => '{{count}} messages' + :other => '%{count} messages' } I18n.translate :inbox, :count => 2 # => '2 messages' @@ -711,7 +711,7 @@ h5. Error Message Interpolation The translated model name, translated attribute name, and value are always available for interpolation. -So, for example, instead of the default error message +"can not be blank"+ you could use the attribute name like this : +"Please fill in your {{attribute}}"+. +So, for example, instead of the default error message +"can not be blank"+ you could use the attribute name like this : +"Please fill in your %{attribute}"+. * +count+, where available, can be used for pluralization if present: @@ -750,8 +750,8 @@ en: errors: template: header: - one: "1 error prohibited this {{model}} from being saved" - other: "{{count}} errors prohibited this {{model}} from being saved" + one: "1 error prohibited this %{model} from being saved" + other: "%{count} errors prohibited this %{model} from being saved" body: "There were problems with the following fields:" -- cgit v1.2.3