Skip to content

Instantly share code, notes, and snippets.

@ozergul
Last active May 19, 2018 10:08
Show Gist options
  • Save ozergul/d61d008163cea9550bb91a22a768c04a to your computer and use it in GitHub Desktop.
Save ozergul/d61d008163cea9550bb91a22a768c04a to your computer and use it in GitHub Desktop.
Seo friendly url for Turkish chars. Crystal/ruby
def to_param(title)
original = ["ş","Ş","ı","I","İ","ğ","Ğ","ü","Ü","ö","Ö","Ç","ç","(",")","/",":",","]
replacements = ["s","s","i","i","i","g","g","u","u","o","o","c","c","","","-","-",""]
new_text = title.downcase.tr(original.join, replacements.join)
new_text = new_text.downcase.gsub(/[^a-zA-Z0-9]+/, "-").gsub(/-{2,}/, "-")
if new_text[new_text.size - 1].to_s == "-"
new_text = new_text.chomp("-")
end
new_text
end
to_param("ÇÖĞÜŞIçöğüşı falan filan #1222///")
# --> cogusicogusi-falan-filan-1222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment