globalize 3.1.0 → 4.0.0.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +0,0 @@
1
- # heavily based on Masao Mutoh's gettext String interpolation extension
2
- # http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
3
-
4
- module I18n
5
- INTERPOLATION_PATTERN = Regexp.union(
6
- /%%/,
7
- /%\{(\w+)\}/, # matches placeholders like "%{foo}"
8
- /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
9
- )
10
-
11
- class << self
12
- # Return String or raises MissingInterpolationArgument exception.
13
- # Missing argument's logic is handled by I18n.config.missing_interpolation_argument_handler.
14
- def interpolate(string, values)
15
- raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ Backend::Base::RESERVED_KEYS_PATTERN
16
- raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash)
17
- interpolate_hash(string, values)
18
- end
19
-
20
- def interpolate_hash(string, values)
21
- string.gsub(INTERPOLATION_PATTERN) do |match|
22
- if match == '%%'
23
- '%'
24
- else
25
- key = ($1 || $2).to_sym
26
- value = if values.key?(key)
27
- values[key]
28
- else
29
- raise(MissingInterpolationArgument.new(values, string))
30
- end
31
- value = value.call(values) if value.respond_to?(:call)
32
- $3 ? sprintf("%#{$3}", value) : value
33
- end
34
- end
35
- end
36
- end
37
- end