Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a0fa45c0
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,发现更多精彩内容 >>
提交
a0fa45c0
编写于
8月 10, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21124 from kirs/feature/reload-i18n
Reload I18n.load_path in development
上级
67b07f80
f50e90a1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
114 addition
and
3 deletion
+114
-3
activesupport/lib/active_support/i18n_railtie.rb
activesupport/lib/active_support/i18n_railtie.rb
+17
-2
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+1
-1
railties/lib/rails/paths.rb
railties/lib/rails/paths.rb
+10
-0
railties/test/application/initializers/i18n_test.rb
railties/test/application/initializers/i18n_test.rb
+73
-0
railties/test/paths_test.rb
railties/test/paths_test.rb
+13
-0
未找到文件。
activesupport/lib/active_support/i18n_railtie.rb
浏览文件 @
a0fa45c0
...
@@ -37,10 +37,12 @@ def self.initialize_i18n(app)
...
@@ -37,10 +37,12 @@ def self.initialize_i18n(app)
enforce_available_locales
=
I18n
.
enforce_available_locales
if
enforce_available_locales
.
nil?
enforce_available_locales
=
I18n
.
enforce_available_locales
if
enforce_available_locales
.
nil?
I18n
.
enforce_available_locales
=
false
I18n
.
enforce_available_locales
=
false
reloadable_paths
=
[]
app
.
config
.
i18n
.
each
do
|
setting
,
value
|
app
.
config
.
i18n
.
each
do
|
setting
,
value
|
case
setting
case
setting
when
:railties_load_path
when
:railties_load_path
app
.
config
.
i18n
.
load_path
.
unshift
(
*
value
)
reloadable_paths
=
value
app
.
config
.
i18n
.
load_path
.
unshift
(
*
value
.
map
(
&
:existent
).
flatten
)
when
:load_path
when
:load_path
I18n
.
load_path
+=
value
I18n
.
load_path
+=
value
else
else
...
@@ -53,7 +55,14 @@ def self.initialize_i18n(app)
...
@@ -53,7 +55,14 @@ def self.initialize_i18n(app)
# Restore available locales check so it will take place from now on.
# Restore available locales check so it will take place from now on.
I18n
.
enforce_available_locales
=
enforce_available_locales
I18n
.
enforce_available_locales
=
enforce_available_locales
reloader
=
ActiveSupport
::
FileUpdateChecker
.
new
(
I18n
.
load_path
.
dup
){
I18n
.
reload!
}
directories
=
watched_dirs_with_extensions
(
reloadable_paths
)
reloader
=
ActiveSupport
::
FileUpdateChecker
.
new
(
I18n
.
load_path
.
dup
,
directories
)
do
I18n
.
load_path
.
keep_if
{
|
p
|
File
.
exist?
(
p
)
}
I18n
.
load_path
|=
reloadable_paths
.
map
(
&
:existent
).
flatten
I18n
.
reload!
end
app
.
reloaders
<<
reloader
app
.
reloaders
<<
reloader
ActionDispatch
::
Reloader
.
to_prepare
do
ActionDispatch
::
Reloader
.
to_prepare
do
reloader
.
execute_if_updated
reloader
.
execute_if_updated
...
@@ -96,5 +105,11 @@ def self.validate_fallbacks(fallbacks)
...
@@ -96,5 +105,11 @@ def self.validate_fallbacks(fallbacks)
raise
"Unexpected fallback type
#{
fallbacks
.
inspect
}
"
raise
"Unexpected fallback type
#{
fallbacks
.
inspect
}
"
end
end
end
end
def
self
.
watched_dirs_with_extensions
(
paths
)
paths
.
each_with_object
({})
do
|
path
,
result
|
result
[
path
.
absolute_current
]
=
path
.
extensions
end
end
end
end
end
end
railties/lib/rails/engine.rb
浏览文件 @
a0fa45c0
...
@@ -587,7 +587,7 @@ def load_seed
...
@@ -587,7 +587,7 @@ def load_seed
# I18n load paths are a special case since the ones added
# I18n load paths are a special case since the ones added
# later have higher priority.
# later have higher priority.
initializer
:add_locales
do
initializer
:add_locales
do
config
.
i18n
.
railties_load_path
.
concat
(
paths
[
"config/locales"
].
existent
)
config
.
i18n
.
railties_load_path
<<
paths
[
"config/locales"
]
end
end
initializer
:add_view_paths
do
initializer
:add_view_paths
do
...
...
railties/lib/rails/paths.rb
浏览文件 @
a0fa45c0
...
@@ -123,6 +123,11 @@ def initialize(root, current, paths, options = {})
...
@@ -123,6 +123,11 @@ def initialize(root, current, paths, options = {})
options
[
:load_path
]
?
load_path!
:
skip_load_path!
options
[
:load_path
]
?
load_path!
:
skip_load_path!
end
end
# :nodoc:
def
absolute_current
File
.
expand_path
(
@current
,
@root
.
path
)
end
def
children
def
children
keys
=
@root
.
keys
.
find_all
{
|
k
|
keys
=
@root
.
keys
.
find_all
{
|
k
|
k
.
start_with?
(
@current
)
&&
k
!=
@current
k
.
start_with?
(
@current
)
&&
k
!=
@current
...
@@ -175,6 +180,11 @@ def to_ary
...
@@ -175,6 +180,11 @@ def to_ary
@paths
@paths
end
end
# :nodoc:
def
extensions
$1
.
split
(
','
)
if
@glob
=~
/\{([\S]+)\}/
end
# Expands all paths against the root and return all unique values.
# Expands all paths against the root and return all unique values.
def
expanded
def
expanded
raise
"You need to set a path root"
unless
@root
.
path
raise
"You need to set a path root"
unless
@root
.
path
...
...
railties/test/application/initializers/i18n_test.rb
浏览文件 @
a0fa45c0
...
@@ -132,6 +132,79 @@ class Foo < ActiveRecord::Base
...
@@ -132,6 +132,79 @@ class Foo < ActiveRecord::Base
assert_equal
"2"
,
last_response
.
body
assert_equal
"2"
,
last_response
.
body
end
end
test
"new locale files are loaded"
do
add_to_config
<<-
RUBY
config.cache_classes = false
RUBY
app_file
"config/locales/en.yml"
,
<<-
YAML
en:
foo: "1"
YAML
app_file
'config/routes.rb'
,
<<-
RUBY
Rails.application.routes.draw do
get '/i18n', :to => lambda { |env| [200, {}, [I18n.t(:foo)]] }
end
RUBY
require
'rack/test'
extend
Rack
::
Test
::
Methods
load_app
get
"/i18n"
assert_equal
"1"
,
last_response
.
body
# Wait a full second so we have time for changes to propagate
sleep
(
1
)
remove_file
"config/locales/en.yml"
app_file
"config/locales/custom.en.yml"
,
<<-
YAML
en:
foo: "2"
YAML
get
"/i18n"
assert_equal
"2"
,
last_response
.
body
end
test
"I18n.load_path is reloaded"
do
add_to_config
<<-
RUBY
config.cache_classes = false
RUBY
app_file
"config/locales/en.yml"
,
<<-
YAML
en:
foo: "1"
YAML
app_file
'config/routes.rb'
,
<<-
RUBY
Rails.application.routes.draw do
get '/i18n', :to => lambda { |env| [200, {}, [I18n.load_path.inspect]] }
end
RUBY
require
'rack/test'
extend
Rack
::
Test
::
Methods
load_app
get
"/i18n"
assert_match
"en.yml"
,
last_response
.
body
# Wait a full second so we have time for changes to propagate
sleep
(
1
)
app_file
"config/locales/fr.yml"
,
<<-
YAML
fr:
foo: "2"
YAML
get
"/i18n"
assert_match
"fr.yml"
,
last_response
.
body
assert_match
"en.yml"
,
last_response
.
body
end
# Fallbacks
# Fallbacks
test
"not using config.i18n.fallbacks does not initialize I18n.fallbacks"
do
test
"not using config.i18n.fallbacks does not initialize I18n.fallbacks"
do
I18n
.
backend
=
Class
.
new
(
I18n
::
Backend
::
Simple
).
new
I18n
.
backend
=
Class
.
new
(
I18n
::
Backend
::
Simple
).
new
...
...
railties/test/paths_test.rb
浏览文件 @
a0fa45c0
...
@@ -62,6 +62,13 @@ def setup
...
@@ -62,6 +62,13 @@ def setup
assert_equal
[
"/foo/bar/baz"
],
@root
[
"app/models"
].
to_a
assert_equal
[
"/foo/bar/baz"
],
@root
[
"app/models"
].
to_a
end
end
test
"absolute current path"
do
@root
.
add
"config"
@root
.
add
"config/locales"
assert_equal
"/foo/bar/config/locales"
,
@root
[
"config/locales"
].
absolute_current
end
test
"adding multiple physical paths as an array"
do
test
"adding multiple physical paths as an array"
do
@root
.
add
"app"
,
with:
[
"/app"
,
"/app2"
]
@root
.
add
"app"
,
with:
[
"/app"
,
"/app2"
]
assert_equal
[
"/app"
,
"/app2"
],
@root
[
"app"
].
to_a
assert_equal
[
"/app"
,
"/app2"
],
@root
[
"app"
].
to_a
...
@@ -215,6 +222,12 @@ def setup
...
@@ -215,6 +222,12 @@ def setup
assert_equal
"*.rb"
,
@root
[
"app"
].
glob
assert_equal
"*.rb"
,
@root
[
"app"
].
glob
end
end
test
"it should be possible to get extensions by glob"
do
@root
[
"app"
]
=
"/app"
@root
[
"app"
].
glob
=
"*.{rb,yml}"
assert_equal
[
"rb"
,
"yml"
],
@root
[
"app"
].
extensions
end
test
"it should be possible to override a path's default glob without assignment"
do
test
"it should be possible to override a path's default glob without assignment"
do
@root
.
add
"app"
,
with:
"/app"
,
glob:
"*.rb"
@root
.
add
"app"
,
with:
"/app"
,
glob:
"*.rb"
assert_equal
"*.rb"
,
@root
[
"app"
].
glob
assert_equal
"*.rb"
,
@root
[
"app"
].
glob
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录