diff options
author | Antonio Tapiador del Dujo <atapiador@dit.upm.es> | 2009-03-24 14:49:47 +0100 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-08-30 13:36:22 -0700 |
commit | cf4846c6ae991143afaef987a63c3ad9a3a2546b (patch) | |
tree | 79dcc28149ac974aab94b48ae429aa6071d39afb /railties/lib | |
parent | 0efedf2a30a12cdaa261556e3684c630690afe0f (diff) | |
download | rails-cf4846c6ae991143afaef987a63c3ad9a3a2546b.tar.gz rails-cf4846c6ae991143afaef987a63c3ad9a3a2546b.tar.bz2 rails-cf4846c6ae991143afaef987a63c3ad9a3a2546b.zip |
I18n support for plugins
Rails will now automatically add locale files found in any engine's locale
directory to the I18n.load_path (i.e. files that match the glob pattern
"config/locales/**/*.{rb,yml}" relative to engine directories).
[#2325 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/plugin.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/plugin/loader.rb | 7 |
2 files changed, 19 insertions, 0 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 49ec5c7fba..1c0af6411a 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -71,6 +71,10 @@ module Rails File.exist?(routing_file) end + # Returns true if there is any localization file in locale_path + def localized? + locale_files.any? + end def view_path File.join(directory, 'app', 'views') @@ -87,6 +91,14 @@ module Rails def routing_file File.join(directory, 'config', 'routes.rb') end + + def locale_path + File.join(directory, 'config', 'locales') + end + + def locale_files + Dir[ File.join(locale_path, '*.{rb,yml}') ] + end private diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 7ea9c7c0f3..9e2c3c7b03 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -73,6 +73,7 @@ module Rails def configure_engines if engines.any? add_engine_routing_configurations + add_engine_locales add_engine_controller_paths add_engine_view_paths end @@ -84,6 +85,12 @@ module Rails end end + def add_engine_locales + # reverse it such that the last engine can overwrite translations from the first, like with routes + locale_files = engines.select(&:localized?).collect(&:locale_files).reverse.flatten + I18n.load_path += locale_files - I18n.load_path + end + def add_engine_controller_paths ActionController::Routing.controller_paths += engines.collect {|engine| engine.controller_path } end |