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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +44 -6
  4. data/lib/tr8n/api_client.rb +109 -0
  5. data/lib/tr8n/application.rb +14 -96
  6. data/lib/tr8n/base.rb +7 -2
  7. data/lib/tr8n/cache.rb +2 -1
  8. data/lib/tr8n/cache_adapters/cdb.rb +2 -1
  9. data/lib/tr8n/cache_adapters/file.rb +2 -1
  10. data/lib/tr8n/cache_adapters/memcache.rb +2 -1
  11. data/lib/tr8n/cache_adapters/redis.rb +2 -1
  12. data/lib/tr8n/component.rb +2 -1
  13. data/lib/tr8n/config.rb +13 -3
  14. data/lib/tr8n/decorators/base.rb +2 -1
  15. data/lib/tr8n/decorators/default.rb +2 -1
  16. data/lib/tr8n/decorators/html.rb +2 -1
  17. data/lib/tr8n/exception.rb +2 -1
  18. data/lib/tr8n/language.rb +9 -3
  19. data/lib/tr8n/language_case.rb +5 -1
  20. data/lib/tr8n/language_case_rule.rb +2 -1
  21. data/lib/tr8n/language_context.rb +4 -1
  22. data/lib/tr8n/language_context_rule.rb +2 -1
  23. data/lib/tr8n/logger.rb +3 -2
  24. data/lib/tr8n/rules_engine/evaluator.rb +2 -1
  25. data/lib/tr8n/rules_engine/parser.rb +2 -1
  26. data/lib/tr8n/session.rb +21 -7
  27. data/lib/tr8n/source.rb +3 -2
  28. data/lib/tr8n/tokens/data.rb +319 -325
  29. data/lib/tr8n/tokens/data_tokenizer.rb +6 -1
  30. data/lib/tr8n/tokens/decoration_tokenizer.rb +15 -5
  31. data/lib/tr8n/tokens/hidden.rb +2 -1
  32. data/lib/tr8n/tokens/method.rb +4 -3
  33. data/lib/tr8n/tokens/transform.rb +22 -10
  34. data/lib/tr8n/translation.rb +6 -8
  35. data/lib/tr8n/translation_key.rb +11 -9
  36. data/lib/tr8n/translator.rb +2 -1
  37. data/lib/tr8n/utils.rb +6 -1
  38. data/lib/tr8n_core.rb +1 -1
  39. data/lib/tr8n_core/ext/array.rb +1 -1
  40. data/lib/tr8n_core/ext/date.rb +1 -1
  41. data/lib/tr8n_core/ext/fixnum.rb +1 -1
  42. data/lib/tr8n_core/ext/hash.rb +1 -1
  43. data/lib/tr8n_core/ext/string.rb +1 -1
  44. data/lib/tr8n_core/ext/time.rb +1 -1
  45. data/lib/tr8n_core/generators/cache/base.rb +1 -1
  46. data/lib/tr8n_core/generators/cache/cdb.rb +1 -1
  47. data/lib/tr8n_core/generators/cache/file.rb +1 -1
  48. data/lib/tr8n_core/languages/en-US.json +1362 -0
  49. data/lib/tr8n_core/version.rb +2 -2
  50. data/spec/language_case_spec.rb +3 -3
  51. data/spec/tokens/data_spec.rb +38 -84
  52. metadata +5 -3
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
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.4"
26
+ VERSION = "4.0.5"
27
27
  end
@@ -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.language_case_by_keyword('pos')
35
+ possessive = @english.case_by_keyword('pos')
36
36
  expect(possessive.apply("Michael")).to eq("Michael's")
37
37
 
38
38
 
39
- plural = @english.language_case_by_keyword('plural')
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.language_case_by_keyword('singular')
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")
@@ -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, {}, @english)).to eq(user.to_s)
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], {}, @english)).to eq(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], {}, @english)).to eq(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}, {}, @english)).to eq(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}, {}, @english)).to eq(user.first_name)
59
- expect(@token.token_value({:object => {:first_name => "Michael"}, :attribute => :first_name}, {}, @english)).to eq("Michael")
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], {}, @english)).to match("2 others")
100
-
101
- expect(token.token_value([users, [:first_name], {
102
- :translate_items => false,
103
- :expandable => false,
104
- :minimizable => true,
105
- :to_sentence => true,
106
- :limit => 4,
107
- :separator => ", ",
108
- :description => nil,
109
- :andor => 'and'
110
- }], {}, @english)).to eq("First name 1, First name 2, First name 3, First name 4 and 2 others")
111
-
112
- expect(token.token_value([users, [:first_name], {
113
- :translate_items => false,
114
- :expandable => false,
115
- :minimizable => true,
116
- :to_sentence => false,
117
- :limit => 4,
118
- :separator => ", ",
119
- :description => nil,
120
- :andor => 'and'
121
- }], {}, @english)).to eq("First name 1, First name 2, First name 3, First name 4, First name 5, First name 6")
122
-
123
- expect(token.token_value([users, [:first_name], {
124
- :translate_items => false,
125
- :expandable => false,
126
- :minimizable => true,
127
- :to_sentence => true,
128
- :limit => 4,
129
- :separator => ", ",
130
- :description => nil,
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
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-03-10 00:00:00.000000000 Z
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@tr8nhub.com
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