Enable kinks on Rails5

I need to add inflection rules for the Italian language in a Rails5 application.

So, I updated initializers/inflections.rbas follows.

ActiveSupport::Inflector.inflections(:it) do |inflect|
   inflect.plural /^([\w]*)o/i, '\1i'
   inflect.plural /^([\w]*)a/i, '\1e'
   inflect.uncountable %w( attività )
 end

But after restarting the server, the English rules are still used.

The locale is correctly set to :it(the user interface is correctly localized), but the words are alternated using English rules.

Do I have a way to include the rules that I defined?

thank

+4
source share
1 answer

The Rails docs for pluralize seem to indicate that the locale should be passed to the pluralize method as an argument, and not automatically inferred from your application locale. So something like:

pluralize("cane", :it)
# or directly on string
"cane".pluralize(2, :it)

... .

, :it I18n.locale, .

, !

"cane".pluralize(:it) #=> "cene"

( ) . , , a . \z , , . \A ^:

ActiveSupport::Inflector.inflections(:it) do |inflect|
  inflect.plural /\A([\w]*)o\z/i, '\1i'
  inflect.plural /\A([\w]*)a\z/i, '\1e'
  inflect.uncountable %w( attività )
end
+1

Source: https://habr.com/ru/post/1658194/