The shortest way to define a name ends with the words `s`,` x` or `z`, and then with the method` I18n.t`

I am creating a Rails application where users can have first and last name. Since I'm a perfectionist, the app might not show something like Dennis profile

or Xianx profile

, but rather Dennis' profile

and Xianx' profile

. I am using I18n, so I wanted to ask what is the shortest way to implement this? This grammar is the same for English and Dutch where the app will be translated.

Oh, some important things:

  • I am not afraid to use helpers and application controller.
  • My language files are in Ruby, not YAML

Thank!

+2


source to share


2 answers


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 test file ("Bordeaux") gives the wrong result according to this .

+2


source


One way to do this with a little risk of being wrong:

Instead:

Person X profile

      



do:

Profile: Person X

      

Impossible to do the first for all languages ​​/ countries / cultures. The second option may not sound perfect, but you will never misrepresent anything.

+2


source







All Articles