aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-09-15 17:09:05 +0100
committerMark Longair <mhl@pobox.com>2013-09-16 11:11:03 +0100
commit88f5008401ac0456306bf957aa0df325684e51cf (patch)
tree2f1200806a48b0bbbc4bc935bb0ff685c5b7e4ba
parentfccffdf4f70d5f9fa12ad6e75187be1728026823 (diff)
Only set up FastGettext on initialization, even in development modeimprove-development-performance
Even on a very fast computer, there is a significant delay (a couple of seconds) in processing every request in development mode. This is because the configuration of FastGettext's paths for finding translations is done in a block passed to Rails.configuration.to_prepare, which causes the block to be run before every request by the Rails Reloader in developmetn mode. It seems to be work fine just running the FastGettext calls on initialization in development mode, however - customizations in the theme's locale-theme directory still have effect in development mode even after the reloader has reloaded classes before handling subsequent requests. So, I think this change should be safe. This commit introduces that change, having the effect that development mode is much more responsive.
-rw-r--r--lib/alavetelitheme.rb13
-rw-r--r--lib/gettext_setup.rb13
2 files changed, 11 insertions, 15 deletions
diff --git a/lib/alavetelitheme.rb b/lib/alavetelitheme.rb
index 77b20de..2930ba6 100644
--- a/lib/alavetelitheme.rb
+++ b/lib/alavetelitheme.rb
@@ -24,11 +24,20 @@ end
# Monkey patch app code
for patch in ['controller_patches.rb',
'model_patches.rb',
- 'patch_mailer_paths.rb',
- 'gettext_setup.rb']
+ 'patch_mailer_paths.rb']
require File.expand_path "../#{patch}", __FILE__
end
# Note you should rename the file at "config/custom-routes.rb" to
# something unique (e.g. yourtheme-custom-routes.rb":
$alaveteli_route_extensions << 'custom-routes.rb'
+
+# Tell FastGettext about the theme's translations: look in the theme's
+# locale-theme directory for a translation in the first place, and if
+# it isn't found, look in the Alaveteli locale directory next:
+repos = [
+ FastGettext::TranslationRepository.build('app', :path=>File.join(File.dirname(__FILE__), '..', 'locale-theme'), :type => :po),
+ FastGettext::TranslationRepository.build('app', :path=>'locale', :type => :po)
+]
+FastGettext.add_text_domain 'app', :type=>:chain, :chain=>repos
+FastGettext.default_text_domain = 'app'
diff --git a/lib/gettext_setup.rb b/lib/gettext_setup.rb
deleted file mode 100644
index 879bf57..0000000
--- a/lib/gettext_setup.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# Add a callback - to be executed before each request in development,
-# and at startup in production - to plug in theme locale strings.
-Rails.configuration.to_prepare do
- repos = [
- FastGettext::TranslationRepository.build('app', :path=>File.join(File.dirname(__FILE__), '..', 'locale-theme'), :type => :po),
- FastGettext::TranslationRepository.build('app', :path=>'locale', :type => :po)
- ]
- FastGettext.add_text_domain 'app', :type=>:chain, :chain=>repos
- FastGettext.default_text_domain = 'app'
-end
-
-
-