activesupport 2.3.6.pre → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (123) hide show
  1. data/CHANGELOG +9 -5
  2. data/lib/active_support/buffered_logger.rb +1 -1
  3. data/lib/active_support/cache/memory_store.rb +7 -1
  4. data/lib/active_support/cache/strategy/local_cache.rb +1 -1
  5. data/lib/active_support/core_ext/array/conversions.rb +1 -1
  6. data/lib/active_support/core_ext/array/random_access.rb +11 -1
  7. data/lib/active_support/core_ext/class/attribute_accessors.rb +35 -28
  8. data/lib/active_support/core_ext/date/calculations.rb +14 -4
  9. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  10. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  11. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  12. data/lib/active_support/core_ext/module/attribute_accessors.rb +33 -26
  13. data/lib/active_support/core_ext/module/synchronization.rb +1 -1
  14. data/lib/active_support/core_ext/object/blank.rb +20 -2
  15. data/lib/active_support/core_ext/string/output_safety.rb +10 -2
  16. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -4
  17. data/lib/active_support/core_ext/time.rb +8 -4
  18. data/lib/active_support/core_ext/time/calculations.rb +11 -2
  19. data/lib/active_support/deprecation.rb +3 -2
  20. data/lib/active_support/inflections.rb +1 -1
  21. data/lib/active_support/inflector.rb +4 -1
  22. data/lib/active_support/json/backends/yaml.rb +10 -7
  23. data/lib/active_support/json/decoding.rb +1 -1
  24. data/lib/active_support/memoizable.rb +1 -1
  25. data/lib/active_support/multibyte/unicode_database.rb +2 -2
  26. data/lib/active_support/multibyte/utils.rb +6 -7
  27. data/lib/active_support/ordered_hash.rb +24 -30
  28. data/lib/active_support/testing/assertions.rb +14 -0
  29. data/lib/active_support/values/time_zone.rb +84 -76
  30. data/lib/active_support/vendor.rb +1 -1
  31. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n.rb +92 -34
  32. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend.rb +2 -0
  33. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record.rb +9 -13
  34. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/missing.rb +1 -1
  35. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/store_procs.rb +6 -6
  36. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/translation.rb +14 -9
  37. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/base.rb +23 -16
  38. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cache.rb +1 -0
  39. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cascade.rb +22 -8
  40. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/chain.rb +2 -1
  41. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/cldr.rb +100 -0
  42. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fallbacks.rb +20 -3
  43. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fast.rb +14 -13
  44. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/gettext.rb +1 -1
  45. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/helpers.rb +4 -16
  46. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/interpolation_compiler.rb +2 -2
  47. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb +34 -0
  48. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/metadata.rb +0 -0
  49. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/pluralization.rb +1 -1
  50. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/simple.rb +0 -0
  51. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb +8 -0
  52. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb +8 -0
  53. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/object/meta_class.rb +0 -0
  54. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/string/interpolate.rb +1 -1
  55. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/exceptions.rb +1 -1
  56. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/gettext.rb +0 -0
  57. data/lib/active_support/vendor/{i18n-0.3.3/vendor → i18n-0.3.7/i18n/gettext}/po_parser.rb +0 -0
  58. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers.rb +0 -0
  59. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers/gettext.rb +3 -2
  60. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale.rb +0 -0
  61. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/fallbacks.rb +0 -0
  62. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag.rb +0 -0
  63. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/parents.rb +0 -0
  64. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/rfc4646.rb +0 -0
  65. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/simple.rb +0 -0
  66. data/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb +3 -0
  67. metadata +42 -96
  68. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +0 -76
  69. data/lib/active_support/vendor/i18n-0.3.3/MIT-LICENSE +0 -20
  70. data/lib/active_support/vendor/i18n-0.3.3/README.textile +0 -81
  71. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +0 -24
  72. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +0 -144
  73. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +0 -71
  74. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +0 -17
  75. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +0 -165
  76. data/lib/active_support/vendor/i18n-0.3.3/init.rb +0 -1
  77. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +0 -3
  78. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +0 -8
  79. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +0 -15
  80. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +0 -40
  81. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +0 -92
  82. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +0 -55
  83. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +0 -91
  84. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +0 -90
  85. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +0 -54
  86. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +0 -84
  87. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +0 -45
  88. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +0 -35
  89. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +0 -40
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +0 -29
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +0 -40
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +0 -31
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +0 -26
  94. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +0 -33
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +0 -31
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +0 -33
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +0 -21
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +0 -60
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +0 -52
  100. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +0 -72
  101. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +0 -66
  102. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +0 -64
  103. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +0 -57
  104. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +0 -50
  105. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +0 -26
  106. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +0 -107
  107. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +0 -67
  108. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +0 -43
  109. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +0 -77
  110. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +0 -94
  111. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +0 -201
  112. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +0 -91
  113. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_exceptions_test.rb +0 -97
  114. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +0 -23
  115. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +0 -172
  116. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +0 -126
  117. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +0 -143
  118. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +0 -33
  119. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +0 -72
  120. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +0 -3
  121. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +0 -3
  122. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +0 -113
  123. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +0 -100
@@ -55,6 +55,7 @@ module I18n
55
55
  def fetch(*args, &block)
56
56
  result = I18n.cache_store.fetch(cache_key(*args), &block)
57
57
  raise result if result.is_a?(Exception)
58
+ result = result.dup if result.frozen? rescue result
58
59
  result
59
60
  rescue MissingTranslationData => exception
60
61
  I18n.cache_store.write(cache_key(*args), exception)
@@ -2,7 +2,7 @@
2
2
 
3
3
  # EXPERIMENTAL
4
4
  #
5
- # The cascade module adds the ability to do cascading lookups to backends that
5
+ # The Cascade module adds the ability to do cascading lookups to backends that
6
6
  # are compatible to the Simple backend.
7
7
  #
8
8
  # By cascading lookups we mean that for any key that can not be found the
@@ -15,7 +15,15 @@
15
15
  # then the remaining scope segment :foo will be omitted, too, and again the
16
16
  # key :baz will be looked up (now with no scope).
17
17
  #
18
- # Defaults will only kick in after the cascading lookups haven't succeeded.
18
+ # To enable a cascading lookup one passes the :cascade option:
19
+ #
20
+ # I18n.t(:'foo.bar.baz', :cascade => true)
21
+ #
22
+ # This will return the first translation found for :"foo.bar.baz", :"foo.baz"
23
+ # or :baz in this order.
24
+ #
25
+ # The cascading lookup takes precedence over resolving any given defaults.
26
+ # I.e. defaults will kick in after the cascading lookups haven't succeeded.
19
27
  #
20
28
  # This behavior is useful for libraries like ActiveRecord validations where
21
29
  # the library wants to give users a bunch of more or less fine-grained options
@@ -25,19 +33,25 @@
25
33
  # http://github.com/clemens/i18n-cascading-backend
26
34
 
27
35
  module I18n
28
- @@fallbacks = nil
29
-
30
36
  module Backend
31
37
  module Cascade
32
- def lookup(locale, key, scope = [], separator = nil)
38
+ def lookup(locale, key, scope = [], options = {})
33
39
  return unless key
34
- locale, *scope = I18n.send(:normalize_translation_keys, locale, key, scope, separator)
35
- key = scope.pop
40
+ return super unless cascade = options[:cascade]
41
+
42
+ separator = options[:separator] || I18n.default_separator
43
+ skip_root = cascade.has_key?(:skip_root) ? cascade[:skip_root] : true
44
+ step = cascade[:step]
45
+
46
+ keys = I18n.normalize_keys(nil, key, nil, separator)
47
+ offset = options[:cascade][:offset] || keys.length
48
+ scope = I18n.normalize_keys(nil, nil, scope, separator) + keys
49
+ key = scope.slice!(-offset, offset).join(separator)
36
50
 
37
51
  begin
38
52
  result = super
39
53
  return result unless result.nil?
40
- end while scope.pop
54
+ end while !scope.empty? && scope.slice!(-step, step) && (!scope.empty? || !skip_root)
41
55
  end
42
56
  end
43
57
  end
@@ -62,7 +62,8 @@ module I18n
62
62
  result = backend.localize(locale, object, format, options) and return result
63
63
  rescue MissingTranslationData
64
64
  end
65
- end and nil
65
+ end
66
+ raise(I18n::MissingTranslationData.new(locale, format, options))
66
67
  end
67
68
 
68
69
  protected
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ require 'cldr'
3
+
4
+ module I18n
5
+ module Backend
6
+ module Cldr
7
+ include ::Cldr::Format
8
+
9
+ def localize(locale, object, format = :default, options = {})
10
+ options[:as] ||= detect_type(object, options)
11
+ send(:"format_#{options[:as]}", locale, object, format, options)
12
+ end
13
+
14
+ def format_decimal(locale, object, format = :default, options = {})
15
+ formatter(locale, :decimal, format).apply(object, options)
16
+ end
17
+
18
+ def format_integer(locale, object, format = :default, options = {})
19
+ format_object(number, options.merge(:precision => 0))
20
+ end
21
+
22
+ def format_currency(locale, object, format = :default, options = {})
23
+ options.merge!(:currency => lookup_currency(locale, options[:currency], object)) if options[:currency].is_a?(Symbol)
24
+ formatter(locale, :currency, format).apply(object, options)
25
+ end
26
+
27
+ def format_percent(locale, object, format = :default, options = {})
28
+ formatter(locale, :percent, format).apply(object, options)
29
+ end
30
+
31
+ def format_date(locale, object, format = :default, options = {})
32
+ formatter(locale, :date, format).apply(object, options)
33
+ end
34
+
35
+ def format_time(locale, object, format = :default, options = {})
36
+ formatter(locale, :time, format).apply(object, options)
37
+ end
38
+
39
+ def format_datetime(locale, object, format = :default, options = {})
40
+ key = :"calendars.gregorian.formats.datetime.#{format}.pattern"
41
+ date = I18n.l(object, :format => options[:date_format] || format, :locale => locale, :as => :date)
42
+ time = I18n.l(object, :format => options[:time_format] || format, :locale => locale, :as => :time)
43
+ I18n.t(key, :date => date, :time => time, :locale => locale, :raise => true)
44
+ end
45
+
46
+ protected
47
+
48
+ def detect_type(object, options)
49
+ options.has_key?(:currency) ? :currency : case object
50
+ when ::Numeric
51
+ :decimal
52
+ when ::Date, ::DateTime, ::Time
53
+ object.class.name.downcase.to_sym
54
+ else
55
+ raise_unspecified_format_type!
56
+ end
57
+ end
58
+
59
+ def formatter(locale, type, format)
60
+ (@formatters ||= {})[:"#{locale}.#{type}.#{format}"] ||= begin
61
+ format = lookup_format(locale, type, format)
62
+ data = lookup_format_data(locale, type)
63
+ ::Cldr::Format.const_get(type.to_s.camelize).new(format, data)
64
+ end
65
+ end
66
+
67
+ def lookup_format(locale, type, format)
68
+ key = case type
69
+ when :date, :time, :datetime
70
+ :"calendars.gregorian.formats.#{type}.#{format}.pattern"
71
+ else
72
+ :"numbers.formats.#{type}.patterns.#{format || :default}"
73
+ end
74
+ I18n.t(key, :locale => locale, :raise => true)
75
+ end
76
+
77
+ def lookup_format_data(locale, type)
78
+ key = case type
79
+ when :date, :time, :datetime
80
+ :'calendars.gregorian'
81
+ else
82
+ :'numbers.symbols'
83
+ end
84
+ I18n.t(key, :locale => locale, :raise => true)
85
+ end
86
+
87
+ def lookup_currency(locale, currency, count)
88
+ I18n.t(:"currencies.#{currency}", :locale => locale, :count => count)
89
+ end
90
+
91
+ def raise_unspecified_format_type!
92
+ raise ArgumentError.new("You have to specify a format type, e.g. :as => :number.")
93
+ end
94
+
95
+ def raise_unspecified_currency!
96
+ raise ArgumentError.new("You have to specify a currency, e.g. :currency => 'EUR'.")
97
+ end
98
+ end
99
+ end
100
+ end
@@ -34,10 +34,12 @@ module I18n
34
34
  # locales it will then raise a MissingTranslationData exception as
35
35
  # usual.
36
36
  #
37
- # The default option takes precedence over fallback locales, i.e. it
38
- # will first evaluate a given default option before falling back to
39
- # another locale.
37
+ # The default option takes precedence over fallback locales
38
+ # only when it's not a String. When default contains String it
39
+ # is evaluated after fallback locales.
40
40
  def translate(locale, key, options = {})
41
+ default = extract_string_default!(options) if options[:default]
42
+
41
43
  I18n.fallbacks[locale].each do |fallback|
42
44
  begin
43
45
  result = super(fallback, key, options)
@@ -45,8 +47,23 @@ module I18n
45
47
  rescue I18n::MissingTranslationData
46
48
  end
47
49
  end
50
+
51
+ return super(locale, nil, options.merge(:default => default)) if default
48
52
  raise(I18n::MissingTranslationData.new(locale, key, options))
49
53
  end
54
+
55
+ def extract_string_default!(options)
56
+ defaults = Array(options[:default])
57
+ if index = find_first_string_default(defaults)
58
+ options[:default] = defaults[0, index]
59
+ defaults[index]
60
+ end
61
+ end
62
+
63
+ def find_first_string_default(defaults)
64
+ defaults.each_index { |ix| return ix if String === defaults[ix] }
65
+ nil
66
+ end
50
67
  end
51
68
  end
52
69
  end
@@ -12,7 +12,7 @@
12
12
  module I18n
13
13
  module Backend
14
14
  module Fast
15
- SEPARATOR_ESCAPE_CHAR = "\001"
15
+ include Links
16
16
 
17
17
  def reset_flattened_translations!
18
18
  @flattened_translations = nil
@@ -22,7 +22,7 @@ module I18n
22
22
  @flattened_translations ||= flatten_translations(translations)
23
23
  end
24
24
 
25
- def merge_translations(locale, data)
25
+ def merge_translations(locale, data, options = {})
26
26
  super
27
27
  reset_flattened_translations!
28
28
  end
@@ -33,29 +33,30 @@ module I18n
33
33
  end
34
34
 
35
35
  protected
36
- # flatten_hash({:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}})
37
- # # => {:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}, :"b.f" => {:x=>"x"}, :"b.c"=>"c", :"b.f.x"=>"x", :"b.d"=>"d"}
38
- def flatten_hash(h, nested_stack = [], flattened_h = {}, orig_h=h)
39
- wind_keys(h, nil, true)
40
- end
41
-
42
36
  def flatten_translations(translations)
43
37
  # don't flatten locale roots
44
- translations.inject({}) do |flattened_h, (locale_name, locale_translations)|
45
- flattened_h[locale_name] = flatten_hash(locale_translations)
46
- flattened_h
38
+ translations.inject({}) do |result, (locale, translations)|
39
+ result[locale] = wind_keys(translations, nil, true)
40
+ result[locale].each do |key, value|
41
+ store_link(locale, key, value) if value.is_a?(Symbol)
42
+ end
43
+ result
47
44
  end
48
45
  end
49
46
 
50
- def lookup(locale, key, scope = nil, separator = nil)
47
+ def lookup(locale, key, scope = nil, options = {})
51
48
  return unless key
52
49
  init_translations unless initialized?
53
50
 
51
+ return nil unless flattened_translations.has_key?(locale.to_sym)
52
+
53
+ separator = options[:separator]
54
54
  if separator && I18n.default_separator != separator
55
55
  key = cleanup_non_standard_separator(key, separator)
56
56
  scope = Array(scope).map{|k| cleanup_non_standard_separator(k, separator)} if scope
57
57
  end
58
-
58
+
59
+ key = resolve_link(locale, key)
59
60
  key = (Array(scope) + [key]).join(I18n.default_separator) if scope
60
61
  flattened_translations[locale.to_sym][key.to_sym]
61
62
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'i18n/gettext'
4
- require File.expand_path(File.dirname(__FILE__) + '/../../../vendor/po_parser.rb')
4
+ require 'i18n/gettext/po_parser'
5
5
 
6
6
  # Experimental support for using Gettext po files to store translations.
7
7
  #
@@ -22,16 +22,11 @@ module I18n
22
22
  key = escape_default_separator(key, separator)
23
23
  curr_key = [prev_key, key].compact.join(separator).to_sym
24
24
 
25
- if value.is_a?(Symbol)
26
- value = hash_lookup(orig_hash, value, separator) ||
27
- hash_lookup(hash, value, separator) || value
28
- end
29
-
30
25
  if value.is_a?(Hash)
31
26
  result[curr_key] = value if subtree
32
27
  wind_keys(value, separator, subtree, curr_key, result, orig_hash)
33
28
  else
34
- result[curr_key] = value
29
+ result[unescape_default_separator(curr_key)] = value
35
30
  end
36
31
  end
37
32
 
@@ -41,16 +36,9 @@ module I18n
41
36
  def escape_default_separator(key, separator=nil)
42
37
  key.to_s.tr(separator || I18n.default_separator, SEPARATOR_ESCAPE_CHAR)
43
38
  end
44
-
45
- def hash_lookup(hash, keys, separator = ".")
46
- keys.to_s.split(separator).inject(hash) do |result, key|
47
- key = key.to_sym
48
- if result.respond_to?(:has_key?) and result.has_key?(key)
49
- result[key]
50
- else
51
- return nil
52
- end
53
- end
39
+
40
+ def unescape_default_separator(key, separator=nil)
41
+ key.to_s.tr(SEPARATOR_ESCAPE_CHAR, separator || I18n.default_separator).to_sym
54
42
  end
55
43
 
56
44
  # Expand keys chained by the the given separator through nested Hashes
@@ -33,7 +33,7 @@ module I18n
33
33
  end
34
34
 
35
35
  def interpolated_str?(str)
36
- str.kind_of?(String) && str =~ INTERPOLATION_SYNTAX_PATTERN
36
+ str.kind_of?(::String) && str =~ INTERPOLATION_SYNTAX_PATTERN
37
37
  end
38
38
 
39
39
  protected
@@ -102,7 +102,7 @@ module I18n
102
102
  end
103
103
  end
104
104
 
105
- def merge_translations(locale, data)
105
+ def merge_translations(locale, data, options = {})
106
106
  compile_all_strings_in(data)
107
107
  super
108
108
  end
@@ -0,0 +1,34 @@
1
+ module I18n
2
+ module Backend
3
+ module Links
4
+ protected
5
+ def links(locale)
6
+ @links ||= {}
7
+ @links[locale.to_sym] ||= {}
8
+ end
9
+
10
+ def store_link(locale, key, link)
11
+ links(locale)[key.to_s] = link.to_s
12
+ end
13
+
14
+ def resolve_link(locale, key)
15
+ key = key.to_s
16
+ links = self.links(locale)
17
+
18
+ if links.key?(key)
19
+ links[key]
20
+ elsif link = find_link(locale, key)
21
+ store_link(locale, key, key.gsub(*link))
22
+ else
23
+ key
24
+ end
25
+ end
26
+
27
+ def find_link(locale, key)
28
+ links(locale).each do |from, to|
29
+ return [from, to] if key[0, from.length] == from
30
+ end && nil
31
+ end
32
+ end
33
+ end
34
+ end
@@ -50,7 +50,7 @@ module I18n
50
50
  end
51
51
 
52
52
  def pluralizer(locale)
53
- pluralizers[locale] ||= lookup(locale, :'i18n.plural.rule')
53
+ pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
54
54
  end
55
55
  end
56
56
  end
@@ -0,0 +1,8 @@
1
+ # from facets (http://facets.rubyforge.org)
2
+ require 'i18n/core_ext/hash/slice'
3
+
4
+ class Hash
5
+ def except(*less_keys)
6
+ slice(*keys - less_keys)
7
+ end
8
+ end unless Hash.method_defined?(:except)
@@ -0,0 +1,8 @@
1
+ # from facets (http://facets.rubyforge.org)
2
+ class Hash
3
+ def slice(*keep_keys)
4
+ h = {}
5
+ keep_keys.each { |key| h[key] = fetch(key) }
6
+ h
7
+ end
8
+ end unless Hash.new.respond_to?(:slice)
@@ -96,4 +96,4 @@ if RUBY_VERSION < '1.9'
96
96
  end
97
97
  end
98
98
  end
99
- end
99
+ end
@@ -21,7 +21,7 @@ module I18n
21
21
  attr_reader :locale, :key, :options
22
22
  def initialize(locale, key, opts = nil)
23
23
  @key, @locale, @options = key, locale, opts || {}
24
- keys = I18n.send(:normalize_translation_keys, locale, key, options[:scope])
24
+ keys = I18n.normalize_keys(locale, key, options[:scope])
25
25
  keys << 'no key' if keys.size < 2
26
26
  super "translation missing: #{keys.join(', ')}"
27
27
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'i18n/gettext'
2
3
 
3
4
  module I18n
4
5
  module Helpers
@@ -14,7 +15,7 @@ module I18n
14
15
 
15
16
  def sgettext(msgid, separator = '|')
16
17
  scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
17
- I18n.t(msgid, :scope => scope, :default => msgid)
18
+ I18n.t(msgid, :scope => scope, :default => msgid, :separator => separator)
18
19
  end
19
20
  alias s_ sgettext
20
21
 
@@ -35,7 +36,7 @@ module I18n
35
36
  def nsgettext(msgid, msgid_plural, n = 1, separator = '|')
36
37
  if msgid.is_a?(Array)
37
38
  msgid, msgid_plural, n, separator = msgid[0], msgid[1], msgid_plural, n
38
- separator = '|' unless separator.is_a?(String)
39
+ separator = '|' unless separator.is_a?(::String)
39
40
  end
40
41
 
41
42
  scope, msgid = I18n::Gettext.extract_scope(msgid, separator)