Где определены параметры метода в Rails? - PullRequest
0 голосов
/ 10 августа 2010
# Transform the model name into a more humane format, using I18n. By default,
# it will underscore then humanize the class name
#
#   BlogPost.model_name.human # => "Blog post"
#
# Specify +options+ with additional translating options.

Я нашел вышеупомянутое, копаясь в Rails, пытаясь выяснить, каковы именно варианты перевода. Я могу найти много ссылок, которые говорят, использовать + опции +, но не могу найти точного метода, где эти опции определены. Чего мне не хватает?

1 Ответ

2 голосов
/ 10 августа 2010

Метод, о котором вы говорите: ActiveRecord::Base#human

# Transform the model name into a more humane format, using I18n. By default,
# it will underscore then humanize the class name
#
#   BlogPost.model_name.human # => "Blog post"
#
# Specify +options+ with additional translating options.
def human(options={})
  return @human unless @klass.respond_to?(:lookup_ancestors) &&
                       @klass.respond_to?(:i18n_scope)

  defaults = @klass.lookup_ancestors.map do |klass|
    klass.model_name.underscore.to_sym
  end

  defaults << options.delete(:default) if options[:default]
  defaults << @human

  options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
  I18n.translate(defaults.shift, options)
end

, которая внутренне зависит от I18n.translate. Таким образом, options может быть любым параметром, поддерживаемым методом I18n, включая :scope, :default и другие.

См. http://guides.rubyonrails.org/i18n.html#looking-up-translations

Аргумент options также зависит от используемого в настоящее время бэкэнда I18n.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...