zastąp domyślną liczbę mnogą dla nazwy modelu w rails3

Moje locale to: de I Lubię to:

Sheet.model_name.human.pluralize # => Belegs

Aby dodać mi końcówkę " e "zamiast" s "

Sheet.model_name.human.pluralize # => Belege
Tylko dla klasy arkuszowej. Czy mogę go jakoś dodać w moim config / locales / models / de.yml ?
Author: Cœur, 2011-05-30

3 answers

Po pierwsze, musisz przestać używać .pluralize. Wykorzystuje Inflector (który jest używany głównie do szyn wewnętrznych, np. odgadywanie nazw tabel dla arkusza modelu - > arkusze).

Sheet.model_name.human # => "Beleg"
"Beleg".pluralize # => "Belegs"

Należy użyć opcji :count.

Sheet.model_name.human(:count => 2) # => "Belege"

To wymaga, abyś zmodyfikował swoje de.yml jako takie:

de:

  ...

  activerecord:

    ...

    models:
      sheet:
        one: Beleg
        other: Belege
 53
Author: Marcel Jackwerth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-08-28 11:27:55

Możesz przesłaniać mnogość w ten sposób:

W config/initializers/inflections.rb

Do:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'Beleg', 'Belege'
end
 12
Author: bruno077,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-30 18:31:49

Jeśli nie lubisz liczby jawnej (np. 2) możesz użyć :many np.

Sheet.model_name.human(count => :many)

Lub bez hash rocket (dla Ruby >= 1.9):

Sheet.model_name.human(count: :many)
 1
Author: jmarceli,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-04 16:26:10