i18n 0.4.0 → 1.14.4
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +0 -0
- data/README.md +127 -0
- data/lib/i18n/backend/base.rb +189 -111
- data/lib/i18n/backend/cache.rb +58 -22
- data/lib/i18n/backend/cache_file.rb +36 -0
- data/lib/i18n/backend/cascade.rb +9 -10
- data/lib/i18n/backend/chain.rb +95 -42
- data/lib/i18n/backend/fallbacks.rb +68 -22
- data/lib/i18n/backend/flatten.rb +13 -8
- data/lib/i18n/backend/gettext.rb +33 -25
- data/lib/i18n/backend/interpolation_compiler.rb +12 -14
- data/lib/i18n/backend/key_value.rb +112 -10
- data/lib/i18n/backend/lazy_loadable.rb +184 -0
- data/lib/i18n/backend/memoize.rb +13 -7
- data/lib/i18n/backend/metadata.rb +12 -6
- data/lib/i18n/backend/pluralization.rb +64 -25
- data/lib/i18n/backend/simple.rb +44 -18
- data/lib/i18n/backend/transliterator.rb +43 -33
- data/lib/i18n/backend.rb +5 -3
- data/lib/i18n/config.rb +91 -10
- data/lib/i18n/exceptions.rb +118 -22
- data/lib/i18n/gettext/helpers.rb +14 -4
- data/lib/i18n/gettext/po_parser.rb +7 -7
- data/lib/i18n/gettext.rb +6 -5
- data/lib/i18n/interpolate/ruby.rb +53 -0
- data/lib/i18n/locale/fallbacks.rb +33 -26
- data/lib/i18n/locale/tag/parents.rb +8 -8
- data/lib/i18n/locale/tag/rfc4646.rb +0 -2
- data/lib/i18n/locale/tag/simple.rb +2 -4
- data/lib/i18n/locale.rb +2 -0
- data/lib/i18n/middleware.rb +17 -0
- data/lib/i18n/tests/basics.rb +58 -0
- data/lib/i18n/tests/defaults.rb +52 -0
- data/lib/i18n/tests/interpolation.rb +167 -0
- data/lib/i18n/tests/link.rb +66 -0
- data/lib/i18n/tests/localization/date.rb +122 -0
- data/lib/i18n/tests/localization/date_time.rb +103 -0
- data/lib/i18n/tests/localization/procs.rb +118 -0
- data/lib/i18n/tests/localization/time.rb +103 -0
- data/lib/i18n/tests/localization.rb +19 -0
- data/lib/i18n/tests/lookup.rb +81 -0
- data/lib/i18n/tests/pluralization.rb +35 -0
- data/lib/i18n/tests/procs.rb +66 -0
- data/lib/i18n/tests.rb +14 -0
- data/lib/i18n/utils.rb +55 -0
- data/lib/i18n/version.rb +3 -1
- data/lib/i18n.rb +200 -87
- metadata +64 -56
- data/CHANGELOG.textile +0 -135
- data/README.textile +0 -93
- data/lib/i18n/backend/active_record/missing.rb +0 -65
- data/lib/i18n/backend/active_record/store_procs.rb +0 -38
- data/lib/i18n/backend/active_record/translation.rb +0 -93
- data/lib/i18n/backend/active_record.rb +0 -61
- data/lib/i18n/backend/cldr.rb +0 -100
- data/lib/i18n/core_ext/hash.rb +0 -29
- data/lib/i18n/core_ext/string/interpolate.rb +0 -98
@@ -1,98 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
=begin
|
4
|
-
heavily based on Masao Mutoh's gettext String interpolation extension
|
5
|
-
http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
|
6
|
-
Copyright (C) 2005-2009 Masao Mutoh
|
7
|
-
You may redistribute it and/or modify it under the same license terms as Ruby.
|
8
|
-
=end
|
9
|
-
|
10
|
-
begin
|
11
|
-
raise ArgumentError if ("a %{x}" % {:x=>'b'}) != 'a b'
|
12
|
-
rescue ArgumentError
|
13
|
-
# KeyError is raised by String#% when the string contains a named placeholder
|
14
|
-
# that is not contained in the given arguments hash. Ruby 1.9 includes and
|
15
|
-
# raises this exception natively. We define it to mimic Ruby 1.9's behaviour
|
16
|
-
# in Ruby 1.8.x
|
17
|
-
class KeyError < IndexError
|
18
|
-
def initialize(message = nil)
|
19
|
-
super(message || "key not found")
|
20
|
-
end
|
21
|
-
end unless defined?(KeyError)
|
22
|
-
|
23
|
-
# Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
|
24
|
-
#
|
25
|
-
# String#% method which accept "named argument". The translator can know
|
26
|
-
# the meaning of the msgids using "named argument" instead of %s/%d style.
|
27
|
-
class String
|
28
|
-
# For older ruby versions, such as ruby-1.8.5
|
29
|
-
alias :bytesize :size unless instance_methods.find {|m| m.to_s == 'bytesize'}
|
30
|
-
alias :interpolate_without_ruby_19_syntax :% # :nodoc:
|
31
|
-
|
32
|
-
INTERPOLATION_PATTERN = Regexp.union(
|
33
|
-
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
|
34
|
-
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
|
35
|
-
)
|
36
|
-
|
37
|
-
INTERPOLATION_PATTERN_WITH_ESCAPE = Regexp.union(
|
38
|
-
/%%/,
|
39
|
-
INTERPOLATION_PATTERN
|
40
|
-
)
|
41
|
-
|
42
|
-
# % uses self (i.e. the String) as a format specification and returns the
|
43
|
-
# result of applying it to the given arguments. In other words it interpolates
|
44
|
-
# the given arguments to the string according to the formats the string
|
45
|
-
# defines.
|
46
|
-
#
|
47
|
-
# There are three ways to use it:
|
48
|
-
#
|
49
|
-
# * Using a single argument or Array of arguments.
|
50
|
-
#
|
51
|
-
# This is the default behaviour of the String class. See Kernel#sprintf for
|
52
|
-
# more details about the format string.
|
53
|
-
#
|
54
|
-
# Example:
|
55
|
-
#
|
56
|
-
# "%d %s" % [1, "message"]
|
57
|
-
# # => "1 message"
|
58
|
-
#
|
59
|
-
# * Using a Hash as an argument and unformatted, named placeholders.
|
60
|
-
#
|
61
|
-
# When you pass a Hash as an argument and specify placeholders with %{foo}
|
62
|
-
# it will interpret the hash values as named arguments.
|
63
|
-
#
|
64
|
-
# Example:
|
65
|
-
#
|
66
|
-
# "%{firstname}, %{lastname}" % {:firstname => "Masao", :lastname => "Mutoh"}
|
67
|
-
# # => "Masao Mutoh"
|
68
|
-
#
|
69
|
-
# * Using a Hash as an argument and formatted, named placeholders.
|
70
|
-
#
|
71
|
-
# When you pass a Hash as an argument and specify placeholders with %<foo>d
|
72
|
-
# it will interpret the hash values as named arguments and format the value
|
73
|
-
# according to the formatting instruction appended to the closing >.
|
74
|
-
#
|
75
|
-
# Example:
|
76
|
-
#
|
77
|
-
# "%<integer>d, %<float>.1f" % { :integer => 10, :float => 43.4 }
|
78
|
-
# # => "10, 43.3"
|
79
|
-
def %(args)
|
80
|
-
if args.kind_of?(Hash)
|
81
|
-
dup.gsub(INTERPOLATION_PATTERN_WITH_ESCAPE) do |match|
|
82
|
-
if match == '%%'
|
83
|
-
'%'
|
84
|
-
else
|
85
|
-
key = ($1 || $2).to_sym
|
86
|
-
raise KeyError unless args.has_key?(key)
|
87
|
-
$3 ? sprintf("%#{$3}", args[key]) : args[key]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
elsif self =~ INTERPOLATION_PATTERN
|
91
|
-
raise ArgumentError.new('one hash required')
|
92
|
-
else
|
93
|
-
result = gsub(/%([{<])/, '%%\1')
|
94
|
-
result.send :'interpolate_without_ruby_19_syntax', args
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|