tml 4.4.4 → 4.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tml/application.rb +1 -0
- data/lib/tml/config.rb +2 -0
- data/lib/tml/decorators/html.rb +2 -3
- data/lib/tml/language.rb +4 -0
- data/lib/tml/source.rb +1 -0
- data/lib/tml/tokenizers/decoration.rb +20 -5
- data/lib/tml/tokens/data.rb +1 -1
- data/lib/tml/tokens/method.rb +1 -1
- data/lib/tml/tokens/transform.rb +1 -1
- data/lib/tml/translation.rb +1 -1
- data/lib/tml/translation_key.rb +6 -5
- data/lib/tml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ee215776a93a3de80da5b0f4f432ea99e44e577
|
4
|
+
data.tar.gz: b2dd1de37941aaef3224de6a2458cbf5cc74c6ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3a8087e25ca982bcc9ed6ed27e74ac53bac437738512bbe1a754f9d23e0ea82e3aaceeae1a6ae425cf53767ff558454a868985b09ff14cbc11a2510ba313a0
|
7
|
+
data.tar.gz: cc3e5c6524a9690e774a31b3aeefeae710a567b67e1e98bd03cf99b3f12799b7c71a4e75b105cc11e0b0fa8c7ab14115a10436d332b631b2f2d849caeac687d6
|
data/lib/tml/application.rb
CHANGED
data/lib/tml/config.rb
CHANGED
@@ -76,6 +76,7 @@ module Tml
|
|
76
76
|
class Config
|
77
77
|
# Configuration Attributes
|
78
78
|
attr_accessor :enabled, :locale, :default_level, :format, :application, :context_rules, :logger, :cache, :default_tokens, :localization
|
79
|
+
attr_accessor :auto_init
|
79
80
|
|
80
81
|
# Used by Rails and Sinatra extensions
|
81
82
|
attr_accessor :current_locale_method, :current_user_method, :translator_options, :i18n_backend
|
@@ -89,6 +90,7 @@ module Tml
|
|
89
90
|
@default_level = 0
|
90
91
|
@format = :html
|
91
92
|
@subdomains = false
|
93
|
+
@auto_init = true
|
92
94
|
|
93
95
|
@locale = {
|
94
96
|
default: 'en',
|
data/lib/tml/decorators/html.rb
CHANGED
@@ -41,11 +41,10 @@ class Tml::Decorators::Html < Tml::Decorators::Base
|
|
41
41
|
# if translation key language is the same as target language - skip decorations
|
42
42
|
return translated_label if translation_key.language == target_language
|
43
43
|
return translated_label unless inline_mode?
|
44
|
-
return translated_label if translation_key.locked? and not Tml.session.current_translator.manager?
|
45
44
|
|
46
45
|
classes = %w(tml_translatable)
|
47
|
-
|
48
|
-
if
|
46
|
+
|
47
|
+
if options[:locked]
|
49
48
|
# must be a manager and enabling locking feature
|
50
49
|
# return translated_label unless Tml.session.current_translator.feature_enabled?(:show_locked_keys)
|
51
50
|
classes << 'tml_locked'
|
data/lib/tml/language.rb
CHANGED
@@ -153,6 +153,10 @@ class Tml::Language < Tml::Base
|
|
153
153
|
return translation_key.translate(self, params[:tokens], params[:options]).tml_translated
|
154
154
|
end
|
155
155
|
|
156
|
+
if options[:dynamic] or Tml.session.block_options[:dynamic]
|
157
|
+
|
158
|
+
end
|
159
|
+
|
156
160
|
source_key = current_source(options)
|
157
161
|
|
158
162
|
source = application.source(source_key, locale)
|
data/lib/tml/source.rb
CHANGED
@@ -44,6 +44,8 @@
|
|
44
44
|
# [link: {count||message}]
|
45
45
|
# [link: {count||person, people}]
|
46
46
|
# [link: {user.name}]
|
47
|
+
# [link] {user.name} [/link]
|
48
|
+
# <link> {user.name} </link>
|
47
49
|
#
|
48
50
|
#######################################################################
|
49
51
|
|
@@ -57,12 +59,14 @@ module Tml
|
|
57
59
|
|
58
60
|
RE_SHORT_TOKEN_START = '\[[\w]*:'
|
59
61
|
RE_SHORT_TOKEN_END = '\]'
|
60
|
-
RE_LONG_TOKEN_START = '\[[\w]*\]'
|
61
|
-
RE_LONG_TOKEN_END = '\[\/[\w]*\]'
|
62
|
-
|
62
|
+
RE_LONG_TOKEN_START = '\[[\w]*\]' # [link]
|
63
|
+
RE_LONG_TOKEN_END = '\[\/[\w]*\]' # [/link]
|
64
|
+
RE_HTML_TOKEN_START = '<[^\>]*>' # <link>
|
65
|
+
RE_HTML_TOKEN_END = '<\/[^\>]*>' # </link>
|
66
|
+
RE_TEXT = '[^\[\]<>]+' # '[\w\s!.:{}\(\)\|,?]*'
|
63
67
|
|
64
68
|
def self.required?(label)
|
65
|
-
label.index('[')
|
69
|
+
label.index('[') or label.index('<')
|
66
70
|
end
|
67
71
|
|
68
72
|
def initialize(text, context = {}, opts = {})
|
@@ -77,6 +81,8 @@ module Tml
|
|
77
81
|
RE_SHORT_TOKEN_END,
|
78
82
|
RE_LONG_TOKEN_START,
|
79
83
|
RE_LONG_TOKEN_END,
|
84
|
+
RE_HTML_TOKEN_START,
|
85
|
+
RE_HTML_TOKEN_END,
|
80
86
|
RE_TEXT].join('|')
|
81
87
|
@fragments = text.scan(/#{re}/)
|
82
88
|
@tokens = []
|
@@ -94,6 +100,11 @@ module Tml
|
|
94
100
|
return parse_tree(token.gsub(/[\[\]]/, ''), :long)
|
95
101
|
end
|
96
102
|
|
103
|
+
if token.match(/#{RE_HTML_TOKEN_START}/)
|
104
|
+
return token if token.index('/>')
|
105
|
+
return parse_tree(token.gsub(/[<>]/, '').split(' ').first, :html)
|
106
|
+
end
|
107
|
+
|
97
108
|
token.to_s
|
98
109
|
end
|
99
110
|
|
@@ -115,6 +126,10 @@ module Tml
|
|
115
126
|
until fragments.first.nil? or fragments.first.match(/#{RE_LONG_TOKEN_END}/)
|
116
127
|
tree << parse
|
117
128
|
end
|
129
|
+
elsif type == :html
|
130
|
+
until fragments.first.nil? or fragments.first.match(/#{RE_HTML_TOKEN_END}/)
|
131
|
+
tree << parse
|
132
|
+
end
|
118
133
|
end
|
119
134
|
|
120
135
|
fragments.shift
|
@@ -196,7 +211,7 @@ module Tml
|
|
196
211
|
end
|
197
212
|
|
198
213
|
def substitute
|
199
|
-
evaluate(parse)
|
214
|
+
evaluate(parse).gsub('[/tml]', '')
|
200
215
|
end
|
201
216
|
|
202
217
|
end
|
data/lib/tml/tokens/data.rb
CHANGED
data/lib/tml/tokens/method.rb
CHANGED
data/lib/tml/tokens/transform.rb
CHANGED
@@ -57,7 +57,7 @@ class Tml::Tokens::Transform < Tml::Tokens::Data
|
|
57
57
|
attr_reader :pipe_separator, :piped_params
|
58
58
|
|
59
59
|
def self.expression
|
60
|
-
/(
|
60
|
+
/(%?\{{1,2}\s*[\w]*\s*(:\s*\w+)*\s*\|\|?[^\{\}\|]+\}{1,2})/
|
61
61
|
end
|
62
62
|
|
63
63
|
def parse_elements
|
data/lib/tml/translation.rb
CHANGED
data/lib/tml/translation_key.rb
CHANGED
@@ -34,7 +34,7 @@ require 'digest/md5'
|
|
34
34
|
|
35
35
|
class Tml::TranslationKey < Tml::Base
|
36
36
|
belongs_to :application, :language
|
37
|
-
attributes :id, :key, :label, :description, :locale, :level
|
37
|
+
attributes :id, :key, :label, :description, :locale, :level
|
38
38
|
has_many :translations # hashed by language
|
39
39
|
|
40
40
|
def initialize(attrs = {})
|
@@ -118,6 +118,7 @@ class Tml::TranslationKey < Tml::Base
|
|
118
118
|
decorator = Tml::Decorators::Base.decorator
|
119
119
|
|
120
120
|
if translation
|
121
|
+
options[:locked] = translation.locked
|
121
122
|
translated_label = substitute_tokens(translation.label, token_values, translation.language, options)
|
122
123
|
return decorator.decorate(translated_label, translation.language, language, self, options)
|
123
124
|
end
|
@@ -164,14 +165,14 @@ class Tml::TranslationKey < Tml::Base
|
|
164
165
|
end
|
165
166
|
|
166
167
|
def substitute_tokens(translated_label, token_values, language, options = {})
|
167
|
-
if Tml::Tokenizers::Data.required?(translated_label)
|
168
|
-
translated_label = Tml::Tokenizers::Data.new(translated_label, token_values, :allowed_tokens => data_tokens_names_map).substitute(language, options)
|
169
|
-
end
|
170
|
-
|
171
168
|
if Tml::Tokenizers::Decoration.required?(translated_label)
|
172
169
|
translated_label = Tml::Tokenizers::Decoration.new(translated_label, token_values, :allowed_tokens => decoration_tokens).substitute
|
173
170
|
end
|
174
171
|
|
172
|
+
if Tml::Tokenizers::Data.required?(translated_label)
|
173
|
+
translated_label = Tml::Tokenizers::Data.new(translated_label, token_values, :allowed_tokens => data_tokens_names_map).substitute(language, options)
|
174
|
+
end
|
175
|
+
|
175
176
|
translated_label
|
176
177
|
end
|
177
178
|
|
data/lib/tml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|