tr8n_core 4.0.7 → 4.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/tr8n/api_client.rb +28 -18
- data/lib/tr8n/application.rb +37 -64
- data/lib/tr8n/cache.rb +8 -41
- data/lib/tr8n/cache_adapters/file.rb +1 -2
- data/lib/tr8n/cache_adapters/memcache.rb +2 -2
- data/lib/tr8n/cache_adapters/redis.rb +2 -2
- data/lib/tr8n/config.rb +48 -13
- data/lib/tr8n/decorators/html.rb +3 -10
- data/lib/tr8n/language.rb +25 -112
- data/lib/tr8n/language_case.rb +1 -1
- data/lib/tr8n/session.rb +2 -9
- data/lib/tr8n/source.rb +12 -44
- data/lib/tr8n/{tokens/data_tokenizer.rb → tokenizers/data.rb} +4 -3
- data/lib/tr8n/{tokens/decoration_tokenizer.rb → tokenizers/decoration.rb} +6 -5
- data/lib/tr8n/tokenizers/dom.rb +346 -0
- data/lib/tr8n/tokens/data.rb +15 -22
- data/lib/tr8n/tokens/transform.rb +24 -12
- data/lib/tr8n/translation_key.rb +6 -29
- data/lib/tr8n/utils.rb +5 -0
- data/lib/tr8n_core/version.rb +1 -1
- data/lib/tr8n_core.rb +7 -26
- metadata +30 -100
- data/lib/tr8n/cache_adapters/cdb.rb +0 -87
- data/lib/tr8n/tokens/hidden.rb +0 -57
- data/spec/application_spec.rb +0 -52
- data/spec/base_spec.rb +0 -19
- data/spec/cache/adapters/file_spec.rb +0 -32
- data/spec/cache/adapters/memcache_spec.rb +0 -15
- data/spec/cache/generators/file_generator_spec.rb +0 -30
- data/spec/config_spec.rb +0 -32
- data/spec/decorator_spec.rb +0 -12
- data/spec/decorators/base_spec.rb +0 -14
- data/spec/decorators/default_spec.rb +0 -12
- data/spec/decorators/html_spec.rb +0 -50
- data/spec/ext/array_spec.rb +0 -12
- data/spec/ext/hash_spec.rb +0 -15
- data/spec/ext/string_spec.rb +0 -10
- data/spec/fixtures/application.json +0 -112
- data/spec/fixtures/languages/en-US.json +0 -1424
- data/spec/fixtures/languages/es.json +0 -291
- data/spec/fixtures/languages/ru.json +0 -582
- data/spec/fixtures/translations/ru/basic.json +0 -56
- data/spec/fixtures/translations/ru/counters.json +0 -43
- data/spec/fixtures/translations/ru/genders.json +0 -171
- data/spec/fixtures/translations/ru/last_names.txt +0 -200
- data/spec/fixtures/translations/ru/names.json +0 -1
- data/spec/fixtures/translations/ru/names.txt +0 -458
- data/spec/language_case_rule_spec.rb +0 -57
- data/spec/language_case_spec.rb +0 -58
- data/spec/language_context_rule_spec.rb +0 -75
- data/spec/language_context_spec.rb +0 -333
- data/spec/language_spec.rb +0 -615
- data/spec/logger_spec.rb +0 -15
- data/spec/rules_engine/evaluator_spec.rb +0 -150
- data/spec/rules_engine/parser_spec.rb +0 -31
- data/spec/source_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -101
- data/spec/tokens/data_spec.rb +0 -114
- data/spec/tokens/data_tokenizer_spec.rb +0 -29
- data/spec/tokens/decoration_tokenizer_spec.rb +0 -81
- data/spec/tokens/hidden_spec.rb +0 -24
- data/spec/tokens/method_spec.rb +0 -84
- data/spec/tokens/transform_spec.rb +0 -50
- data/spec/translation_key_spec.rb +0 -96
- data/spec/translation_spec.rb +0 -24
- data/spec/utils_spec.rb +0 -62
data/spec/application_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Tr8n::Application do
|
6
|
-
describe "#configuration" do
|
7
|
-
it "sets class attributes" do
|
8
|
-
expect(Tr8n::Application.attributes).to eq([:host, :key, :secret, :access_token,
|
9
|
-
:name, :description, :threshold, :default_locale, :default_level,
|
10
|
-
:features, :languages, :featured_locales, :sources, :components, :tokens,
|
11
|
-
:css, :shortcuts])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#initialize" do
|
16
|
-
before do
|
17
|
-
@app = init_application
|
18
|
-
end
|
19
|
-
|
20
|
-
it "loads application attributes" do
|
21
|
-
expect(@app.key).to eq("default")
|
22
|
-
expect(@app.name).to eq("Tr8n Translation Service")
|
23
|
-
|
24
|
-
expect(@app.default_data_token('nbsp')).to eq(" ")
|
25
|
-
expect(@app.default_decoration_token('strong')).to eq("<strong>{$0}</strong>")
|
26
|
-
|
27
|
-
expect(@app.feature_enabled?(:language_cases)).to be_truthy
|
28
|
-
expect(@app.feature_enabled?(:language_flags)).to be_truthy
|
29
|
-
end
|
30
|
-
|
31
|
-
it "loads application language" do
|
32
|
-
expect(@app.languages.size).to eq(14)
|
33
|
-
|
34
|
-
russian = @app.language('ru')
|
35
|
-
expect(russian.locale).to eq('ru')
|
36
|
-
expect(russian.contexts.keys.size).to eq(6)
|
37
|
-
expect(russian.contexts.keys).to eq(["date", "gender", "genders", "list", "number", "value"])
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should reset translations" do
|
41
|
-
@app.reset_translation_cache
|
42
|
-
expect(@app.translation_keys).to eq({})
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should reset translations" do
|
46
|
-
@app.register_missing_key(Tr8n::TranslationKey.new(:application => @app, :label => "Hello"), Tr8n::Source.new(:key => "test"))
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
end
|
data/spec/base_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_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
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Tr8n::CacheAdapters::File do
|
6
|
-
describe "#configuration" do
|
7
|
-
it "provides correct values" do
|
8
|
-
|
9
|
-
Tr8n.with_config_settings do |config|
|
10
|
-
|
11
|
-
config.cache = {
|
12
|
-
:path => "./cache"
|
13
|
-
}
|
14
|
-
|
15
|
-
c = Tr8n::CacheAdapters::File.new
|
16
|
-
|
17
|
-
expect(c.class.cache_path).to eq("./cache/files/current")
|
18
|
-
|
19
|
-
expect(c.class.file_name("test_key")).to eq("test_key.json")
|
20
|
-
expect(c.class.file_name("test/key")).to eq("test-key.json")
|
21
|
-
expect(c.class.file_path("test/key")).to eq("./cache/files/current/test-key.json")
|
22
|
-
|
23
|
-
c.store("a", "b")
|
24
|
-
c.delete("a")
|
25
|
-
c.clear()
|
26
|
-
|
27
|
-
expect(c.exist?("some_new_key")).to be_falsey
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Tr8nCore::Generators::Cache::File do
|
6
|
-
describe "#configuration" do
|
7
|
-
it "provides correct values" do
|
8
|
-
|
9
|
-
Tr8n.with_config_settings do |config|
|
10
|
-
Tr8n.session.application = init_application
|
11
|
-
|
12
|
-
config.cache = {
|
13
|
-
:path => "./cache"
|
14
|
-
}
|
15
|
-
|
16
|
-
#g = Tr8nCore::Generators::Cache::File.new
|
17
|
-
#g.started_at = Time.new(2014, 01, 01, 10, 11, 12)
|
18
|
-
#expect(g.cache_path).to eq("./cache/files/tr8n_default_2014_01_01_10_11_12")
|
19
|
-
#expect(g.symlink_path).to eq("./cache/files/current")
|
20
|
-
#
|
21
|
-
#expect(g.file_path("test_key")).to eq("./cache/files/tr8n_default_2014_01_01_10_11_12/test_key.json")
|
22
|
-
#
|
23
|
-
#g.cache("test_key", {"a" => "b"})
|
24
|
-
#expect(File.exists?(g.file_path("test_key"))).to be_truthy
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/config_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_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_falsey
|
9
|
-
expect(Tr8n.config.enabled?).to be_truthy
|
10
|
-
expect(Tr8n.config.default_locale).to eq("en-US")
|
11
|
-
expect(Tr8n.config.cache[:enabled]).to be_falsey
|
12
|
-
expect(Tr8n.config.logger[:path]).to eq("./log/tr8n.log")
|
13
|
-
expect(Tr8n.config.cache[:adapter]).to eq("memcache")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "configuring settings" do
|
18
|
-
it "should preserve changes" do
|
19
|
-
expect(Tr8n.config.default_locale).to eq("en-US")
|
20
|
-
Tr8n.configure do |config|
|
21
|
-
config.default_locale= 'ru'
|
22
|
-
end
|
23
|
-
expect(Tr8n.config.default_locale).to eq("ru")
|
24
|
-
|
25
|
-
Tr8n.configure do |config|
|
26
|
-
config.default_locale= 'en-US'
|
27
|
-
end
|
28
|
-
expect(Tr8n.config.default_locale).to eq("en-US")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/decorator_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_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
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_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
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_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.session.current_translator = nil
|
23
|
-
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
24
|
-
|
25
|
-
Tr8n.session.current_translator = Tr8n::Translator.new
|
26
|
-
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
27
|
-
|
28
|
-
Tr8n.session.current_translator = Tr8n::Translator.new
|
29
|
-
Tr8n.session.current_translator.inline = false
|
30
|
-
expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
|
31
|
-
Tr8n.session.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.session.current_translator.features = {"show_locked_keys" => true}
|
46
|
-
Tr8n.session.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
|
data/spec/ext/array_spec.rb
DELETED
data/spec/ext/hash_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Hash do
|
6
|
-
it "must provide correct attributes" do
|
7
|
-
h = {}.tr8n_translated
|
8
|
-
expect(h.tr8n_translated?).to be_truthy
|
9
|
-
|
10
|
-
h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
|
11
|
-
h2 = {"b" => 254, "c" => 300, "c" => {"c1" => 16, "c3" => 94}}
|
12
|
-
expect(h1.rmerge(h2)).to eq({"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}})
|
13
|
-
expect(h1.rmerge!(h2)).to eq({"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}})
|
14
|
-
end
|
15
|
-
end
|
data/spec/ext/string_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
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
|
-
}
|