tr8n_core 4.0.4 → 4.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +44 -6
- data/lib/tr8n/api_client.rb +109 -0
- data/lib/tr8n/application.rb +14 -96
- data/lib/tr8n/base.rb +7 -2
- data/lib/tr8n/cache.rb +2 -1
- data/lib/tr8n/cache_adapters/cdb.rb +2 -1
- data/lib/tr8n/cache_adapters/file.rb +2 -1
- data/lib/tr8n/cache_adapters/memcache.rb +2 -1
- data/lib/tr8n/cache_adapters/redis.rb +2 -1
- data/lib/tr8n/component.rb +2 -1
- data/lib/tr8n/config.rb +13 -3
- data/lib/tr8n/decorators/base.rb +2 -1
- data/lib/tr8n/decorators/default.rb +2 -1
- data/lib/tr8n/decorators/html.rb +2 -1
- data/lib/tr8n/exception.rb +2 -1
- data/lib/tr8n/language.rb +9 -3
- data/lib/tr8n/language_case.rb +5 -1
- data/lib/tr8n/language_case_rule.rb +2 -1
- data/lib/tr8n/language_context.rb +4 -1
- data/lib/tr8n/language_context_rule.rb +2 -1
- data/lib/tr8n/logger.rb +3 -2
- data/lib/tr8n/rules_engine/evaluator.rb +2 -1
- data/lib/tr8n/rules_engine/parser.rb +2 -1
- data/lib/tr8n/session.rb +21 -7
- data/lib/tr8n/source.rb +3 -2
- data/lib/tr8n/tokens/data.rb +319 -325
- data/lib/tr8n/tokens/data_tokenizer.rb +6 -1
- data/lib/tr8n/tokens/decoration_tokenizer.rb +15 -5
- data/lib/tr8n/tokens/hidden.rb +2 -1
- data/lib/tr8n/tokens/method.rb +4 -3
- data/lib/tr8n/tokens/transform.rb +22 -10
- data/lib/tr8n/translation.rb +6 -8
- data/lib/tr8n/translation_key.rb +11 -9
- data/lib/tr8n/translator.rb +2 -1
- data/lib/tr8n/utils.rb +6 -1
- data/lib/tr8n_core.rb +1 -1
- data/lib/tr8n_core/ext/array.rb +1 -1
- data/lib/tr8n_core/ext/date.rb +1 -1
- data/lib/tr8n_core/ext/fixnum.rb +1 -1
- data/lib/tr8n_core/ext/hash.rb +1 -1
- data/lib/tr8n_core/ext/string.rb +1 -1
- data/lib/tr8n_core/ext/time.rb +1 -1
- data/lib/tr8n_core/generators/cache/base.rb +1 -1
- data/lib/tr8n_core/generators/cache/cdb.rb +1 -1
- data/lib/tr8n_core/generators/cache/file.rb +1 -1
- data/lib/tr8n_core/languages/en-US.json +1362 -0
- data/lib/tr8n_core/version.rb +2 -2
- data/spec/language_case_spec.rb +3 -3
- data/spec/tokens/data_spec.rb +38 -84
- metadata +5 -3
data/lib/tr8n_core/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2014 Michael Berkovich,
|
2
|
+
# Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -23,5 +23,5 @@
|
|
23
23
|
|
24
24
|
|
25
25
|
module Tr8nCore
|
26
|
-
VERSION = "4.0.
|
26
|
+
VERSION = "4.0.5"
|
27
27
|
end
|
data/spec/language_case_spec.rb
CHANGED
@@ -32,11 +32,11 @@ describe Tr8n::LanguageCase do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should correctly process default cases" do
|
35
|
-
possessive = @english.
|
35
|
+
possessive = @english.case_by_keyword('pos')
|
36
36
|
expect(possessive.apply("Michael")).to eq("Michael's")
|
37
37
|
|
38
38
|
|
39
|
-
plural = @english.
|
39
|
+
plural = @english.case_by_keyword('plural')
|
40
40
|
|
41
41
|
expect(plural.apply("fish")).to eq("fish")
|
42
42
|
expect(plural.apply("money")).to eq("money")
|
@@ -48,7 +48,7 @@ describe Tr8n::LanguageCase do
|
|
48
48
|
expect(plural.apply("quiz")).to eq("quizzes")
|
49
49
|
expect(plural.apply("wife")).to eq("wives")
|
50
50
|
|
51
|
-
singular = @english.
|
51
|
+
singular = @english.case_by_keyword('singular')
|
52
52
|
expect(singular.apply("quizzes")).to eq("quiz")
|
53
53
|
expect(singular.apply("cars")).to eq("car")
|
54
54
|
expect(singular.apply("wives")).to eq("wife")
|
data/spec/tokens/data_spec.rb
CHANGED
@@ -27,36 +27,20 @@ describe Tr8n::Tokens::Data do
|
|
27
27
|
user.stub(:last_name_with_prefix) {|prefix| "#{prefix} #{user.last_name}"}
|
28
28
|
|
29
29
|
# tr("Hello {user}", "", {:user => current_user}}
|
30
|
-
expect(@token.token_value(user,
|
31
|
-
|
32
|
-
# tr("Hello {user}", "", {:user => [current_user]}}
|
33
|
-
expect(@token.token_value([user], {}, @english)).to eq(user.to_s)
|
30
|
+
expect(@token.token_value(user, @english)).to eq(user.to_s)
|
34
31
|
|
35
32
|
# tr("Hello {user}", "", {:user => [current_user, current_user.name]}}
|
36
|
-
expect(@token.token_value([user, user.first_name],
|
37
|
-
|
38
|
-
# tr("Hello {user}", "", {:user => [current_user, "{$0} {$1}", "param1"]}}
|
39
|
-
expect(@token.token_value([user, "{$0} {$1}", "param1"], {}, @english)).to eq(user.to_s + " param1")
|
40
|
-
expect(@token.token_value([user, "{$0} {$1} {$2}", "param1", "param2"], {}, @english)).to eq(user.to_s + " param1 param2")
|
33
|
+
expect(@token.token_value([user, user.first_name], @english)).to eq(user.first_name)
|
41
34
|
|
42
35
|
# tr("Hello {user}", "", {:user => [current_user, :name]}}
|
43
|
-
expect(@token.token_value([user, :first_name],
|
44
|
-
|
45
|
-
# tr("Hello {user}", "", {:user => [current_user, :method_name, "param1"]}}
|
46
|
-
expect(@token.token_value([user, :last_name_with_prefix, 'Mr.'], {}, @english)).to eq("Mr. Anderson")
|
47
|
-
|
48
|
-
# tr("Hello {user}", "", {:user => [current_user, lambda{|user| user.name}]}}
|
49
|
-
expect(@token.token_value([user, lambda{|user| user.to_s}], {}, @english)).to eq(user.to_s)
|
50
|
-
|
51
|
-
# tr("Hello {user}", "", {:user => [current_user, lambda{|user, param1| user.name}, "param1"]}}
|
52
|
-
expect(@token.token_value([user, lambda{|user, param1| user.to_s + " " + param1}, "extra_param1"], {}, @english)).to eq(user.to_s + " extra_param1")
|
36
|
+
expect(@token.token_value([user, :first_name], @english)).to eq(user.first_name)
|
53
37
|
|
54
38
|
# tr("Hello {user}", "", {:user => {:object => current_user, :value => current_user.name}]}}
|
55
|
-
expect(@token.token_value({:object => user, :value => user.to_s},
|
39
|
+
expect(@token.token_value({:object => user, :value => user.to_s}, @english)).to eq(user.to_s)
|
56
40
|
|
57
41
|
# tr("Hello {user}", "", {:user => {:object => current_user, :attribute => :first_name}]}}
|
58
|
-
expect(@token.token_value({:object => user, :attribute => :first_name},
|
59
|
-
expect(@token.token_value({:object => {:first_name => "Michael"}, :attribute => :first_name},
|
42
|
+
expect(@token.token_value({:object => user, :attribute => :first_name}, @english)).to eq(user.first_name)
|
43
|
+
expect(@token.token_value({:object => {:first_name => "Michael"}, :attribute => :first_name}, @english)).to eq("Michael")
|
60
44
|
end
|
61
45
|
|
62
46
|
it "should perform complete substitution" do
|
@@ -65,14 +49,8 @@ describe Tr8n::Tokens::Data do
|
|
65
49
|
|
66
50
|
[
|
67
51
|
{:user => user}, "Hello Tom Anderson",
|
68
|
-
{:user => [user]}, "Hello Tom Anderson",
|
69
52
|
{:user => [user, user.first_name]}, "Hello Tom",
|
70
|
-
{:user => [user, "{$0} {$1}", "param1"]}, "Hello Tom Anderson param1",
|
71
|
-
{:user => [user, "{$0} {$1} {$2}", "param1", "param2"]}, "Hello Tom Anderson param1 param2",
|
72
53
|
{:user => [user, :first_name]}, "Hello Tom",
|
73
|
-
{:user => [user, :last_name_with_prefix, 'Mr.']}, "Hello Mr. Anderson",
|
74
|
-
{:user => [user, lambda{|user| user.to_s}]}, "Hello Tom Anderson",
|
75
|
-
{:user => [user, lambda{|user, param1| user.to_s + " " + param1}, "extra_param1"]}, "Hello Tom Anderson extra_param1",
|
76
54
|
{:user => {:object => user, :value => user.to_s}}, "Hello Tom Anderson",
|
77
55
|
{:user => {:object => user, :attribute => :first_name}}, "Hello Tom",
|
78
56
|
{:user => {:object => {:first_name => "Michael"}, :attribute => :first_name}}, "Hello Michael"
|
@@ -96,62 +74,38 @@ describe Tr8n::Tokens::Data do
|
|
96
74
|
end
|
97
75
|
|
98
76
|
Tr8n.session.with_block_options(:dry => true) do
|
99
|
-
expect(token.token_value([users, :first_name],
|
100
|
-
|
101
|
-
expect(token.token_value([users,
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
:andor => 'or'
|
132
|
-
}], {}, @english)).to eq("First name 1, First name 2, First name 3, First name 4 or 2 others")
|
133
|
-
|
134
|
-
expect(token.token_value([users, [:first_name], {
|
135
|
-
:translate_items => false,
|
136
|
-
:expandable => false,
|
137
|
-
:minimizable => true,
|
138
|
-
:to_sentence => true,
|
139
|
-
:limit => 2,
|
140
|
-
:separator => ", ",
|
141
|
-
:description => nil,
|
142
|
-
:andor => 'or'
|
143
|
-
}], {}, @english)).to eq("First name 1, First name 2 or 4 others")
|
144
|
-
|
145
|
-
expect(token.token_value([users, [:first_name], {
|
146
|
-
:translate_items => false,
|
147
|
-
:expandable => false,
|
148
|
-
:minimizable => true,
|
149
|
-
:to_sentence => true,
|
150
|
-
:limit => 2,
|
151
|
-
:separator => " & ",
|
152
|
-
:description => nil,
|
153
|
-
:andor => 'or'
|
154
|
-
}], {}, @english)).to eq("First name 1 & First name 2 or 4 others")
|
77
|
+
expect(token.token_value([users, :first_name], @english)).to match("2 others")
|
78
|
+
|
79
|
+
expect(token.token_value([users, :first_name, {
|
80
|
+
:description => "List joiner",
|
81
|
+
:limit => 4,
|
82
|
+
:separator => ", ",
|
83
|
+
:joiner => 'and',
|
84
|
+
:less => '{laquo} less',
|
85
|
+
:expandable => false,
|
86
|
+
:collapsable => true
|
87
|
+
}], @english)).to eq("First name 1, First name 2, First name 3, First name 4 and 2 others")
|
88
|
+
|
89
|
+
expect(token.token_value([users, :first_name, {
|
90
|
+
:description => "List joiner",
|
91
|
+
:limit => 10,
|
92
|
+
:separator => ", ",
|
93
|
+
:joiner => 'and',
|
94
|
+
:less => '{laquo} less',
|
95
|
+
:expandable => false,
|
96
|
+
:collapsable => true
|
97
|
+
}], @english)).to eq("First name 1, First name 2, First name 3, First name 4, First name 5 and First name 6")
|
98
|
+
|
99
|
+
expect(token.token_value([users, :first_name, {
|
100
|
+
:joiner => 'or',
|
101
|
+
:expandable => false,
|
102
|
+
}], @english)).to eq("First name 1, First name 2, First name 3, First name 4 or 2 others")
|
103
|
+
|
104
|
+
expect(token.token_value([users, :first_name, {
|
105
|
+
:limit => 2,
|
106
|
+
:joiner => 'or',
|
107
|
+
:expandable => false,
|
108
|
+
}], @english)).to eq("First name 1, First name 2 or 4 others")
|
155
109
|
|
156
110
|
end
|
157
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -26,11 +26,12 @@ dependencies:
|
|
26
26
|
version: '0'
|
27
27
|
description: Tr8n core classes that can be used by any Ruby framework
|
28
28
|
email:
|
29
|
-
- michael@
|
29
|
+
- michael@translationexchange.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- lib/tr8n/api_client.rb
|
34
35
|
- lib/tr8n/application.rb
|
35
36
|
- lib/tr8n/base.rb
|
36
37
|
- lib/tr8n/cache.rb
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- lib/tr8n_core/generators/cache/base.rb
|
74
75
|
- lib/tr8n_core/generators/cache/cdb.rb
|
75
76
|
- lib/tr8n_core/generators/cache/file.rb
|
77
|
+
- lib/tr8n_core/languages/en-US.json
|
76
78
|
- lib/tr8n_core/version.rb
|
77
79
|
- lib/tr8n_core.rb
|
78
80
|
- LICENSE
|