mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
lean on Inflector transliteration
This commit is contained in:
11
lib/slug.rb
11
lib/slug.rb
@ -11,14 +11,11 @@ module Slug
|
||||
str.gsub!(/^\s+|\s+$/, '')
|
||||
str.downcase!
|
||||
|
||||
from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;."
|
||||
to = "aaaaeeeeiiiioooouuuunc-------"
|
||||
# The characters we want to replace with a hyphen
|
||||
str.tr!("·/_,:;.", "\-")
|
||||
|
||||
idx = 0
|
||||
from.each_char do |c|
|
||||
str.gsub!(c, to[idx])
|
||||
idx += 1
|
||||
end
|
||||
# Convert to ASCII or remove if transliteration is unknown.
|
||||
str = ActiveSupport::Inflector.transliterate(str, '')
|
||||
|
||||
str.gsub!(/[^a-z0-9 -]/, '')
|
||||
str.gsub!(/\s+/, '-')
|
||||
|
Reference in New Issue
Block a user