tml-rails 5.0.1 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2088405b5d3e687320118711c6d8af1da0a6e512
4
- data.tar.gz: 056a6c51fb7ccfb609eb8c303dd937aaffa517ef
3
+ metadata.gz: c55b2155d5864d1fcd05e6f0fa8ec005b00336af
4
+ data.tar.gz: 4e22781c61854eec7e9221f0904d970b214ce954
5
5
  SHA512:
6
- metadata.gz: daf41e9d10c5e54cf2a78be03c65de63ea3cd844b4fa1554a6c02556ce0d4e1f383c13789c65518413a2d45441b8f029ee2afd25f618b1312e01ecef1e99b725
7
- data.tar.gz: 1d26cb1bd823edcbcd39072ebf0f5561313e1b561786f00d16c4f9499ca73ac1866e1508032c569504a0f94ba9cf43c5346ae23ca8bd2d6b21d30f8eb4219242
6
+ metadata.gz: 6ca9668d6855391a64a53d80179c481c02242ded5147637307e0bb926a67d78638e8f7d587eafc5e6ce027b681523487c13e64263244abaea9c8ab062b07bbd9
7
+ data.tar.gz: e5afe0332d5f5e249f34a0b61aa7623b994b92b490b30cc7b69c22de93c5e254a1240f88a2e830ab0879b4bd3e7d0ec38f2bc172b3922fa208d4a8f87d13d82e
data/README.md CHANGED
@@ -40,6 +40,7 @@ config/initializers/tml.rb
40
40
  ```ruby
41
41
  Tml.configure do |config|
42
42
  config.application = {
43
+ key: YOUR_APPLICATION_KEY,
43
44
  token: YOUR_APPLICATION_TOKEN,
44
45
  }
45
46
  config.cache = {
@@ -264,7 +265,7 @@ And the i18n will use Translation Exchange as the backend for your translations.
264
265
  <%= tr("This is a nested key") %>
265
266
  ```
266
267
 
267
- The above calls are equivalent.
268
+ The above calls are equivalent.
268
269
 
269
270
 
270
271
  Logging
@@ -384,4 +385,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
384
385
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
385
386
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
386
387
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
387
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
388
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -7,36 +7,11 @@
7
7
  <%= tml_application.css %>
8
8
  </style>
9
9
 
10
- <script>
11
- (function() {
12
- if (window.tml_already_initialized) return;
13
- window.tml_already_initialized = true;
14
-
15
- var script = window.document.createElement('script');
16
- script.setAttribute('id', 'tml-tools');
17
- script.setAttribute('type', 'application/javascript');
18
- script.setAttribute('src', '<%= tml_application.tools['javascript'] %>');
19
- script.setAttribute('charset', 'UTF-8');
20
- script.onload = function() {
21
- Tml.Utils.insertCSS(window.document, "<%= tml_application.tools['stylesheet'] %>", false);
22
- Tml.app_key = '<%= tml_application.key %>';
23
- Tml.host = '<%= tml_application.tools['host'] %>';
24
- Tml.locale = '<%= tml_current_language.locale %>';
25
- Tml.current_source = '<%= tml_current_source %>';
26
- <%
27
- if tml_application.feature_enabled?(:shortcuts)
28
- tml_application.shortcuts.each do |key, script|
29
- %>
30
- shortcut.add('<%=key.html_safe%>', function() {<%= script.html_safe %>});
31
- <%
32
- end
33
- end
34
- %>
35
- if (typeof(tml_on_ready) === 'function') {
36
- tml_on_ready();
37
- }
38
- };
39
- window.document.getElementsByTagName('head')[0].appendChild(script);
40
- })();
41
- </script>
10
+ <% if Tml.config.respond_to?(:agent) and Tml.config.agent and Tml.config.agent[:enabled] %>
11
+ <% if Tml.config.agent[:type].to_s == 'agent' %>
12
+ <%= render(:partial => '/tml_rails/tags/scripts_agent') %>
13
+ <% else %>
14
+ <%= render(:partial => '/tml_rails/tags/scripts_tools') %>
15
+ <% end %>
16
+ <% end %>
42
17
  <% end %>
@@ -0,0 +1,16 @@
1
+ <script>
2
+ <%
3
+ agent_host = Tml.config.agent[:host] || 'https://cdn.translationexchange.com/tools/agent/' + (Tml.config.agent[:version] || 'stable') + '/agent.min.js'
4
+ %>
5
+ (function() {
6
+ var script = window.document.createElement('script');
7
+ script.setAttribute('id', 'tml-agent');
8
+ script.setAttribute('type', 'application/javascript');
9
+ script.setAttribute('src', '<%= agent_host %>');
10
+ script.setAttribute('charset', 'UTF-8');
11
+ script.onload = function() {
12
+ Trex.init("<%=tml_application.key%>", <%=Tml.config.agent.to_json.html_safe%>);
13
+ };
14
+ window.document.getElementsByTagName('head')[0].appendChild(script);
15
+ })();
16
+ </script>
@@ -0,0 +1,32 @@
1
+ <script>
2
+ (function() {
3
+ if (window.tml_already_initialized) return;
4
+ window.tml_already_initialized = true;
5
+
6
+ var script = window.document.createElement('script');
7
+ script.setAttribute('id', 'tml-tools');
8
+ script.setAttribute('type', 'application/javascript');
9
+ script.setAttribute('src', '<%= tml_application.tools['javascript'] %>');
10
+ script.setAttribute('charset', 'UTF-8');
11
+ script.onload = function() {
12
+ Tml.Utils.insertCSS(window.document, "<%= tml_application.tools['stylesheet'] %>", false);
13
+ Tml.app_key = '<%= tml_application.key %>';
14
+ Tml.host = '<%= tml_application.tools['host'] %>';
15
+ Tml.locale = '<%= tml_current_language.locale %>';
16
+ Tml.current_source = '<%= tml_current_source %>';
17
+ <%
18
+ if tml_application.feature_enabled?(:shortcuts)
19
+ tml_application.shortcuts.each do |key, script|
20
+ %>
21
+ shortcut.add('<%=key.html_safe%>', function() {<%= script.html_safe %>});
22
+ <%
23
+ end
24
+ end
25
+ %>
26
+ if (typeof(tml_on_ready) === 'function') {
27
+ tml_on_ready();
28
+ }
29
+ };
30
+ window.document.getElementsByTagName('head')[0].appendChild(script);
31
+ })();
32
+ </script>
@@ -49,30 +49,38 @@ module I18n
49
49
  end
50
50
 
51
51
  def translate(locale, key, options = {})
52
- super(locale, key, options).html_safe
52
+ translation = super(locale, key, options)
53
+ translation.is_a?(String) ? translation.html_safe : translation
54
+ end
55
+
56
+ def convert_to_tml(str)
57
+ str.gsub('%{', '{')
53
58
  end
54
59
 
55
60
  def lookup(locale, key, scope = [], options = {})
56
- #pp ''
57
- #pp [locale, key, scope, options]
61
+ # pp [locale, key, scope, options]
58
62
 
59
63
  default_key = super(application.default_locale, key, scope, options)
64
+ return default_key if key.to_s.match(/^(support|i18n)/)
60
65
 
61
- #pp default_key
66
+ if default_key.nil?
67
+ default_key = key.to_s.gsub('_', ' ').capitalize
68
+ end
62
69
 
63
70
  default_key ||= key
64
71
  if default_key.is_a?(String)
65
- translated_key = default_key.gsub('%{', '{')
66
- translated_key = application.language(locale.to_s).translate(translated_key, options, options)
72
+ translated_key = application.language(locale.to_s).translate(convert_to_tml(default_key), options, options)
67
73
  elsif default_key.is_a?(Hash)
68
74
  translated_key = {}
75
+
69
76
  default_key.each do |key, value|
70
- value = value.gsub('%{', '{')
71
- translated_key[key] = application.language(locale.to_s).translate(value, options, options)
77
+ if value.is_a?(String)
78
+ value = application.language(locale.to_s).translate(convert_to_tml(value), options, options)
79
+ end
80
+ translated_key[key] = value
72
81
  end
73
82
  end
74
83
 
75
- #pp translated_key
76
84
  translated_key
77
85
  end
78
86
 
@@ -65,10 +65,14 @@ module TmlRails
65
65
  self.class.name
66
66
  end
67
67
 
68
+ def tml_cookie_name
69
+ Tml::Utils.cookie_name(Tml.config.application[:key])
70
+ end
71
+
68
72
  # Returns data from cookie set by the agent
69
73
  def tml_cookie
70
74
  @tml_cookie ||= begin
71
- cookie = cookies[Tml::Utils.cookie_name(Tml.config.application[:key])]
75
+ cookie = cookies[tml_cookie_name]
72
76
  if cookie.blank?
73
77
  {}
74
78
  else
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module TmlRails
33
- VERSION = '5.0.1'
33
+ VERSION = '5.1.1'
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.1.1
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-09-08 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,8 @@ files:
59
59
  - app/views/tml_rails/tags/_language_strip.html.erb
60
60
  - app/views/tml_rails/tags/_powered_by_trex.html.erb
61
61
  - app/views/tml_rails/tags/_scripts.html.erb
62
+ - app/views/tml_rails/tags/_scripts_agent.html.erb
63
+ - app/views/tml_rails/tags/_scripts_tools.html.erb
62
64
  - config/routes.rb
63
65
  - lib/i18n/backend/tml.rb
64
66
  - lib/tasks/templates/tml.rb