Last active
May 19, 2018 10:08
-
-
Save ozergul/d61d008163cea9550bb91a22a768c04a to your computer and use it in GitHub Desktop.
Seo friendly url for Turkish chars. Crystal/ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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