views:

98

answers:

2

I'm creating a Rails application where users can have a first and last name. Since I'm a perfectionist, the application may not show something like Dennis's profile or Xianx's profile, but rather Dennis' profile and Xianx' profile. I use I18n, so I wanted to ask what is the shortest way of implementing this? This grammar is the same for both English and Dutch, where the application will be translated to.

Oh, some important things:

  • I am not afraid of using helpers and the application controller
  • My language files are in Ruby, not YAML

Thanks!

+2  A: 

It's hard to be perfect in Dutch

 def having_s( word ) # maybe genitiv_s  is a better name
   case word[-1,1]  #  [-1] will do in ruby 1.9 
     when 's', 'x', 'z' 
       "#{word}'"
     else 
       "#{word}'s"
     end
  end

  names=%w(Alex Inez Kees Maria Bordeaux)
  names.each{|name| puts  having_s(name)}

The last testcase ("Bordeaux") yields a wrong result, according to this.

steenslag
eaux is always pronounced as 'o', so I can add that to the list. Also, for now it's not really a matter of life and death, as users can upload there vCard (with a small chance that It contains the phonetics if their name) and I can also ask the user if the site isn't sure :)
Time Machine
+2  A: 

One way to implement this with little risk of not being correct:

Instead of:

Person X's profile

Do:

Profile: Person X

There's not going to be a way to do the first for all languages/countries/cultures. The 2nd option may not look ideal, but you won't ever present anything incorrectly.

NinjaCat