From cf4846c6ae991143afaef987a63c3ad9a3a2546b Mon Sep 17 00:00:00 2001 From: Antonio Tapiador del Dujo Date: Tue, 24 Mar 2009 14:49:47 +0100 Subject: 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 --- railties/lib/rails/plugin.rb | 12 ++++++++++++ railties/lib/rails/plugin/loader.rb | 7 +++++++ 2 files changed, 19 insertions(+) (limited to 'railties/lib/rails') 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 -- cgit v1.2.3 From 57f7308da4dff57639f8e67a830baab358aaa5df Mon Sep 17 00:00:00 2001 From: Jay Pignata Date: Sun, 30 Aug 2009 19:51:13 -0400 Subject: Changing plugin loader to use blocks instead of Symbol#to_proc to ensure tests run without activesupport [#3118 state:committed] Signed-off-by: Jeremy Kemper --- railties/lib/rails/plugin/loader.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 9e2c3c7b03..0d16cbd7c3 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -86,8 +86,10 @@ module Rails end def add_engine_locales + localized_engines = engines.select { |engine| engine.localized? } + # 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 + locale_files = localized_engines.collect { |engine| engine.locale_files }.reverse.flatten I18n.load_path += locale_files - I18n.load_path end -- cgit v1.2.3 From 14870257c12925241de9756a585e716321151c67 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 31 Aug 2009 21:09:16 -0500 Subject: Initializer middleware helper needs to require actioncontroller --- railties/lib/rails/configuration.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 5cc4f80684..2b362a9c50 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -109,6 +109,7 @@ module Rails # TODO: Fix this when there is an application object def middleware + require 'action_controller' ActionController::Dispatcher.middleware end -- cgit v1.2.3