Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a61c4dfa
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,发现更多精彩内容 >>
提交
a61c4dfa
编写于
10月 28, 2008
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Follow style conventions
上级
1df157cd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
14 deletion
+14
-14
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
...b/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
+14
-14
未找到文件。
activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
浏览文件 @
a61c4dfa
...
...
@@ -10,7 +10,7 @@ class Simple
# plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml
# for details.
def
load_translations
(
*
filenames
)
filenames
.
each
{
|
filename
|
load_file
filename
}
filenames
.
each
{
|
filename
|
load_file
(
filename
)
}
end
# Stores translations for the given locale in memory.
...
...
@@ -23,12 +23,12 @@ def store_translations(locale, data)
def
translate
(
locale
,
key
,
options
=
{})
raise
InvalidLocale
.
new
(
locale
)
if
locale
.
nil?
return
key
.
map
{
|
k
|
translate
locale
,
k
,
options
}
if
key
.
is_a?
Array
return
key
.
map
{
|
k
|
translate
(
locale
,
k
,
options
)
}
if
key
.
is_a?
Array
reserved
=
:scope
,
:default
count
,
scope
,
default
=
options
.
values_at
(
:count
,
*
reserved
)
options
.
delete
(
:default
)
values
=
options
.
reject
{
|
name
,
value
|
reserved
.
include?
name
}
values
=
options
.
reject
{
|
name
,
value
|
reserved
.
include?
(
name
)
}
entry
=
lookup
(
locale
,
key
,
scope
)
if
entry
.
nil?
...
...
@@ -37,8 +37,8 @@ def translate(locale, key, options = {})
raise
(
I18n
::
MissingTranslationData
.
new
(
locale
,
key
,
options
))
end
end
entry
=
pluralize
locale
,
entry
,
count
entry
=
interpolate
locale
,
entry
,
values
entry
=
pluralize
(
locale
,
entry
,
count
)
entry
=
interpolate
(
locale
,
entry
,
values
)
entry
end
...
...
@@ -170,21 +170,21 @@ def interpolate(locale, string, values = {})
# for all other file extensions.
def
load_file
(
filename
)
type
=
File
.
extname
(
filename
).
tr
(
'.'
,
''
).
downcase
raise
UnknownFileType
.
new
(
type
,
filename
)
unless
respond_to?
:"load_
#{
type
}
"
raise
UnknownFileType
.
new
(
type
,
filename
)
unless
respond_to?
(
:"load_
#{
type
}
"
)
data
=
send
:"load_
#{
type
}
"
,
filename
# TODO raise a meaningful exception if this does not yield a Hash
data
.
each
{
|
locale
,
d
|
merge_translations
locale
,
d
}
data
.
each
{
|
locale
,
d
|
merge_translations
(
locale
,
d
)
}
end
# Loads a plain Ruby translations file. eval'ing the file must yield
# a Hash containing translation data with locales as toplevel keys.
def
load_rb
(
filename
)
eval
IO
.
read
(
filename
),
binding
,
filename
eval
(
IO
.
read
(
filename
),
binding
,
filename
)
end
# Loads a YAML translations file. The data must have locales as
# toplevel keys.
def
load_yml
(
filename
)
YAML
::
load
IO
.
read
(
filename
)
YAML
::
load
(
IO
.
read
(
filename
)
)
end
# Deep merges the given translations hash with the existing translations
...
...
@@ -192,16 +192,16 @@ def load_yml(filename)
def
merge_translations
(
locale
,
data
)
locale
=
locale
.
to_sym
translations
[
locale
]
||=
{}
data
=
deep_symbolize_keys
data
data
=
deep_symbolize_keys
(
data
)
# deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
merger
=
proc
{
|
key
,
v1
,
v2
|
Hash
===
v1
&&
Hash
===
v2
?
v1
.
merge
(
v2
,
&
merger
)
:
v2
}
translations
[
locale
].
merge!
data
,
&
merger
merger
=
proc
{
|
key
,
v1
,
v2
|
Hash
===
v1
&&
Hash
===
v2
?
v1
.
merge
(
v2
,
&
merger
)
:
v2
}
translations
[
locale
].
merge!
(
data
,
&
merger
)
end
# Return a new hash with all keys and nested keys converted to symbols.
def
deep_symbolize_keys
(
hash
)
hash
.
inject
({})
{
|
result
,
(
key
,
value
)
|
hash
.
inject
({})
{
|
result
,
(
key
,
value
)
|
value
=
deep_symbolize_keys
(
value
)
if
value
.
is_a?
Hash
result
[(
key
.
to_sym
rescue
key
)
||
key
]
=
value
result
...
...
@@ -209,4 +209,4 @@ def deep_symbolize_keys(hash)
end
end
end
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录