globalize 3.1.0 → 4.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -4
- data/Gemfile.lock +74 -241
- data/lib/globalize.rb +2 -5
- data/lib/globalize/active_record.rb +1 -1
- data/lib/globalize/active_record/act_macro.rb +10 -10
- data/lib/globalize/active_record/adapter.rb +14 -30
- data/lib/globalize/active_record/attributes.rb +0 -1
- data/lib/globalize/active_record/class_methods.rb +23 -52
- data/lib/globalize/active_record/instance_methods.rb +42 -74
- data/lib/globalize/active_record/migration.rb +2 -2
- data/lib/globalize/active_record/relation.rb +63 -0
- data/lib/globalize/active_record/translation.rb +0 -1
- data/lib/globalize/versioning.rb +5 -0
- data/lib/globalize/versioning/paper_trail.rb +39 -0
- data/lib/patches/active_record/relation.rb +20 -0
- metadata +56 -126
- data/CHANGELOG.md +0 -73
- data/CONTRIBUTING.md +0 -37
- data/lib/globalize/active_record/query_methods.rb +0 -13
- data/lib/globalize/version.rb +0 -3
- data/lib/patches/i18n/interpolate.rb +0 -37
@@ -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
|