Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
410a4286
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 搜索 >>
提交
410a4286
编写于
6月 11, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get rid of the alternate namespace lookup.
上级
f5e1548c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
5 addition
and
17 deletion
+5
-17
activemodel/lib/active_model/naming.rb
activemodel/lib/active_model/naming.rb
+3
-4
activemodel/lib/active_model/translation.rb
activemodel/lib/active_model/translation.rb
+2
-3
activemodel/test/cases/translation_test.rb
activemodel/test/cases/translation_test.rb
+0
-10
未找到文件。
activemodel/lib/active_model/naming.rb
浏览文件 @
410a4286
...
...
@@ -21,7 +21,7 @@ def initialize(klass, namespace = nil, name = nil)
@partial_path
=
"
#{
@collection
}
/
#{
@element
}
"
.
freeze
@param_key
=
(
namespace
?
_singularize
(
@unnamespaced
)
:
@singular
).
freeze
@route_key
=
(
namespace
?
ActiveSupport
::
Inflector
.
pluralize
(
@param_key
)
:
@plural
).
freeze
@i18n_key
=
self
.
underscore
.
t
r
(
'/'
,
'.'
).
t
o_sym
@i18n_key
=
self
.
underscore
.
to_sym
end
# Transform the model name into a more humane format, using I18n. By default,
...
...
@@ -35,9 +35,8 @@ def human(options={})
@klass
.
respond_to?
(
:i18n_scope
)
defaults
=
@klass
.
lookup_ancestors
.
map
do
|
klass
|
[
klass
.
model_name
.
i18n_key
,
klass
.
model_name
.
i18n_key
.
to_s
.
tr
(
'.'
,
'/'
).
to_sym
]
end
.
flatten
klass
.
model_name
.
i18n_key
end
defaults
<<
options
[
:default
]
if
options
[
:default
]
defaults
<<
@human
...
...
activemodel/lib/active_model/translation.rb
浏览文件 @
410a4286
...
...
@@ -44,9 +44,8 @@ def lookup_ancestors
# Specify +options+ with additional translating options.
def
human_attribute_name
(
attribute
,
options
=
{})
defaults
=
lookup_ancestors
.
map
do
|
klass
|
[
:"
#{
self
.
i18n_scope
}
.attributes.
#{
klass
.
model_name
.
i18n_key
}
.
#{
attribute
}
"
,
:"
#{
self
.
i18n_scope
}
.attributes.
#{
klass
.
model_name
.
i18n_key
.
to_s
.
tr
(
'.'
,
'/'
)
}
.
#{
attribute
}
"
]
end
.
flatten
:"
#{
self
.
i18n_scope
}
.attributes.
#{
klass
.
model_name
.
i18n_key
}
.
#{
attribute
}
"
end
defaults
<<
:"attributes.
#{
attribute
}
"
defaults
<<
options
.
delete
(
:default
)
if
options
[
:default
]
...
...
activemodel/test/cases/translation_test.rb
浏览文件 @
410a4286
...
...
@@ -76,15 +76,5 @@ def test_human_does_not_modify_options
Person
.
model_name
.
human
(
options
)
assert_equal
({
:default
=>
'person model'
},
options
)
end
def
test_alternate_namespaced_model_attribute_translation
I18n
.
backend
.
store_translations
'en'
,
:activemodel
=>
{
:attributes
=>
{
:person
=>
{
:gender
=>
{
:attribute
=>
'person gender attribute'
}}}}
assert_equal
'person gender attribute'
,
Person
::
Gender
.
human_attribute_name
(
'attribute'
)
end
def
test_alternate_namespaced_model_translation
I18n
.
backend
.
store_translations
'en'
,
:activemodel
=>
{
:models
=>
{
:person
=>
{
:gender
=>
'person gender model'
}}}
assert_equal
'person gender model'
,
Person
::
Gender
.
model_name
.
human
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录