Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
cddcc1da
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,发现更多精彩内容 >>
未验证
提交
cddcc1da
编写于
4月 19, 2018
作者:
R
Rafael França
提交者:
GitHub
4月 19, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #32168 from christianblais/activesupport-ordinalize-i18n
`#ordinal` and `#ordinalize` now support I18n
上级
8bdf50d5
f58e2dd0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
13 deletion
+59
-13
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+28
-0
activesupport/lib/active_support/i18n.rb
activesupport/lib/active_support/i18n.rb
+1
-0
activesupport/lib/active_support/inflector/methods.rb
activesupport/lib/active_support/inflector/methods.rb
+2
-13
activesupport/lib/active_support/locale/en.rb
activesupport/lib/active_support/locale/en.rb
+28
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
cddcc1da
...
...
@@ -28,6 +28,34 @@
*Nick Holden*
*
`ActiveSupport::Inflector#ordinal`
and
`ActiveSupport::Inflector#ordinalize`
now support
translations through I18n.
# locale/fr.rb
{
fr: {
number: {
nth: {
ordinals: lambda do |_key, number:, **_options|
if number.to_i.abs == 1
'er'
else
'e'
end
end,
ordinalized: lambda do |_key, number:, **_options|
"#{number}#{ActiveSupport::Inflector.ordinal(number)}"
end
}
}
}
}
*Christian Blais*
*
Add
`:private`
option to ActiveSupport's
`Module#delegate`
in order to delegate methods as private:
...
...
activesupport/lib/active_support/i18n.rb
浏览文件 @
cddcc1da
...
...
@@ -13,3 +13,4 @@
ActiveSupport
.
run_load_hooks
(
:i18n
)
I18n
.
load_path
<<
File
.
expand_path
(
"locale/en.yml"
,
__dir__
)
I18n
.
load_path
<<
File
.
expand_path
(
"locale/en.rb"
,
__dir__
)
activesupport/lib/active_support/inflector/methods.rb
浏览文件 @
cddcc1da
...
...
@@ -341,18 +341,7 @@ def safe_constantize(camel_cased_word)
# ordinal(-11) # => "th"
# ordinal(-1021) # => "st"
def
ordinal
(
number
)
abs_number
=
number
.
to_i
.
abs
if
(
11
..
13
).
include?
(
abs_number
%
100
)
"th"
else
case
abs_number
%
10
when
1
;
"st"
when
2
;
"nd"
when
3
;
"rd"
else
"th"
end
end
I18n
.
translate
(
"number.nth.ordinals"
,
number:
number
)
end
# Turns a number into an ordinal string used to denote the position in an
...
...
@@ -365,7 +354,7 @@ def ordinal(number)
# ordinalize(-11) # => "-11th"
# ordinalize(-1021) # => "-1021st"
def
ordinalize
(
number
)
"
#{
number
}#{
ordinal
(
number
)
}
"
I18n
.
translate
(
"number.nth.ordinalized"
,
number:
number
)
end
private
...
...
activesupport/lib/active_support/locale/en.rb
0 → 100644
浏览文件 @
cddcc1da
# frozen_string_literal: true
{
en:
{
number:
{
nth:
{
ordinals:
lambda
do
|
_key
,
number
:,
**
_options
|
abs_number
=
number
.
to_i
.
abs
if
(
11
..
13
).
cover?
(
abs_number
%
100
)
"th"
else
case
abs_number
%
10
when
1
then
"st"
when
2
then
"nd"
when
3
then
"rd"
else
"th"
end
end
end
,
ordinalized:
lambda
do
|
_key
,
number
:,
**
_options
|
"
#{
number
}#{
ActiveSupport
::
Inflector
.
ordinal
(
number
)
}
"
end
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录