I'm using the permalink_fu plugin to create permalinks from titles. My problem is: If the title contains german characters, they are just replaced with '_'.
What I need is something that replaces ä with ae ü with ue ö with oe
I fount String.tr but the problem here is that it replaces 1 character with 1 replacement, so it would work for replacing
é with e ø with o
etc.
Does anyone have a nice and clean solution for that?
Thanks
Look at transliterate and parameterize (with transliterations in locales/de.yml):
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate
I18n.transliterate("Über der Höhenstraße")
=> "Ueber der Hoehenstrasse"
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize
"Über der Höhenstraße".parameterize
=> "ueber-der-hoehenstrasse"
If you don't want to write the transliterations yourself, you can install the rails-i18n
gem.
I have written a small Library called Asciify for exactly that purpose
$ sudo gem install asciify
Usage:
#!/bin/ruby
require "asciify"
"Lücke".asciify #=> "Luecke"
You can provide a YAML-file for custom mappings like so:
translator = Asciify.new("/path/to/mappings.yaml")
output_string = translator.convert("input string")
(see the builtin default mapping for the expected format)
The whole project is quite old, but maybe it does the job you need it to. If not, maybe the source code will be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With