Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
352865d0
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,发现更多精彩内容 >>
提交
352865d0
编写于
5月 28, 2017
作者:
M
Matthew Draper
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29097 from EilisHamilton/fix_uncountable_pluralization_locale
Fix pluralization of uncountables when given a locale
上级
58a5aa40
7c45146b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
6 deletion
+20
-6
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+4
-0
activesupport/lib/active_support/inflector/methods.rb
activesupport/lib/active_support/inflector/methods.rb
+9
-6
activesupport/test/inflector_test.rb
activesupport/test/inflector_test.rb
+7
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
352865d0
*
`#singularize`
and
`#pluralize`
now respect uncountables for the specified locale.
*Eilis Hamilton*
*
Add ActiveSupport::CurrentAttributes to provide a thread-isolated attributes singleton.
Primary use case is keeping all the per-request attributes easily available to the whole system.
...
...
activesupport/lib/active_support/inflector/methods.rb
浏览文件 @
352865d0
...
...
@@ -28,7 +28,7 @@ module Inflector
# pluralize('CamelOctopus') # => "CamelOctopi"
# pluralize('ley', :es) # => "leyes"
def
pluralize
(
word
,
locale
=
:en
)
apply_inflections
(
word
,
inflections
(
locale
).
plurals
)
apply_inflections
(
word
,
inflections
(
locale
).
plurals
,
locale
)
end
# The reverse of #pluralize, returns the singular form of a word in a
...
...
@@ -45,7 +45,7 @@ def pluralize(word, locale = :en)
# singularize('CamelOctopi') # => "CamelOctopus"
# singularize('leyes', :es) # => "ley"
def
singularize
(
word
,
locale
=
:en
)
apply_inflections
(
word
,
inflections
(
locale
).
singulars
)
apply_inflections
(
word
,
inflections
(
locale
).
singulars
,
locale
)
end
# Converts strings to UpperCamelCase.
...
...
@@ -387,12 +387,15 @@ def const_regexp(camel_cased_word)
# Applies inflection rules for +singularize+ and +pluralize+.
#
# apply_inflections('post', inflections.plurals) # => "posts"
# apply_inflections('posts', inflections.singulars) # => "post"
def
apply_inflections
(
word
,
rules
)
# If passed an optional +locale+ parameter, the uncountables will be
# found for that locale.
#
# apply_inflections('post', inflections.plurals, :en) # => "posts"
# apply_inflections('posts', inflections.singulars, :en) # => "post"
def
apply_inflections
(
word
,
rules
,
locale
=
:en
)
result
=
word
.
to_s
.
dup
if
word
.
empty?
||
inflections
.
uncountables
.
uncountable?
(
result
)
if
word
.
empty?
||
inflections
(
locale
)
.
uncountables
.
uncountable?
(
result
)
result
else
rules
.
each
{
|
(
rule
,
replacement
)
|
break
if
result
.
sub!
(
rule
,
replacement
)
}
...
...
activesupport/test/inflector_test.rb
浏览文件 @
352865d0
...
...
@@ -420,6 +420,8 @@ def test_inflector_locality
inflect
.
singular
(
/es$/
,
""
)
inflect
.
irregular
(
"el"
,
"los"
)
inflect
.
uncountable
(
"agua"
)
end
assert_equal
(
"hijos"
,
"hijo"
.
pluralize
(
:es
))
...
...
@@ -432,12 +434,17 @@ def test_inflector_locality
assert_equal
(
"los"
,
"el"
.
pluralize
(
:es
))
assert_equal
(
"els"
,
"el"
.
pluralize
)
assert_equal
(
"agua"
,
"agua"
.
pluralize
(
:es
))
assert_equal
(
"aguas"
,
"agua"
.
pluralize
)
ActiveSupport
::
Inflector
.
inflections
(
:es
)
{
|
inflect
|
inflect
.
clear
}
assert
ActiveSupport
::
Inflector
.
inflections
(
:es
).
plurals
.
empty?
assert
ActiveSupport
::
Inflector
.
inflections
(
:es
).
singulars
.
empty?
assert
ActiveSupport
::
Inflector
.
inflections
(
:es
).
uncountables
.
empty?
assert
!
ActiveSupport
::
Inflector
.
inflections
.
plurals
.
empty?
assert
!
ActiveSupport
::
Inflector
.
inflections
.
singulars
.
empty?
assert
!
ActiveSupport
::
Inflector
.
inflections
.
uncountables
.
empty?
end
def
test_clear_all
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录