mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
lean on Inflector transliteration
This commit is contained in:
parent
ecbaa45736
commit
9daf53df73
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+/, '-')
|
||||
|
|
|
@ -35,5 +35,11 @@ describe Slug do
|
|||
Slug.for("...hello").should == "hello"
|
||||
end
|
||||
|
||||
it 'handles our initial transliteration' do
|
||||
from = "àáäâčďèéëěêìíïîľĺňòóöôŕřšťůùúüûýžñç"
|
||||
to = "aaaacdeeeeeiiiillnoooorrstuuuuuyznc"
|
||||
Slug.for(from).should == to
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user