January 8, 2008 | rails
If you're using globalize to translate or localize your rails site you'll have noticed that your log quickly fills up with messages like the following (especially in the devlopment environment):
[sourcecode language='sql']
Globalize::Language Columns (0.000516) SHOW FIELDS FROM globalize_languages
Globalize::Language Load (0.000202) SELECT * FROM globalize_languages WHERE (globalize_languages.`rfc_3066` = 'en-us') LIMIT 1
Globalize::Language Load (0.000131) SELECT * FROM globalize_languages WHERE (globalize_languages.`iso_639_1` = 'en') LIMIT 1
Globalize::Country Columns (0.000383) SHOW FIELDS FROM globalize_countries
Globalize::Country Load (0.000152) SELECT * FROM globalize_countries WHERE (globalize_countries.`code` = 'us') LIMIT 1
[/sourcecode]
We do a lot of view text translation in our templates, a lot like the following:
[sourcecode lang='ruby']
[/sourcecode]
And over time, you'll end up with tons of .translate calls, each one causing extra log cruft.
If you're developing a feature that doesn't require your localization to be enabled, and you want to skim down the globalize log cruft from this type of translation, here's a simple fix to softly disable the extensions to String
Edit vendor/plugins/globalize/lib/gloablize/localization/core_ext.rb and make it look like the following:
[sourcecode lang='ruby']
def translate(default = nil, arg = nil, namespace = nil)
# Locale.translate(self, default, arg, namespace)
self.to_s
end
[/sourcecode]
You can switch the comment from line #2 to line#3 to re-enable translate easily.
Note: make sure to restart your server to ensure this takes effect.
No Comments »