tr8n_core 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +9 -0
- data/config/config.yml +34 -0
- data/config/tokens/data.yml +45 -0
- data/config/tokens/decorations.yml +37 -0
- data/lib/tr8n/application.rb +320 -0
- data/lib/tr8n/base.rb +123 -0
- data/lib/tr8n/cache.rb +144 -0
- data/lib/tr8n/cache_adapters/cdb.rb +74 -0
- data/lib/tr8n/cache_adapters/file.rb +70 -0
- data/lib/tr8n/cache_adapters/memcache.rb +91 -0
- data/lib/tr8n/cache_adapters/redis.rb +94 -0
- data/lib/tr8n/component.rb +68 -0
- data/lib/tr8n/config.rb +291 -0
- data/lib/tr8n/decorators/base.rb +35 -0
- data/lib/tr8n/decorators/default.rb +30 -0
- data/lib/tr8n/decorators/html.rb +63 -0
- data/lib/tr8n/exception.rb +26 -0
- data/lib/tr8n/language.rb +250 -0
- data/lib/tr8n/language_case.rb +116 -0
- data/lib/tr8n/language_case_rule.rb +85 -0
- data/lib/tr8n/language_context.rb +115 -0
- data/lib/tr8n/language_context_rule.rb +62 -0
- data/lib/tr8n/logger.rb +83 -0
- data/lib/tr8n/rules_engine/evaluator.rb +156 -0
- data/lib/tr8n/rules_engine/parser.rb +83 -0
- data/lib/tr8n/source.rb +95 -0
- data/lib/tr8n/tokens/data.rb +410 -0
- data/lib/tr8n/tokens/data_tokenizer.rb +82 -0
- data/lib/tr8n/tokens/decoration_tokenizer.rb +200 -0
- data/lib/tr8n/tokens/hidden.rb +48 -0
- data/lib/tr8n/tokens/method.rb +52 -0
- data/lib/tr8n/tokens/transform.rb +191 -0
- data/lib/tr8n/translation.rb +104 -0
- data/lib/tr8n/translation_key.rb +205 -0
- data/lib/tr8n/translator.rb +62 -0
- data/lib/tr8n/utils.rb +124 -0
- data/lib/tr8n_core/ext/array.rb +74 -0
- data/lib/tr8n_core/ext/date.rb +63 -0
- data/lib/tr8n_core/ext/fixnum.rb +39 -0
- data/lib/tr8n_core/ext/hash.rb +126 -0
- data/lib/tr8n_core/ext/string.rb +44 -0
- data/lib/tr8n_core/ext/time.rb +71 -0
- data/lib/tr8n_core/generators/cache/base.rb +85 -0
- data/lib/tr8n_core/generators/cache/cdb.rb +27 -0
- data/lib/tr8n_core/generators/cache/file.rb +69 -0
- data/lib/tr8n_core/modules/logger.rb +43 -0
- data/lib/tr8n_core/version.rb +27 -0
- data/lib/tr8n_core.rb +68 -0
- data/spec/application_spec.rb +228 -0
- data/spec/base_spec.rb +19 -0
- data/spec/config_spec.rb +16 -0
- data/spec/decorator_spec.rb +10 -0
- data/spec/decorators/base_spec.rb +14 -0
- data/spec/decorators/default_spec.rb +12 -0
- data/spec/decorators/html_spec.rb +50 -0
- data/spec/fixtures/application.json +112 -0
- data/spec/fixtures/languages/en-US.json +1424 -0
- data/spec/fixtures/languages/es.json +291 -0
- data/spec/fixtures/languages/ru.json +550 -0
- data/spec/fixtures/translations/ru/basic.json +56 -0
- data/spec/fixtures/translations/ru/counters.json +43 -0
- data/spec/fixtures/translations/ru/genders.json +171 -0
- data/spec/fixtures/translations/ru/last_names.txt +200 -0
- data/spec/fixtures/translations/ru/names.json +1 -0
- data/spec/fixtures/translations/ru/names.txt +458 -0
- data/spec/helper.rb +84 -0
- data/spec/language_case_rule_spec.rb +57 -0
- data/spec/language_case_spec.rb +58 -0
- data/spec/language_context_rule_spec.rb +73 -0
- data/spec/language_context_spec.rb +331 -0
- data/spec/language_spec.rb +16 -0
- data/spec/rules_engine/evaluator_spec.rb +148 -0
- data/spec/rules_engine/parser_spec.rb +29 -0
- data/spec/tokens/data_spec.rb +160 -0
- data/spec/tokens/data_tokenizer_spec.rb +29 -0
- data/spec/tokens/decoration_tokenizer_spec.rb +81 -0
- data/spec/tokens/hidden_spec.rb +24 -0
- data/spec/tokens/method_spec.rb +84 -0
- data/spec/tokens/transform_spec.rb +50 -0
- data/spec/translation_key_spec.rb +96 -0
- data/spec/translation_spec.rb +24 -0
- data/spec/utils_spec.rb +64 -0
- metadata +176 -0
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe Tr8n::Base do
|
6
|
+
describe "hash value method" do
|
7
|
+
it "must return correct values" do
|
8
|
+
expect(Tr8n::Base.hash_value({"a" => "b"}, "a")).to eq("b")
|
9
|
+
expect(Tr8n::Base.hash_value({:a => "b"}, "a")).to eq("b")
|
10
|
+
expect(Tr8n::Base.hash_value({:a => "b"}, :a)).to eq("b")
|
11
|
+
expect(Tr8n::Base.hash_value({"a" => "b"}, :a)).to eq("b")
|
12
|
+
|
13
|
+
expect(Tr8n::Base.hash_value({"a" => {:b => "c"}}, "a.b")).to eq("c")
|
14
|
+
expect(Tr8n::Base.hash_value({:a => {:b => "c"}}, "a.b")).to eq("c")
|
15
|
+
expect(Tr8n::Base.hash_value({:a => {:b => "c"}}, "a.d")).to be_nil
|
16
|
+
expect(Tr8n::Base.hash_value({:a => {:b => {:c => :d}}}, "a.b.c")).to eq(:d)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe Tr8n::Config do
|
6
|
+
describe "loading defaults" do
|
7
|
+
it "should load correct values" do
|
8
|
+
expect(Tr8n.config.logger_enabled?).to be_true
|
9
|
+
expect(Tr8n.config.enabled?).to be_true
|
10
|
+
expect(Tr8n.config.default_locale).to eq("en-US")
|
11
|
+
expect(Tr8n.config.cache_enabled?).to be_false
|
12
|
+
expect(Tr8n.config.log_path).to eq("./log/tr8n.log")
|
13
|
+
expect(Tr8n.config.cache_adapter).to eq("file")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe Tr8n::Decorators::Base do
|
6
|
+
describe "creating new decorator" do
|
7
|
+
it "must return a decorator specified in the config file" do
|
8
|
+
decor = Tr8n::Decorators::Base.decorator
|
9
|
+
expect(decor.class.name).to eq("Tr8n::Decorators::Default")
|
10
|
+
|
11
|
+
expect{Tr8n::Decorators::Base.new.decorate(nil, nil, nil, nil)}.to raise_error(Tr8n::Exception)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe Tr8n::Decorators::Default do
|
6
|
+
describe "default decorator" do
|
7
|
+
it "should return label as is without applying decorations" do
|
8
|
+
decor = Tr8n::Decorators::Default.new
|
9
|
+
expect(decor.decorate("Hello World", nil, nil, nil)).to eq("Hello World")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe Tr8n::Decorators::Html do
|
6
|
+
describe "html decorator" do
|
7
|
+
it "should decorate the label according to the options" do
|
8
|
+
decor = Tr8n::Decorators::Html.new
|
9
|
+
|
10
|
+
app = init_application
|
11
|
+
en = app.language('en-US')
|
12
|
+
ru = app.language('ru')
|
13
|
+
es = app.language('es')
|
14
|
+
|
15
|
+
tkey = Tr8n::TranslationKey.new({
|
16
|
+
:label => "Hello World",
|
17
|
+
:application => app,
|
18
|
+
:locale => 'en-US'
|
19
|
+
})
|
20
|
+
|
21
|
+
expect(decor.decorate("Hello World", en, en, tkey, {:skip_decorations => true})).to eq("Hello World")
|
22
|
+
Tr8n.config.current_translator = nil
|
23
|
+
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
24
|
+
|
25
|
+
Tr8n.config.current_translator = Tr8n::Translator.new
|
26
|
+
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
27
|
+
|
28
|
+
Tr8n.config.current_translator = Tr8n::Translator.new
|
29
|
+
Tr8n.config.current_translator.inline = false
|
30
|
+
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
31
|
+
Tr8n.config.current_translator.inline = true
|
32
|
+
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
33
|
+
expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("<span class='tr8n_pending'>Privet Mir</span>")
|
34
|
+
expect(decor.decorate("Privet Mir", ru, ru, tkey, {:use_div => true})).to eq("<div class='tr8n_pending'>Privet Mir</div>")
|
35
|
+
|
36
|
+
tkey.id = 5
|
37
|
+
expect(decor.decorate("Hello World", en, ru, tkey)).to eq("<span class='tr8n_translatable tr8n_not_translated' data-translation_key_id='5'>Hello World</span>")
|
38
|
+
expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("<span class='tr8n_translatable tr8n_translated' data-translation_key_id='5'>Privet Mir</span>")
|
39
|
+
|
40
|
+
expect(decor.decorate("Hola Mir", es, ru, tkey)).to eq("<span class='tr8n_translatable tr8n_fallback' data-translation_key_id='5'>Hola Mir</span>")
|
41
|
+
|
42
|
+
tkey.locked = true
|
43
|
+
expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("Privet Mir")
|
44
|
+
|
45
|
+
Tr8n.config.current_translator.features = {"show_locked_keys" => true}
|
46
|
+
Tr8n.config.current_translator.manager = true
|
47
|
+
expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("<span class='tr8n_translatable tr8n_locked' data-translation_key_id='5'>Privet Mir</span>")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
{
|
2
|
+
"key":"default",
|
3
|
+
"name":"Tr8n Translation Service",
|
4
|
+
"description":"",
|
5
|
+
"default_locale":"en-US",
|
6
|
+
"languages":[
|
7
|
+
{
|
8
|
+
"locale":"da",
|
9
|
+
"name":"Danske",
|
10
|
+
"english_name":"Danish",
|
11
|
+
"native_name":"Danske",
|
12
|
+
"flag_url":"http://localhost:3000/media/22/6/63/49/2d1982f07d7e7c2b0.png"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"locale":"nl",
|
16
|
+
"name":"Flemish",
|
17
|
+
"english_name":"Dutch",
|
18
|
+
"native_name":"Flemish",
|
19
|
+
"flag_url":"http://localhost:3000/media/5/2/45/67/0915799fae203af51.png"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"locale":"en-US",
|
23
|
+
"name":"English (US)",
|
24
|
+
"english_name":"English (US)",
|
25
|
+
"native_name":"English (US)",
|
26
|
+
"flag_url":"http://localhost:3000/media/57/23/20/19/cf185dab9566b718e.png"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"locale":"et",
|
30
|
+
"name":"Eesti",
|
31
|
+
"english_name":"Estonian",
|
32
|
+
"native_name":"Eesti",
|
33
|
+
"flag_url":"http://localhost:3000/media/71/5/89/63/5f40bc0a610274b28.png"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"locale":"fr",
|
37
|
+
"name":"Français",
|
38
|
+
"english_name":"French",
|
39
|
+
"native_name":"Français",
|
40
|
+
"flag_url":"http://localhost:3000/media/22/5/6/87/e52809adf86d81215.png"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"locale":"de",
|
44
|
+
"name":"Deutsch",
|
45
|
+
"english_name":"German",
|
46
|
+
"native_name":"Deutsch",
|
47
|
+
"flag_url":"http://localhost:3000/media/5/11/98/10/bc99d7cc527101e6d.png"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"locale":"he",
|
51
|
+
"name":"עברית",
|
52
|
+
"english_name":"Hebrew",
|
53
|
+
"native_name":"עברית",
|
54
|
+
"right_to_left":true,
|
55
|
+
"flag_url":"http://localhost:3000/media/42/62/44/29/8720a6f403329ec30.png"
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"locale":"no",
|
59
|
+
"name":"Norsk (bokmål)",
|
60
|
+
"english_name":"Norwegian",
|
61
|
+
"native_name":"Norsk (bokmål)",
|
62
|
+
"flag_url":"http://localhost:3000/media/23/60/15/78/a3c7c6e81482ffa63.png"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"locale":"ru",
|
66
|
+
"name":"Русский",
|
67
|
+
"english_name":"Russian",
|
68
|
+
"native_name":"Русский",
|
69
|
+
"flag_url":"http://localhost:3000/media/54/39/11/49/cb768f030bde97f97.png"
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"locale":"es",
|
73
|
+
"name":"Español",
|
74
|
+
"english_name":"Spanish",
|
75
|
+
"native_name":"Español",
|
76
|
+
"flag_url":"http://localhost:3000/media/52/47/56/19/6594b760c14053ef4.png"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"locale":"sv",
|
80
|
+
"name":"Svenska",
|
81
|
+
"english_name":"Swedish",
|
82
|
+
"native_name":"Svenska",
|
83
|
+
"flag_url":"http://localhost:3000/media/38/75/53/53/89753a508d8179af1.png"
|
84
|
+
}
|
85
|
+
],
|
86
|
+
"threshold":1,
|
87
|
+
"translator_level":1,
|
88
|
+
"features":{
|
89
|
+
"inline_translations":true,
|
90
|
+
"google_suggestions":true,
|
91
|
+
"decorations":true,
|
92
|
+
"shortcuts":true,
|
93
|
+
"context_rules":true,
|
94
|
+
"language_cases":true,
|
95
|
+
"javascript_sdk":false,
|
96
|
+
"glossary":true,
|
97
|
+
"forum":true,
|
98
|
+
"awards":true,
|
99
|
+
"admin_translations":true,
|
100
|
+
"open_registration":false,
|
101
|
+
"language_flags":true
|
102
|
+
},
|
103
|
+
"tokens":{
|
104
|
+
"data":{
|
105
|
+
"nbsp":" "
|
106
|
+
},
|
107
|
+
"decoration":{
|
108
|
+
"link":"<a href=\"{$href}\">{$0}</a>",
|
109
|
+
"strong":"<strong>{$0}</strong>"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|