Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
878e9809
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
878e9809
编写于
3月 11, 2019
作者:
R
Rafael França
提交者:
GitHub
3月 11, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35571 from KaanOzkan/ko-parameterize-locale
Add locale option to #parameterize
上级
f1b8bb4e
bc9711fb
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
14 addition
and
10 deletion
+14
-10
activesupport/lib/active_support/core_ext/string/inflections.rb
...support/lib/active_support/core_ext/string/inflections.rb
+7
-2
activesupport/lib/active_support/inflector/transliterate.rb
activesupport/lib/active_support/inflector/transliterate.rb
+7
-8
未找到文件。
activesupport/lib/active_support/core_ext/string/inflections.rb
浏览文件 @
878e9809
...
...
@@ -162,6 +162,11 @@ def deconstantize
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
#
# If the optional parameter +locale+ is specified,
# the word will be parameterized as a word of that language.
# By default, this parameter is set to <tt>nil</tt> and it will use
# configured I18n.locale
#
# class Person
# def to_param
# "#{id}-#{name.parameterize}"
...
...
@@ -187,8 +192,8 @@ def deconstantize
#
# <%= link_to(@person.name, person_path) %>
# # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a>
def
parameterize
(
separator:
"-"
,
preserve_case:
false
)
ActiveSupport
::
Inflector
.
parameterize
(
self
,
separator:
separator
,
preserve_case:
preserve_case
)
def
parameterize
(
separator:
"-"
,
preserve_case:
false
,
locale:
nil
)
ActiveSupport
::
Inflector
.
parameterize
(
self
,
separator:
separator
,
preserve_case:
preserve_case
,
locale:
locale
)
end
# Creates the name of a table like Rails does for models to table names. This method
...
...
activesupport/lib/active_support/inflector/transliterate.rb
浏览文件 @
878e9809
...
...
@@ -51,19 +51,18 @@ module Inflector
#
# Now you can have different transliterations for each locale:
#
# I18n.locale = :en
# transliterate('Jürgen')
# transliterate('Jürgen', locale: :en)
# # => "Jurgen"
#
# I18n.locale = :de
# transliterate('Jürgen')
# transliterate('Jürgen', locale: :de)
# # => "Juergen"
def
transliterate
(
string
,
replacement
=
"?"
)
def
transliterate
(
string
,
replacement
=
"?"
,
locale:
nil
)
raise
ArgumentError
,
"Can only transliterate strings. Received
#{
string
.
class
.
name
}
"
unless
string
.
is_a?
(
String
)
I18n
.
transliterate
(
ActiveSupport
::
Multibyte
::
Unicode
.
tidy_bytes
(
string
).
unicode_normalize
(
:nfc
),
replacement:
replacement
replacement:
replacement
,
locale:
locale
)
end
...
...
@@ -89,9 +88,9 @@ def transliterate(string, replacement = "?")
# parameterize("^très|Jolie-- ", separator: "_") # => "tres_jolie--"
# parameterize("^très_Jolie-- ", separator: ".") # => "tres_jolie--"
#
def
parameterize
(
string
,
separator:
"-"
,
preserve_case:
false
)
def
parameterize
(
string
,
separator:
"-"
,
preserve_case:
false
,
locale:
nil
)
# Replace accented chars with their ASCII equivalents.
parameterized_string
=
transliterate
(
string
)
parameterized_string
=
transliterate
(
string
,
locale
)
# Turn unwanted chars into the separator.
parameterized_string
.
gsub!
(
/[^a-z0-9\-_]+/i
,
separator
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录