2013-02-06 03:16:51 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2014-09-16 19:15:05 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
module Slug
|
|
|
|
|
|
|
|
def self.for(string)
|
2014-11-18 08:47:04 +08:00
|
|
|
# TODO review if ja should use this
|
|
|
|
# ko asked for it to be removed
|
|
|
|
if ['zh_CN', 'ja'].include?(SiteSetting.default_locale)
|
2014-09-16 19:15:05 +08:00
|
|
|
unless defined? Stringex
|
|
|
|
require 'stringex_lite'
|
|
|
|
end
|
|
|
|
slug = string.to_url
|
2015-02-27 04:49:24 +08:00
|
|
|
else
|
|
|
|
slug = string.gsub("'", "").parameterize
|
|
|
|
slug.gsub!("_", "-")
|
2014-09-16 19:15:05 +08:00
|
|
|
end
|
2013-05-30 23:54:02 +08:00
|
|
|
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|