Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c50de962
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,发现更多精彩内容 >>
提交
c50de962
编写于
10月 19, 2012
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7997 from steveklabnik/issue_733
Add i18n scope to disance_of_time_in_words.
上级
86df55e7
e22e7854
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
11 deletion
+24
-11
actionpack/lib/action_view/helpers/date_helper.rb
actionpack/lib/action_view/helpers/date_helper.rb
+5
-1
actionpack/test/template/date_helper_i18n_test.rb
actionpack/test/template/date_helper_i18n_test.rb
+19
-10
未找到文件。
actionpack/lib/action_view/helpers/date_helper.rb
浏览文件 @
c50de962
...
...
@@ -73,13 +73,17 @@ def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options
options
[
:include_seconds
]
||=
!!
include_seconds_or_options
end
options
=
{
scope: :'datetime.distance_in_words'
}.
merge!
(
options
)
from_time
=
from_time
.
to_time
if
from_time
.
respond_to?
(
:to_time
)
to_time
=
to_time
.
to_time
if
to_time
.
respond_to?
(
:to_time
)
from_time
,
to_time
=
to_time
,
from_time
if
from_time
>
to_time
distance_in_minutes
=
((
to_time
-
from_time
)
/
60.0
).
round
distance_in_seconds
=
(
to_time
-
from_time
).
round
I18n
.
with_options
:locale
=>
options
[
:locale
],
:scope
=>
:'datetime.distance_in_words'
do
|
locale
|
I18n
.
with_options
:locale
=>
options
[
:locale
],
:scope
=>
options
[
:scope
]
do
|
locale
|
case
distance_in_minutes
when
0
..
1
return
distance_in_minutes
==
0
?
...
...
actionpack/test/template/date_helper_i18n_test.rb
浏览文件 @
c50de962
...
...
@@ -36,16 +36,13 @@ def test_distance_of_time_in_words_calls_i18n
end
end
def
assert_distance_of_time_in_words_translates_key
(
passed
,
expected
)
diff
,
passed_options
=
*
passed
key
,
count
=
*
expected
to
=
@from
+
diff
options
=
{
:locale
=>
'en'
,
:scope
=>
:'datetime.distance_in_words'
}
options
[
:count
]
=
count
if
count
I18n
.
expects
(
:t
).
with
(
key
,
options
)
distance_of_time_in_words
(
@from
,
to
,
passed_options
.
merge
(
:locale
=>
'en'
))
def
test_distance_of_time_in_words_calls_i18n_with_custom_scope
{
[
30
.
days
,
{
scope: :'datetime.distance_in_words_ago'
}]
=>
[
:'about_x_months'
,
1
],
[
60
.
days
,
{
scope: :'datetime.distance_in_words_ago'
}]
=>
[
:'x_months'
,
2
],
}.
each
do
|
passed
,
expected
|
assert_distance_of_time_in_words_translates_key
(
passed
,
expected
,
scope: :'datetime.distance_in_words_ago'
)
end
end
def
test_time_ago_in_words_passes_locale
...
...
@@ -74,6 +71,18 @@ def test_distance_of_time_pluralizations
assert_equal
expected
,
I18n
.
t
(
key
,
:count
=>
count
,
:scope
=>
'datetime.distance_in_words'
)
end
end
def
assert_distance_of_time_in_words_translates_key
(
passed
,
expected
,
expected_options
=
{})
diff
,
passed_options
=
*
passed
key
,
count
=
*
expected
to
=
@from
+
diff
options
=
{
locale:
'en'
,
scope: :'datetime.distance_in_words'
}.
merge!
(
expected_options
)
options
[
:count
]
=
count
if
count
I18n
.
expects
(
:t
).
with
(
key
,
options
)
distance_of_time_in_words
(
@from
,
to
,
passed_options
.
merge
(
locale:
'en'
))
end
end
class
DateHelperSelectTagsI18nTests
<
ActiveSupport
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录