diff options
| author | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
| commit | 36a2f1f3c085dd81171cf7d8220770d4ff921ab3 (patch) | |
| tree | 5ded15331b192bf428af4c94d46d1abb28ef0690 /vendor/plugins/globalize2/lib/globalize/i18n | |
| parent | ce9645d0092d42c7bf8781378181ffbd4ff3d088 (diff) | |
added globalize2 plugin as well as some modifications
which use the new translation facilities.
backend mostly.
Diffstat (limited to 'vendor/plugins/globalize2/lib/globalize/i18n')
| -rw-r--r-- | vendor/plugins/globalize2/lib/globalize/i18n/missing_translations_log_handler.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/plugins/globalize2/lib/globalize/i18n/missing_translations_log_handler.rb b/vendor/plugins/globalize2/lib/globalize/i18n/missing_translations_log_handler.rb new file mode 100644 index 00000000..3f06ac24 --- /dev/null +++ b/vendor/plugins/globalize2/lib/globalize/i18n/missing_translations_log_handler.rb | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | # A simple exception handler that behaves like the default exception handler | ||
| 2 | # but additionally logs missing translations to a given log. | ||
| 3 | # | ||
| 4 | # Useful for identifying missing translations during testing. | ||
| 5 | # | ||
| 6 | # E.g. | ||
| 7 | # | ||
| 8 | # require 'globalize/i18n/missing_translations_log_handler | ||
| 9 | # I18n.missing_translations_logger = RAILS_DEFAULT_LOGGER | ||
| 10 | # I18n.exception_handler = :missing_translations_log_handler | ||
| 11 | # | ||
| 12 | # To set up a different log file: | ||
| 13 | # | ||
| 14 | # logger = Logger.new("#{RAILS_ROOT}/log/missing_translations.log") | ||
| 15 | # I18n.missing_translations_logger = logger | ||
| 16 | |||
| 17 | module I18n | ||
| 18 | @@missing_translations_logger = nil | ||
| 19 | |||
| 20 | class << self | ||
| 21 | def missing_translations_logger | ||
| 22 | @@missing_translations_logger ||= begin | ||
| 23 | require 'logger' unless defined?(Logger) | ||
| 24 | Logger.new(STDOUT) | ||
| 25 | end | ||
| 26 | end | ||
| 27 | |||
| 28 | def missing_translations_logger=(logger) | ||
| 29 | @@missing_translations_logger = logger | ||
| 30 | end | ||
| 31 | |||
| 32 | def missing_translations_log_handler(exception, locale, key, options) | ||
| 33 | if MissingTranslationData === exception | ||
| 34 | missing_translations_logger.warn(exception.message) | ||
| 35 | return exception.message | ||
| 36 | else | ||
| 37 | raise exception | ||
| 38 | end | ||
| 39 | end | ||
| 40 | end | ||
| 41 | end \ No newline at end of file | ||
