From a3b7fa78bfdc33e45e39c095b67e02d50a2c7bea Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 15 Sep 2008 10:26:50 +0200 Subject: I18n: Introduce I18n.load_path in favor of I18n.load_translations and change Simple backend to load translations lazily. [#1048 state:resolved] Signed-off-by: Pratik Naik --- .../vendor/i18n-0.0.1/i18n/backend/simple.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/vendor/i18n-0.0.1/i18n') diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb index ff15d83f4e..2dbaf8a405 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb @@ -1,4 +1,4 @@ -require 'strscan' +require 'yaml' module I18n module Backend @@ -59,7 +59,16 @@ module I18n object.strftime(format) end + def initialized? + @initialized ||= false + end + protected + + def init_translations + load_translations(*I18n.load_path) + @initialized = true + end def translations @translations ||= {} @@ -72,6 +81,7 @@ module I18n # %w(currency format). def lookup(locale, key, scope = []) return unless key + init_translations unless initialized? keys = I18n.send :normalize_translation_keys, locale, key, scope keys.inject(translations){|result, k| result[k.to_sym] or return nil } end @@ -94,7 +104,7 @@ module I18n rescue MissingTranslationData nil end - + # Picks a translation from an array according to English pluralization # rules. It will pick the first translation if count is not equal to 1 # and the second translation if it is equal to 1. Other backends can -- cgit v1.2.3