tml 4.3.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 +243 -0
- data/Rakefile +9 -0
- data/lib/tml.rb +56 -0
- data/lib/tml/api/client.rb +206 -0
- data/lib/tml/api/post_office.rb +71 -0
- data/lib/tml/application.rb +254 -0
- data/lib/tml/base.rb +116 -0
- data/lib/tml/cache.rb +143 -0
- data/lib/tml/cache_adapters/file.rb +89 -0
- data/lib/tml/cache_adapters/memcache.rb +104 -0
- data/lib/tml/cache_adapters/memory.rb +85 -0
- data/lib/tml/cache_adapters/redis.rb +108 -0
- data/lib/tml/config.rb +410 -0
- data/lib/tml/decorators/base.rb +52 -0
- data/lib/tml/decorators/default.rb +43 -0
- data/lib/tml/decorators/html.rb +102 -0
- data/lib/tml/exception.rb +35 -0
- data/lib/tml/ext/array.rb +86 -0
- data/lib/tml/ext/date.rb +99 -0
- data/lib/tml/ext/fixnum.rb +47 -0
- data/lib/tml/ext/hash.rb +99 -0
- data/lib/tml/ext/string.rb +56 -0
- data/lib/tml/ext/time.rb +89 -0
- data/lib/tml/generators/cache/base.rb +117 -0
- data/lib/tml/generators/cache/file.rb +159 -0
- data/lib/tml/language.rb +175 -0
- data/lib/tml/language_case.rb +105 -0
- data/lib/tml/language_case_rule.rb +76 -0
- data/lib/tml/language_context.rb +117 -0
- data/lib/tml/language_context_rule.rb +56 -0
- data/lib/tml/languages/en.json +1363 -0
- data/lib/tml/logger.rb +109 -0
- data/lib/tml/rules_engine/evaluator.rb +162 -0
- data/lib/tml/rules_engine/parser.rb +65 -0
- data/lib/tml/session.rb +199 -0
- data/lib/tml/source.rb +106 -0
- data/lib/tml/tokenizers/data.rb +96 -0
- data/lib/tml/tokenizers/decoration.rb +204 -0
- data/lib/tml/tokenizers/dom.rb +346 -0
- data/lib/tml/tokens/data.rb +403 -0
- data/lib/tml/tokens/method.rb +61 -0
- data/lib/tml/tokens/transform.rb +223 -0
- data/lib/tml/translation.rb +67 -0
- data/lib/tml/translation_key.rb +178 -0
- data/lib/tml/translator.rb +47 -0
- data/lib/tml/utils.rb +130 -0
- data/lib/tml/version.rb +34 -0
- metadata +121 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2015 Translation Exchange, Inc
|
4
|
+
#
|
5
|
+
# _______ _ _ _ ______ _
|
6
|
+
# |__ __| | | | | (_) | ____| | |
|
7
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
8
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
9
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
10
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
11
|
+
# __/ |
|
12
|
+
# |___/
|
13
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
14
|
+
# a copy of this software and associated documentation files (the
|
15
|
+
# "Software"), to deal in the Software without restriction, including
|
16
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
17
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
19
|
+
# the following conditions:
|
20
|
+
#
|
21
|
+
# The above copyright notice and this permission notice shall be
|
22
|
+
# included in all copies or substantial portions of the Software.
|
23
|
+
#
|
24
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
25
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
27
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
28
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
29
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
30
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
+
#++
|
32
|
+
|
33
|
+
class Tml::Translator < Tml::Base
|
34
|
+
belongs_to :application
|
35
|
+
attributes :id, :name, :email, :gender, :mugshot, :link, :inline, :features, :image_url
|
36
|
+
attributes :voting_power, :rank, :level, :locale, :manager, :code
|
37
|
+
|
38
|
+
def feature_enabled?(key)
|
39
|
+
return false unless features
|
40
|
+
hash_value(features, key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def inline?
|
44
|
+
return Tml.session.block_options[:inline] unless Tml.session.block_options[:inline].nil?
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
data/lib/tml/utils.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2015 Translation Exchange, Inc
|
4
|
+
#
|
5
|
+
# _______ _ _ _ ______ _
|
6
|
+
# |__ __| | | | | (_) | ____| | |
|
7
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
8
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
9
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
10
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
11
|
+
# __/ |
|
12
|
+
# |___/
|
13
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
14
|
+
# a copy of this software and associated documentation files (the
|
15
|
+
# "Software"), to deal in the Software without restriction, including
|
16
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
17
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
19
|
+
# the following conditions:
|
20
|
+
#
|
21
|
+
# The above copyright notice and this permission notice shall be
|
22
|
+
# included in all copies or substantial portions of the Software.
|
23
|
+
#
|
24
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
25
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
27
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
28
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
29
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
30
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
+
#++
|
32
|
+
|
33
|
+
require 'yaml'
|
34
|
+
require 'base64'
|
35
|
+
require 'openssl'
|
36
|
+
require 'json'
|
37
|
+
require 'uri'
|
38
|
+
|
39
|
+
module Tml
|
40
|
+
class Utils
|
41
|
+
def self.normalize_tr_params(label, description, tokens, options)
|
42
|
+
return label if label.is_a?(Hash)
|
43
|
+
|
44
|
+
if description.is_a?(Hash)
|
45
|
+
return {
|
46
|
+
:label => label,
|
47
|
+
:description => nil,
|
48
|
+
:tokens => description,
|
49
|
+
:options => tokens
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
{
|
54
|
+
:label => label,
|
55
|
+
:description => description,
|
56
|
+
:tokens => tokens,
|
57
|
+
:options => options
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.guid
|
62
|
+
(0..16).to_a.map{|a| rand(16).to_s(16)}.join
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.hash_value(hash, key)
|
66
|
+
hash[key.to_s] || hash[key.to_sym]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.split_by_sentence(text)
|
70
|
+
sentence_regex = /[^.!?\s][^.!?]*(?:[.!?](?![\'"]?\s|$)[^.!?]*)*[.!?]?[\'"]?(?=\s|$)/
|
71
|
+
|
72
|
+
sentences = []
|
73
|
+
text.scan(sentence_regex).each do |s|
|
74
|
+
sentences << s
|
75
|
+
end
|
76
|
+
|
77
|
+
sentences
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.load_json(file_path, env = nil)
|
81
|
+
json = JSON.parse(File.read(file_path))
|
82
|
+
return json if env.nil?
|
83
|
+
return yml['defaults'] if env == 'defaults'
|
84
|
+
yml['defaults'].rmerge(yml[env] || {})
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.load_yaml(file_path, env = nil)
|
88
|
+
yaml = YAML.load_file(file_path)
|
89
|
+
return yaml if env.nil?
|
90
|
+
return yaml['defaults'] if env == 'defaults'
|
91
|
+
yaml['defaults'].rmerge(yaml[env] || {})
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.sign_and_encode_params(params, secret)
|
95
|
+
URI::encode(Base64.encode64(params.to_json))
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.decode_and_verify_params(signed_request, secret)
|
99
|
+
payload = URI::decode(signed_request)
|
100
|
+
payload = Base64.decode64(payload)
|
101
|
+
JSON.parse(payload)
|
102
|
+
rescue Exception => ex
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.split_sentences(paragraph)
|
107
|
+
sentence_regex = /[^.!?\s][^.!?]*(?:[.!?](?![\'"]?\s|$)[^.!?]*)*[.!?]?[\'"]?(?=\s|$)/
|
108
|
+
paragraph.match(sentence_regex)
|
109
|
+
end
|
110
|
+
|
111
|
+
######################################################################
|
112
|
+
# Author: Iain Hecker
|
113
|
+
# reference: http://github.com/iain/http_accept_language
|
114
|
+
######################################################################
|
115
|
+
def self.browser_accepted_locales(request)
|
116
|
+
request.env['HTTP_ACCEPT_LANGUAGE'].split(/\s*,\s*/).collect do |l|
|
117
|
+
l += ';q=1.0' unless l =~ /;q=\d+\.\d+$/
|
118
|
+
l.split(';q=')
|
119
|
+
end.sort do |x,y|
|
120
|
+
raise Tml::Exception.new('Not correctly formatted') unless x.first =~ /^[a-z\-]+$/i
|
121
|
+
y.last.to_f <=> x.last.to_f
|
122
|
+
end.collect do |l|
|
123
|
+
l.first.downcase.gsub(/-[a-z]+$/i) { |x| x.upcase }
|
124
|
+
end
|
125
|
+
rescue
|
126
|
+
[]
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/lib/tml/version.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
|
+
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
|
32
|
+
module Tml
|
33
|
+
VERSION = '4.3.1'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Berkovich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
description: Tml core classes that can be used by any Ruby framework
|
42
|
+
email:
|
43
|
+
- michael@translationexchange.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/tml.rb
|
52
|
+
- lib/tml/api/client.rb
|
53
|
+
- lib/tml/api/post_office.rb
|
54
|
+
- lib/tml/application.rb
|
55
|
+
- lib/tml/base.rb
|
56
|
+
- lib/tml/cache.rb
|
57
|
+
- lib/tml/cache_adapters/file.rb
|
58
|
+
- lib/tml/cache_adapters/memcache.rb
|
59
|
+
- lib/tml/cache_adapters/memory.rb
|
60
|
+
- lib/tml/cache_adapters/redis.rb
|
61
|
+
- lib/tml/config.rb
|
62
|
+
- lib/tml/decorators/base.rb
|
63
|
+
- lib/tml/decorators/default.rb
|
64
|
+
- lib/tml/decorators/html.rb
|
65
|
+
- lib/tml/exception.rb
|
66
|
+
- lib/tml/ext/array.rb
|
67
|
+
- lib/tml/ext/date.rb
|
68
|
+
- lib/tml/ext/fixnum.rb
|
69
|
+
- lib/tml/ext/hash.rb
|
70
|
+
- lib/tml/ext/string.rb
|
71
|
+
- lib/tml/ext/time.rb
|
72
|
+
- lib/tml/generators/cache/base.rb
|
73
|
+
- lib/tml/generators/cache/file.rb
|
74
|
+
- lib/tml/language.rb
|
75
|
+
- lib/tml/language_case.rb
|
76
|
+
- lib/tml/language_case_rule.rb
|
77
|
+
- lib/tml/language_context.rb
|
78
|
+
- lib/tml/language_context_rule.rb
|
79
|
+
- lib/tml/languages/en.json
|
80
|
+
- lib/tml/logger.rb
|
81
|
+
- lib/tml/rules_engine/evaluator.rb
|
82
|
+
- lib/tml/rules_engine/parser.rb
|
83
|
+
- lib/tml/session.rb
|
84
|
+
- lib/tml/source.rb
|
85
|
+
- lib/tml/tokenizers/data.rb
|
86
|
+
- lib/tml/tokenizers/decoration.rb
|
87
|
+
- lib/tml/tokenizers/dom.rb
|
88
|
+
- lib/tml/tokens/data.rb
|
89
|
+
- lib/tml/tokens/method.rb
|
90
|
+
- lib/tml/tokens/transform.rb
|
91
|
+
- lib/tml/translation.rb
|
92
|
+
- lib/tml/translation_key.rb
|
93
|
+
- lib/tml/translator.rb
|
94
|
+
- lib/tml/utils.rb
|
95
|
+
- lib/tml/version.rb
|
96
|
+
homepage: https://github.com/translationexchange/tml
|
97
|
+
licenses:
|
98
|
+
- MIT-LICENSE
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.1
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Tml Core Classes
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|