Created
July 12, 2012 09:17
-
-
Save chytreg/3096949 to your computer and use it in GitHub Desktop.
Rails polish pluralization settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inside class Application < Rails::Application block | |
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/locales/pluralizations/pl.rb | |
{:pl => | |
{ :i18n => | |
{ :plural => | |
{ :keys => [:one, :few, :many, :other], | |
:rule => lambda { |n| | |
if n == 1 | |
:one | |
elsif [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) | |
:few | |
elsif (n != 1 && [0, 1].include?(n % 10)) || [5, 6, 7, 8, 9].include?(n % 10) || [12, 13, 14].include?(n % 100) | |
:many | |
else | |
:other | |
end | |
} | |
} | |
} | |
} | |
} | |
# http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html | |
# one → n is 1; | |
# few → n mod 10 in 2..4 and n mod 100 not in 12..14; | |
# many → n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14; | |
# other → everything else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/locales/pl.yml | |
pl: | |
age: | |
zero: 'brak danych' | |
one: '1 rok' | |
few: '%{count} lata' | |
many: '%{count} lat' | |
other: '%{count} lat' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/pluralization.rb | |
require "i18n/backend/pluralization" | |
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment