diff options
| author | hukl <contact@smyck.org> | 2010-01-14 22:21:43 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2010-01-14 22:21:43 +0100 |
| commit | 57d1382013c85a7b11ac8ce5e683f6006b12b328 (patch) | |
| tree | 19646c4fa5952fa1cf0a2c874952affa346373f1 /vendor/plugins/globalize2/lib/globalize/backend/static.rb | |
| parent | 1b86bf5f2e35d1820bfa32d979bcc2d9ff9a9a8e (diff) | |
Updated globalize2 to latest version. Modified existing code accoringly
Diffstat (limited to 'vendor/plugins/globalize2/lib/globalize/backend/static.rb')
| -rw-r--r-- | vendor/plugins/globalize2/lib/globalize/backend/static.rb | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/vendor/plugins/globalize2/lib/globalize/backend/static.rb b/vendor/plugins/globalize2/lib/globalize/backend/static.rb deleted file mode 100644 index fb9e1fe2..00000000 --- a/vendor/plugins/globalize2/lib/globalize/backend/static.rb +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | require 'globalize/backend/pluralizing' | ||
| 2 | require 'globalize/locale/fallbacks' | ||
| 3 | require 'globalize/translation' | ||
| 4 | |||
| 5 | module Globalize | ||
| 6 | module Backend | ||
| 7 | class Static < Pluralizing | ||
| 8 | def initialize(*args) | ||
| 9 | add(*args) unless args.empty? | ||
| 10 | end | ||
| 11 | |||
| 12 | def translate(locale, key, options = {}) | ||
| 13 | result, default, fallback = nil, options.delete(:default), nil | ||
| 14 | I18n.fallbacks[locale].each do |fallback| | ||
| 15 | begin | ||
| 16 | result = super(fallback, key, options) and break | ||
| 17 | rescue I18n::MissingTranslationData | ||
| 18 | end | ||
| 19 | end | ||
| 20 | result ||= default locale, default, options | ||
| 21 | |||
| 22 | attrs = {:requested_locale => locale, :locale => fallback, :key => key, :options => options} | ||
| 23 | translation(result, attrs) || raise(I18n::MissingTranslationData.new(locale, key, options)) | ||
| 24 | end | ||
| 25 | |||
| 26 | protected | ||
| 27 | |||
| 28 | alias :orig_interpolate :interpolate unless method_defined? :orig_interpolate | ||
| 29 | def interpolate(locale, string, values = {}) | ||
| 30 | result = orig_interpolate(locale, string, values) | ||
| 31 | translation = translation(string) | ||
| 32 | translation.nil? ? result : translation.replace(result) | ||
| 33 | end | ||
| 34 | |||
| 35 | def translation(result, meta = nil) | ||
| 36 | return unless result | ||
| 37 | |||
| 38 | case result | ||
| 39 | when Numeric | ||
| 40 | result | ||
| 41 | when String | ||
| 42 | result = Translation::Static.new(result) unless result.is_a? Translation::Static | ||
| 43 | result.set_meta meta | ||
| 44 | result | ||
| 45 | when Hash | ||
| 46 | Hash[*result.map do |key, value| | ||
| 47 | [key, translation(value, meta)] | ||
| 48 | end.flatten] | ||
| 49 | when Array | ||
| 50 | result.map do |value| | ||
| 51 | translation(value, meta) | ||
| 52 | end | ||
| 53 | else | ||
| 54 | result | ||
| 55 | # raise "unexpected translation type: #{result.inspect}" | ||
| 56 | end | ||
| 57 | end | ||
| 58 | end | ||
| 59 | end | ||
| 60 | end \ No newline at end of file | ||
