tr8n_core 4.0.7 → 4.0.9

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/tr8n/api_client.rb +28 -18
  4. data/lib/tr8n/application.rb +37 -64
  5. data/lib/tr8n/cache.rb +8 -41
  6. data/lib/tr8n/cache_adapters/file.rb +1 -2
  7. data/lib/tr8n/cache_adapters/memcache.rb +2 -2
  8. data/lib/tr8n/cache_adapters/redis.rb +2 -2
  9. data/lib/tr8n/config.rb +48 -13
  10. data/lib/tr8n/decorators/html.rb +3 -10
  11. data/lib/tr8n/language.rb +25 -112
  12. data/lib/tr8n/language_case.rb +1 -1
  13. data/lib/tr8n/session.rb +2 -9
  14. data/lib/tr8n/source.rb +12 -44
  15. data/lib/tr8n/{tokens/data_tokenizer.rb → tokenizers/data.rb} +4 -3
  16. data/lib/tr8n/{tokens/decoration_tokenizer.rb → tokenizers/decoration.rb} +6 -5
  17. data/lib/tr8n/tokenizers/dom.rb +346 -0
  18. data/lib/tr8n/tokens/data.rb +15 -22
  19. data/lib/tr8n/tokens/transform.rb +24 -12
  20. data/lib/tr8n/translation_key.rb +6 -29
  21. data/lib/tr8n/utils.rb +5 -0
  22. data/lib/tr8n_core/version.rb +1 -1
  23. data/lib/tr8n_core.rb +7 -26
  24. metadata +30 -100
  25. data/lib/tr8n/cache_adapters/cdb.rb +0 -87
  26. data/lib/tr8n/tokens/hidden.rb +0 -57
  27. data/spec/application_spec.rb +0 -52
  28. data/spec/base_spec.rb +0 -19
  29. data/spec/cache/adapters/file_spec.rb +0 -32
  30. data/spec/cache/adapters/memcache_spec.rb +0 -15
  31. data/spec/cache/generators/file_generator_spec.rb +0 -30
  32. data/spec/config_spec.rb +0 -32
  33. data/spec/decorator_spec.rb +0 -12
  34. data/spec/decorators/base_spec.rb +0 -14
  35. data/spec/decorators/default_spec.rb +0 -12
  36. data/spec/decorators/html_spec.rb +0 -50
  37. data/spec/ext/array_spec.rb +0 -12
  38. data/spec/ext/hash_spec.rb +0 -15
  39. data/spec/ext/string_spec.rb +0 -10
  40. data/spec/fixtures/application.json +0 -112
  41. data/spec/fixtures/languages/en-US.json +0 -1424
  42. data/spec/fixtures/languages/es.json +0 -291
  43. data/spec/fixtures/languages/ru.json +0 -582
  44. data/spec/fixtures/translations/ru/basic.json +0 -56
  45. data/spec/fixtures/translations/ru/counters.json +0 -43
  46. data/spec/fixtures/translations/ru/genders.json +0 -171
  47. data/spec/fixtures/translations/ru/last_names.txt +0 -200
  48. data/spec/fixtures/translations/ru/names.json +0 -1
  49. data/spec/fixtures/translations/ru/names.txt +0 -458
  50. data/spec/language_case_rule_spec.rb +0 -57
  51. data/spec/language_case_spec.rb +0 -58
  52. data/spec/language_context_rule_spec.rb +0 -75
  53. data/spec/language_context_spec.rb +0 -333
  54. data/spec/language_spec.rb +0 -615
  55. data/spec/logger_spec.rb +0 -15
  56. data/spec/rules_engine/evaluator_spec.rb +0 -150
  57. data/spec/rules_engine/parser_spec.rb +0 -31
  58. data/spec/source_spec.rb +0 -13
  59. data/spec/spec_helper.rb +0 -101
  60. data/spec/tokens/data_spec.rb +0 -114
  61. data/spec/tokens/data_tokenizer_spec.rb +0 -29
  62. data/spec/tokens/decoration_tokenizer_spec.rb +0 -81
  63. data/spec/tokens/hidden_spec.rb +0 -24
  64. data/spec/tokens/method_spec.rb +0 -84
  65. data/spec/tokens/transform_spec.rb +0 -50
  66. data/spec/translation_key_spec.rb +0 -96
  67. data/spec/translation_spec.rb +0 -24
  68. data/spec/utils_spec.rb +0 -62
@@ -1,50 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::Tokens::Transform do
6
- #before do
7
- # @app = init_application
8
- # @english = @app.language('en-US')
9
- # @tkey = Tr8n::TranslationKey.new({
10
- # :label => "You have {count||message}",
11
- # :application => @app,
12
- # :locale => 'en-US'
13
- # })
14
- # @tlabel = @tkey.tokenized_label
15
- #end
16
- #
17
- #describe "initialize" do
18
- # it "should parse token info" do
19
- # token = @tlabel.tokens.first
20
- # expect(token.class.name).to eq("Tr8n::Tokens::Transform")
21
- # expect(token.original_label).to eq(@tlabel.label)
22
- # expect(token.full_name).to eq("{count||message}")
23
- # expect(token.declared_name).to eq("count||message")
24
- # expect(token.name).to eq("count")
25
- # expect(token.sanitized_name).to eq("{count}")
26
- # expect(token.name_key).to eq(:count)
27
- # expect(token.pipeless_name).to eq("count")
28
- # expect(token.case_key).to be_nil
29
- # expect(token.supports_cases?).to be_truthy
30
- # expect(token.has_case_key?).to be_falsey
31
- # expect(token.caseless_name).to eq("count")
32
- #
33
- # expect(token.types).to be_nil
34
- # expect(token.has_types?).to be_falsey
35
- # expect(token.associated_rule_types).to eq([:number, :value])
36
- # expect(token.language_rule_classes).to eq([Tr8n::Rules::Number, Tr8n::Rules::Value])
37
- # expect(token.transformable_language_rule_classes).to eq([Tr8n::Rules::Number])
38
- # expect(token.decoration?).to be_falsey
39
- # end
40
- #end
41
- #
42
- #describe "substitute" do
43
- # it "should substitute values" do
44
- # token = @tlabel.tokens.first
45
- #
46
- # end
47
- #end
48
-
49
-
50
- end
@@ -1,96 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::TranslationKey do
6
- describe "#initialize" do
7
- before do
8
- @app = init_application
9
- @english = @app.language('en-US')
10
- @russian = @app.language('ru')
11
- end
12
-
13
- it "sets attributes" do
14
- expect(Tr8n::TranslationKey.attributes).to eq([:application, :language, :id, :key, :label, :description, :locale, :level, :locked, :translations])
15
-
16
- tkey = Tr8n::TranslationKey.new({
17
- :label => "Hello World",
18
- :application => @app
19
- })
20
- expect(tkey.locale).to eq("en-US")
21
- expect(tkey.language.locale).to eq("en-US")
22
-
23
- tkey = Tr8n::TranslationKey.new({
24
- :label => "Hello World",
25
- :application => @app,
26
- :locale => 'en-US'
27
- })
28
-
29
- expect(tkey.id).to be_nil
30
- expect(tkey.label).to eq("Hello World")
31
- expect(tkey.description).to be_nil
32
- expect(tkey.key).to eq("d541c79af1be6a05b1f16fca8b5730de")
33
- expect(tkey.locale).to eq("en-US")
34
- expect(tkey.language.locale).to eq("en-US")
35
- expect(tkey.has_translations_for_language?(@russian)).to be_falsey
36
- expect(tkey.translations_for_language(@russian)).to eq([])
37
- end
38
-
39
- it "translates labels correctly into default language" do
40
- tkey = Tr8n::TranslationKey.new(:label => "Hello World", :application => @app)
41
- expect(tkey.substitute_tokens("Hello World", {}, @english)).to eq("Hello World")
42
-
43
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user}", :application => @app)
44
- expect(tkey.substitute_tokens("Hello {user1}", {:user => "Michael"}, @english)).to eq("Hello {user1}")
45
-
46
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user}", :application => @app)
47
- expect(tkey.substitute_tokens("Hello {user}", {:user => "Michael"}, @english)).to eq("Hello Michael")
48
-
49
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user1} and {user2}", :application => @app)
50
- expect(tkey.substitute_tokens("Hello {user1} and {user2}", {:user1 => "Michael" , :user2 => "Tom"}, @english)).to eq("Hello Michael and Tom")
51
-
52
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user}", :application => @app)
53
- expect(tkey.substitute_tokens("Hello {user}", {:user => {:object => {:name => "Michael"}, :value => "Michael"}}, @english)).to eq("Hello Michael")
54
-
55
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user}", :application => @app)
56
- expect(tkey.substitute_tokens("Hello {user}", {:user => {:object => {:name => "Michael"}, :attribute => "name"}}, @english)).to eq("Hello Michael")
57
-
58
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user}", :application => @app)
59
- expect(tkey.substitute_tokens("Hello {user}", {:user => {:object => double(:name => "Michael"), :attribute => "name"}}, @english)).to eq("Hello Michael")
60
-
61
- tkey = Tr8n::TranslationKey.new(:label => "Hello {user1} [bold: and] {user2}", :application => @app)
62
- expect(tkey.substitute_tokens("Hello {user1} [bold: and] {user2}", {:user1 => "Michael" , :user2 => "Tom"}, @english)).to eq("Hello Michael <strong>and</strong> Tom")
63
-
64
- tkey = Tr8n::TranslationKey.new(:label => "You have [link: [bold: {count}] messages]", :application => @app)
65
- expect(tkey.substitute_tokens("You have [link: [bold: {count}] messages]", {:count => 5, :link => {:href => "www.google.com"}}, @english)).to eq("You have <a href='www.google.com'><strong>5</strong> messages</a>")
66
-
67
- tkey = Tr8n::TranslationKey.new(:label => "You have [link][bold: {count}] messages[/link]", :application => @app)
68
- expect(tkey.substitute_tokens("You have [link][bold: {count}] messages[/link]", {:count => 5, :link => {:href => "www.google.com"}}, @english)).to eq("You have <a href='www.google.com'><strong>5</strong> messages</a>")
69
- end
70
-
71
- context "labels with numeric rules" do
72
- it "should return correct translations" do
73
- key = Tr8n::TranslationKey.new(:label => "You have {count||message}.", :application => @app)
74
- key.set_language_translations(@russian, [
75
- Tr8n::Translation.new(:label => "U vas est {count} soobshenie.", :context => {"count" => {"number" => "one"}}),
76
- Tr8n::Translation.new(:label => "U vas est {count} soobsheniya.", :context => {"count" => {"number" => "few"}}),
77
- Tr8n::Translation.new(:label => "U vas est {count} soobshenii.", :context => {"count" => {"number" => "many"}}),
78
- ])
79
-
80
- expect(key.translate(@russian, {:count => 1})).to eq("U vas est 1 soobshenie.")
81
- expect(key.translate(@russian, {:count => 101})).to eq("U vas est 101 soobshenie.")
82
- expect(key.translate(@russian, {:count => 11})).to eq("U vas est 11 soobshenii.")
83
- expect(key.translate(@russian, {:count => 111})).to eq("U vas est 111 soobshenii.")
84
-
85
- expect(key.translate(@russian, {:count => 5})).to eq("U vas est 5 soobshenii.")
86
- expect(key.translate(@russian, {:count => 26})).to eq("U vas est 26 soobshenii.")
87
- expect(key.translate(@russian, {:count => 106})).to eq("U vas est 106 soobshenii.")
88
-
89
- expect(key.translate(@russian, {:count => 3})).to eq("U vas est 3 soobsheniya.")
90
- expect(key.translate(@russian, {:count => 13})).to eq("U vas est 13 soobshenii.")
91
- expect(key.translate(@russian, {:count => 23})).to eq("U vas est 23 soobsheniya.")
92
- expect(key.translate(@russian, {:count => 103})).to eq("U vas est 103 soobsheniya.")
93
- end
94
- end
95
- end
96
- end
@@ -1,24 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::Translation do
6
- describe "initialize" do
7
- before do
8
- @app = init_application
9
- @english = @app.language('en-US')
10
- @russian = @app.language('ru')
11
- end
12
-
13
- it "sets attributes" do
14
- expect(Tr8n::Translation.attributes).to eq([:translation_key, :language, :locale, :label, :context, :precedence])
15
-
16
- t = Tr8n::Translation.new(:label => "You have {count||message}", :context => {"count" => {"number" => "one"}}, :language => @russian)
17
-
18
- [1, 101, 1001].each do |count|
19
- expect(t.matches_rules?(:count => count)).to be_truthy
20
- end
21
-
22
- end
23
- end
24
- end
data/spec/utils_spec.rb DELETED
@@ -1,62 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::Utils do
6
- describe "helper methods" do
7
- it "should return correct values" do
8
-
9
- expect(
10
- Tr8n::Utils.normalize_tr_params("Hello {user}", "Sample label", {:user => "Michael"}, {})
11
- ).to eq(
12
- {:label=>"Hello {user}", :description=>"Sample label", :tokens=>{:user=>"Michael"}, :options=>{}}
13
- )
14
-
15
- expect(
16
- Tr8n::Utils.normalize_tr_params("Hello {user}", {:user => "Michael"}, nil, nil)
17
- ).to eq(
18
- {:label=>"Hello {user}", :description=>nil, :tokens=>{:user=>"Michael"}, :options=>nil}
19
- )
20
-
21
- expect(
22
- Tr8n::Utils.normalize_tr_params("Hello {user}", {:user => "Michael"}, {:skip_decoration => true}, nil)
23
- ).to eq(
24
- {:label=>"Hello {user}", :description=>nil, :tokens=>{:user=>"Michael"}, :options=>{:skip_decoration=>true}}
25
- )
26
-
27
- expect(
28
- Tr8n::Utils.normalize_tr_params({:label=>"Hello {user}", :description=>"Sample label", :tokens=>{:user=>"Michael"}, :options=>{}}, nil, nil, nil)
29
- ).to eq(
30
- {:label=>"Hello {user}", :description=>"Sample label", :tokens=>{:user=>"Michael"}, :options=>{}}
31
- )
32
-
33
- expect(Tr8n::Utils.guid.class).to be(String)
34
- end
35
-
36
- it "should correctly split by sentence" do
37
-
38
- expect(
39
- Tr8n::Utils.split_by_sentence("Hello World")
40
- ).to eq(
41
- ["Hello World"]
42
- )
43
-
44
- expect(
45
- Tr8n::Utils.split_by_sentence("This is the first sentence. Followed by the second one.")
46
- ).to eq(
47
- ["This is the first sentence.", "Followed by the second one."]
48
- )
49
-
50
- end
51
-
52
- it "should correctly sign and verify signature" do
53
- data = {"name" => "Michael"}
54
- key = "abc"
55
-
56
- request = Tr8n::Utils.sign_and_encode_params(data, key)
57
- result = Tr8n::Utils.decode_and_verify_params(request, key)
58
- expect(result["name"]).to eq(data["name"])
59
- end
60
-
61
- end
62
- end