Skip to content

Instantly share code, notes, and snippets.

@lenart
Created September 24, 2013 20:01
Show Gist options
  • Save lenart/6690435 to your computer and use it in GitHub Desktop.
Save lenart/6690435 to your computer and use it in GitHub Desktop.
Rails 3.x I18n pluralization for slovene language
# app/views/users/index.html.haml
%h1 Uporabniki
- # 1 uporabnik
= t(:user, count: 1)
- # 2 uporabnika
= t(:user, count: 2)
- # 3 uporabniki
= t(:user, count: 3)
- # 4 uporabniki
= t(:user, count: 4)
- # 5 uporabnikov
= t(:user, count: 5)
# config/initializers/pluralization.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
# config/locales/plurals.rb
# Copied from Rails I18n project
{
:sl => { :i18n => { :plural => { :keys => [:one, :two, :few, :other], :rule => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } },
}
# Used in gist from Krule - https://gist.github.com/Krule/478347
# Haven't tried it out though
# {
# :'sl' => { :i18n => { :plural => { :rule => lambda { |n| [1].include?(n % 100) && ![11].include?(n % 100) ? :one : [2].include?(n % 100) && ![12].include?(n % 100) ? :two : [3, 4].include?(n % 100) && ![13, 14].include?(n % 100) ? :few : :other }}}}
# }
# config/locales/sl.yml
sl:
user:
one: 1 uporabnik
two: 2 uporabnika
few: "%{count} uporabniki"
other: "%{count} uporabnikov"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment