tr8n_client_sdk 3.3.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,45 +1,103 @@
1
1
  <% if Tr8n.config.enabled? %>
2
+
2
3
  <style type="text/css">
3
- .tr8n_fltr {<%=tr8n_style_attribute_tag('float', 'right')%> !important;}
4
- .tr8n_fltl {<%=tr8n_style_attribute_tag('float', 'left')%> !important;}
5
- .tr8n_txtr {<%=tr8n_style_attribute_tag('text-align', 'right')%> !important;}
6
- .tr8n_txtl {<%=tr8n_style_attribute_tag('text-align', 'left')%> !important;}
4
+ .tr8n_fltr {
5
+ <%=tr8n_style_attribute_tag('float', 'right')%> !important;
6
+ }
7
+ .tr8n_fltl {
8
+ <%=tr8n_style_attribute_tag('float', 'left')%> !important;
9
+ }
10
+ .tr8n_txtr {
11
+ <%=tr8n_style_attribute_tag('text-align', 'right')%> !important;
12
+ }
13
+ .tr8n_txtl {
14
+ <%=tr8n_style_attribute_tag('text-align', 'left')%> !important;
15
+ }
7
16
  </style>
8
17
 
9
18
  <script>
10
- (function() {
11
- if (window.tr8n_already_initialized) return;
12
- window.tr8n_already_initialized = true;
19
+ function tr8n_add_css(doc, value, inline) {
20
+ var css = null;
21
+ if (inline) {
22
+ css = doc.createElement('style');
23
+ css.type = 'text/css';
24
+ if (css.styleSheet){
25
+ css.styleSheet.cssText = value;
26
+ } else {
27
+ css.appendChild(document.createTextNode(value));
28
+ }
29
+ } else {
30
+ css = doc.createElement('link');
31
+ css.setAttribute('type', 'text/css');
32
+ css.setAttribute('rel', 'stylesheet');
33
+ css.setAttribute('media', 'screen');
34
+
35
+ if (value.indexOf('//') != -1) {
36
+ css.setAttribute('href', value);
37
+ } else {
38
+ css.setAttribute('href', '<%= tr8n_application.host %>' + value);
39
+ }
40
+ }
41
+ doc.getElementsByTagName('head')[0].appendChild(css);
42
+ return css;
43
+ }
13
44
 
14
- var script = window.document.createElement('script');
15
- script.setAttribute('id', 'tr8n-tools');
45
+ function tr8n_add_script(doc, id, src, onload) {
46
+ var script = doc.createElement('script');
47
+ script.setAttribute('id', id);
16
48
  script.setAttribute('type', 'application/javascript');
17
- script.setAttribute('src', '<%= tr8n_application.tools['javascript'] %>');
49
+ if (src.indexOf('//') != -1) {
50
+ script.setAttribute('src', src);
51
+ } else {
52
+ script.setAttribute('src', '<%= tr8n_application.host %>' + src);
53
+ }
18
54
  script.setAttribute('charset', 'UTF-8');
19
- script.onload = function() {
20
- Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.tools['stylesheet'] %>", false);
21
- Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.css %>", true);
22
- Tr8n.app_key = '<%= tr8n_application.key %>';
23
- Tr8n.host = '<%= tr8n_application.tools['host'] %>';
24
- Tr8n.locale = '<%= tr8n_current_language.locale %>';
25
- Tr8n.sources = [];
26
- <%
27
- if tr8n_application.feature_enabled?(:shortcuts)
28
- tr8n_application.shortcuts.each do |key, script|
29
- %>
30
- shortcut.add('<%=key.html_safe%>', function() {
31
- <%= script.html_safe %>
32
- });
33
- <%
34
- end
35
- end
36
- %>
37
- if (typeof(tr8n_on_ready) === 'function') {
38
- tr8n_on_ready();
39
- }
40
- };
55
+ if (onload) script.onload = onload;
56
+ doc.getElementsByTagName('head')[0].appendChild(script);
57
+ return script;
58
+ }
59
+
60
+ (function() {
61
+ if (window.addEventListener) window.addEventListener('load', tr8n_init, false); // Standard
62
+ else if (window.attachEvent) window.attachEvent('onload', tr8n_init); // Microsoft
63
+ window.setTimeout(function() { // just in case, hit it one more time a second later
64
+ tr8n_init();
65
+ }, 1000);
66
+
67
+ function tr8n_init() {
68
+ if (window.tr8n_already_initialized) return;
69
+ window.tr8n_already_initialized = true;
70
+
71
+ tr8n_add_css(window.document, '/assets/tr8n/tools.css', false);
72
+ tr8n_add_css(window.document, "<%= tr8n_application.css %>", true);
73
+
74
+ tr8n_add_script(window.document, 'tr8n-jssdk', '/assets/tools.js?t=<%=Time.now%>', function() {
75
+ Tr8n.app_key = '<%= tr8n_application.key %>';
76
+ Tr8n.host = '<%= tr8n_application.host %>';
77
+ Tr8n.sources = [];
78
+ Tr8n.default_locale = '<%= tr8n_application.default_locale %>';
79
+ Tr8n.page_locale = '<%= tr8n_current_language.locale %>';
80
+ Tr8n.locale = '<%= tr8n_current_language.locale %>';
41
81
 
42
- window.document.getElementsByTagName('head')[0].appendChild(script);
82
+ <%
83
+ if tr8n_application.feature_enabled?(:shortcuts)
84
+ tr8n_application.shortcuts.each do |key, script|
85
+ %>
86
+ shortcut.add('<%=key.html_safe%>', function() {
87
+ <%= script.html_safe %>
88
+ });
89
+ <%
90
+ end
91
+ end
92
+ %>
93
+
94
+ if (typeof(tr8n_on_ready) === 'function') {
95
+ tr8n_on_ready();
96
+ }
97
+ });
98
+ }
43
99
  })();
44
100
  </script>
101
+
102
+
45
103
  <% end %>
data/config/routes.rb CHANGED
@@ -1,34 +1,2 @@
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
- Rails.application.routes.draw do
33
- get '/tr8n/upgrade' => 'tr8n_client_sdk/cache#upgrade'
1
+ Tr8nClientSdk::Engine.routes.draw do
34
2
  end
@@ -1,14 +1,6 @@
1
1
  #--
2
- # Copyright (c) 2014 Michael Berkovich, TranslationExchange.com
2
+ # Copyright (c) 2010-2013 Michael Berkovich, tr8nhub.com
3
3
  #
4
- # _______ _ _ _ ______ _
5
- # |__ __| | | | | (_) | ____| | |
6
- # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
- # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
- # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
- # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
- # __/ |
11
- # |___/
12
4
  # Permission is hereby granted, free of charge, to any person obtaining
13
5
  # a copy of this software and associated documentation files (the
14
6
  # "Software"), to deal in the Software without restriction, including
@@ -29,16 +21,19 @@
29
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
22
  #++
31
23
 
32
- class String
24
+ namespace :tr8n_client_sdk do
33
25
 
34
- def tr8n_translated
35
- return self if frozen?
36
- @tr8n_translated = true
37
- self.html_safe
26
+ task :init => :environment do
27
+
38
28
  end
39
29
 
40
- def tr8n_translated?
41
- @tr8n_translated
30
+ task :cache do
31
+ require "tr8n_client_sdk/config"
32
+ Tr8n.config = Tr8nClientSdk::Config.new
33
+
34
+ Tr8n.config.init_application
35
+ g = Tr8nCore::Generators::Cache::File.new
36
+ g.run
42
37
  end
43
38
 
44
- end
39
+ end
@@ -1,14 +1,6 @@
1
1
  #--
2
- # Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
2
+ # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
3
3
  #
4
- # _______ _ _ _ ______ _
5
- # |__ __| | | | | (_) | ____| | |
6
- # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
- # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
- # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
- # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
- # __/ |
11
- # |___/
12
4
  # Permission is hereby granted, free of charge, to any person obtaining
13
5
  # a copy of this software and associated documentation files (the
14
6
  # "Software"), to deal in the Software without restriction, including
@@ -1,14 +1,6 @@
1
1
  #--
2
- # Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
2
+ # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
3
3
  #
4
- # _______ _ _ _ ______ _
5
- # |__ __| | | | | (_) | ____| | |
6
- # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
- # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
- # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
- # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
- # __/ |
11
- # |___/
12
4
  # Permission is hereby granted, free of charge, to any person obtaining
13
5
  # a copy of this software and associated documentation files (the
14
6
  # "Software"), to deal in the Software without restriction, including
@@ -34,16 +26,16 @@ module Tr8nClientSdk
34
26
  ############################################################
35
27
  # There are three ways to call the tr method
36
28
  #
37
- # tr(label, desc = '', tokens = {}, options = {})
29
+ # tr(label, desc = "", tokens = {}, options = {})
38
30
  # or
39
31
  # tr(label, tokens = {}, options = {})
40
32
  # or
41
- # tr(:label => label, :description => '', :tokens => {}, :options => {})
33
+ # tr(:label => label, :description => "", :tokens => {}, :options => {})
42
34
  ############################################################
43
- def tr(label, description = '', tokens = {}, options = {})
44
- params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
45
- return params[:label].html_safe if params[:label].tr8n_translated?
35
+ def tr(label, description = "", tokens = {}, options = {})
36
+ return label.html_safe if label.tr8n_translated?
46
37
 
38
+ params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
47
39
  params[:options][:caller] = caller
48
40
 
49
41
  if request
@@ -52,7 +44,7 @@ module Tr8nClientSdk
52
44
  end
53
45
 
54
46
  if Tr8n.config.disabled?
55
- return Tr8n.config.default_language.translate(params[:label], params[:tokens], params[:options]).tr8n_translated.html_safe
47
+ return Tr8n::TranslationKey.substitute_tokens(params[:label], params[:tokens], params[:options]).tr8n_translated.html_safe
56
48
  end
57
49
 
58
50
  # Translate individual sentences
@@ -65,33 +57,32 @@ module Tr8nClientSdk
65
57
  return text.tr8n_translated.html_safe
66
58
  end
67
59
 
68
- Tr8n.session.target_language.translate(params).tr8n_translated.html_safe
60
+ tr8n_current_language.translate(params).tr8n_translated.html_safe
69
61
  rescue Tr8n::Exception => ex
70
- #pp ex, ex.backtrace
71
- Tr8n.logger.error(ex.message)
72
- #Tr8n.logger.error(ex.message + "\n=> " + ex.backtrace.join("\n=> "))
62
+ Tr8n::Logger.error("ERROR: #{label}")
63
+ Tr8n::Logger.error(ex.message + "\n=> " + ex.backtrace.join("\n=> "))
73
64
  label
74
65
  end
75
66
 
76
67
  # for translating labels
77
- def trl(label, description = '', tokens = {}, options = {})
68
+ def trl(label, description = "", tokens = {}, options = {})
78
69
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
79
70
  params[:options][:skip_decorations] = true
80
71
  tr(params)
81
72
  end
82
73
 
83
74
  # flash notice
84
- def trfn(label, desc = '', tokens = {}, options = {})
75
+ def trfn(label, desc = "", tokens = {}, options = {})
85
76
  flash[:trfn] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
86
77
  end
87
78
 
88
79
  # flash error
89
- def trfe(label, desc = '', tokens = {}, options = {})
80
+ def trfe(label, desc = "", tokens = {}, options = {})
90
81
  flash[:trfe] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
91
82
  end
92
83
 
93
84
  # flash warning
94
- def trfw(label, desc = '', tokens = {}, options = {})
85
+ def trfw(label, desc = "", tokens = {}, options = {})
95
86
  flash[:trfw] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
96
87
  end
97
88
 
@@ -99,32 +90,20 @@ module Tr8nClientSdk
99
90
  ## Common methods - wrappers
100
91
  ######################################################################
101
92
 
102
- def tr8n_session
103
- Tr8n.session
104
- end
105
-
106
93
  def tr8n_application
107
- tr8n_session.application
94
+ Tr8n.session.application
108
95
  end
109
96
 
110
97
  def tr8n_current_user
111
- tr8n_session.current_user
98
+ Tr8n.session.current_user
112
99
  end
113
100
 
114
101
  def tr8n_current_translator
115
- tr8n_session.current_translator
116
- end
117
-
118
- def tr8n_current_locale
119
- tr8n_session.current_language.locale
102
+ Tr8n.session.current_translator
120
103
  end
121
104
 
122
105
  def tr8n_current_language
123
- tr8n_session.current_language
124
- end
125
-
126
- def tr8n_language_dir
127
- tr8n_current_language.dir
106
+ Tr8n.session.current_language
128
107
  end
129
108
 
130
109
  end
@@ -1,14 +1,6 @@
1
1
  #--
2
- # Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
2
+ # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
3
3
  #
4
- # _______ _ _ _ ______ _
5
- # |__ __| | | | | (_) | ____| | |
6
- # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
- # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
- # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
- # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
- # __/ |
11
- # |___/
12
4
  # Permission is hereby granted, free of charge, to any person obtaining
13
5
  # a copy of this software and associated documentation files (the
14
6
  # "Software"), to deal in the Software without restriction, including
@@ -33,18 +25,10 @@ module Tr8nClientSdk
33
25
  module ActionControllerExtension
34
26
 
35
27
  def self.included(base)
36
- base.send(:include, Tr8nClientSdk::ActionCommonMethods)
37
- base.send(:include, InstanceMethods)
28
+ base.send(:include, Tr8nClientSdk::ActionCommonMethods)
29
+ base.send(:include, InstanceMethods)
38
30
  base.before_filter :tr8n_init_client_sdk
39
31
  base.after_filter :tr8n_reset_client_sdk
40
- if defined? base.rescue_from
41
- base.rescue_from 'Tr8n::Exception' do |e|
42
- Tr8n.logger.error(e)
43
- Tr8n.logger.error(e.backtrace)
44
- Tr8n.session.reset
45
- raise e
46
- end
47
- end
48
32
  end
49
33
 
50
34
  module InstanceMethods
@@ -60,7 +44,7 @@ module Tr8nClientSdk
60
44
  end
61
45
  Tr8n.config.default_locale
62
46
  end
63
-
47
+
64
48
  # Overwrite this method in a controller to assign a custom source for all views
65
49
  def tr8n_source
66
50
  "/#{controller_name}/#{action_name}"
@@ -71,47 +55,19 @@ module Tr8nClientSdk
71
55
  # Overwrite this method in a controller to assign a custom component for all views
72
56
  def tr8n_component
73
57
  nil
74
- end
75
-
76
- def tr8n_cookie_name
77
- "tr8n_#{tr8n_application.key}"
78
- end
79
-
80
- def tr8n_cookie
81
- request.cookies[tr8n_cookie_name]
82
- end
83
-
84
- def tr8n_cookie_params
85
- @tr8n_cookie_params ||= begin
86
- if tr8n_cookie
87
- cookie_params = Tr8n::Utils.decode_and_verify_params(tr8n_cookie, tr8n_application.secret)
88
- Tr8n.logger.info(cookie_params.inspect)
89
- cookie_params
90
- else
91
- {}
92
- end
93
- end
94
- end
58
+ end
95
59
 
96
- def tr8n_translator_locale
97
- tr8n_cookie_params["locale"]
98
- end
99
-
100
-
101
- def tr8n_locale
60
+ def tr8n_init_current_locale
102
61
  self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method
103
62
  rescue
104
- # fallback onto the cookie params from the service
105
- return tr8n_translator_locale if tr8n_translator_locale
106
-
107
63
  # fallback to the default session based locale implementation
108
64
  # choose the first language from the accepted languages header
109
65
  session[:locale] = tr8n_user_preferred_locale unless session[:locale]
110
66
  session[:locale] = params[:locale] if params[:locale]
111
- session[:locale] || Tr8n.config.default_locale
67
+ session[:locale]
112
68
  end
113
69
 
114
- def tr8n_user
70
+ def tr8n_init_current_user
115
71
  self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method
116
72
  rescue
117
73
  nil
@@ -120,26 +76,39 @@ module Tr8nClientSdk
120
76
  def tr8n_init_client_sdk
121
77
  return if Tr8n.config.disabled?
122
78
 
79
+ Tr8n.logger.info("Initializing request...")
123
80
  @tr8n_started_at = Time.now
124
81
 
125
- Tr8n.session.init(
126
- :cookies => request.cookies,
127
- :locale => tr8n_locale,
128
- :user => tr8n_user,
129
- :source => tr8n_source,
130
- :component => tr8n_component
131
- )
82
+ Tr8n.session.init
83
+
84
+ translator = nil
132
85
 
133
- I18n.enforce_available_locales = false
134
- I18n.locale = Tr8n.session.current_language.locale
86
+ cookie_name = "tr8n_#{tr8n_application.key}"
87
+ if request.cookies[cookie_name]
88
+ Tr8n.logger.info("Cookie exists:")
89
+ cookie_params = Tr8n::Utils.decode_and_verify_params(request.cookies[cookie_name], tr8n_application.secret)
90
+ Tr8n.logger.info(cookie_params.inspect)
91
+ locale = cookie_params["locale"]
92
+ translator = Tr8n::Translator.new(cookie_params["translator"].merge(:application => tr8n_application)) unless cookie_params["translator"].nil?
93
+ else
94
+ Tr8n.logger.info("Cookie does not exist")
95
+ end
96
+
97
+ Tr8n.session.current_user = tr8n_init_current_user
98
+ Tr8n.session.current_translator = translator
99
+ Tr8n.session.current_language = tr8n_application.language(locale || tr8n_init_current_locale)
100
+ Tr8n.session.current_source = tr8n_source
101
+ Tr8n.session.current_component = tr8n_component
135
102
  end
136
103
 
137
104
  def tr8n_reset_client_sdk
138
- return if Tr8n.config.disabled?
139
105
  @tr8n_finished_at = Time.now
106
+
107
+ Tr8n.logger.info("Resetting request...")
140
108
  tr8n_application.submit_missing_keys
141
109
  Tr8n.session.reset
142
- Tr8n.logger.info("Request took #{@tr8n_finished_at - @tr8n_started_at} mls") if @tr8n_started_at
110
+
111
+ Tr8n.logger.info("Request took #{@tr8n_finished_at - @tr8n_started_at} mls")
143
112
  end
144
113
 
145
114
  end
@@ -1,14 +1,6 @@
1
1
  #--
2
- # Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
2
+ # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
3
3
  #
4
- # _______ _ _ _ ______ _
5
- # |__ __| | | | | (_) | ____| | |
6
- # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
7
- # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
8
- # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
9
- # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
10
- # __/ |
11
- # |___/
12
4
  # Permission is hereby granted, free of charge, to any person obtaining
13
5
  # a copy of this software and associated documentation files (the
14
6
  # "Software"), to deal in the Software without restriction, including
@@ -33,15 +25,6 @@ module Tr8nClientSdk
33
25
  module ActionViewExtension
34
26
  extend ActiveSupport::Concern
35
27
 
36
- def trh(tokens = {}, options = {}, &block)
37
- return '' unless block_given?
38
-
39
- label = capture(&block)
40
-
41
- tokenizer = Tr8n::Tokenizers::Dom.new(tokens, options)
42
- tokenizer.translate(label).html_safe
43
- end
44
-
45
28
  def tr8n_options_for_select(options, selected = nil, description = nil, lang = Tr8n.session.current_language)
46
29
  options_for_select(options.tro(description), selected)
47
30
  end
@@ -58,14 +41,14 @@ module Tr8nClientSdk
58
41
  def tr8n_language_flag_tag(lang = tr8n_current_language, opts = {})
59
42
  return "" unless tr8n_application.feature_enabled?(:language_flags)
60
43
  html = image_tag(lang.flag_url, :style => "vertical-align:middle;", :title => lang.native_name)
61
- html << "&nbsp;".html_safe
44
+ html << "&nbsp;".html_safe
62
45
  html.html_safe
63
46
  end
64
47
 
65
48
  def tr8n_language_name_tag(lang = tr8n_current_language, opts = {})
66
49
  show_flag = opts[:flag].nil? ? true : opts[:flag]
67
50
  name_type = opts[:name].nil? ? :full : opts[:name] # :full, :native, :english, :locale
68
- linked = opts[:linked].nil? ? true : opts[:linked]
51
+ linked = opts[:linked].nil? ? true : opts[:linked]
69
52
 
70
53
  html = "<span style='white-space: nowrap'>"
71
54
  html << tr8n_language_flag_tag(lang, opts) if show_flag
@@ -84,25 +67,24 @@ module Tr8nClientSdk
84
67
  end
85
68
 
86
69
  def tr8n_language_selector_tag(opts = {})
87
- return unless Tr8n.config.enabled?
88
70
  render(:partial => '/tr8n_client_sdk/tags/language_selector', :locals => {:opts => opts})
89
71
  end
90
72
 
91
73
  def tr8n_language_strip_tag(opts = {})
92
74
  opts[:flag] = opts[:flag].nil? ? false : opts[:flag]
93
- opts[:name] = opts[:name].nil? ? :native : opts[:name]
94
- opts[:linked] = opts[:linked].nil? ? true : opts[:linked]
95
- opts[:javascript] = opts[:javascript].nil? ? false : opts[:javascript]
75
+ opts[:name] = opts[:name].nil? ? :native : opts[:name]
76
+ opts[:linked] = opts[:linked].nil? ? true : opts[:linked]
77
+ opts[:javascript] = opts[:javascript].nil? ? false : opts[:javascript]
96
78
 
97
- render(:partial => '/tr8n_client_sdk/tags/language_strip', :locals => {:opts => opts})
79
+ render(:partial => '/tr8n_client_sdk/tags/language_strip', :locals => {:opts => opts})
98
80
  end
99
81
 
100
82
  def tr8n_flashes_tag(opts = {})
101
- render(:partial => '/tr8n_client_sdk/tags/flashes', :locals => {:opts => opts})
83
+ render(:partial => '/tr8n_client_sdk/tags/flashes', :locals => {:opts => opts})
102
84
  end
103
85
 
104
86
  def tr8n_scripts_tag(opts = {})
105
- render(:partial => '/tr8n_client_sdk/tags/scripts', :locals => {:opts => opts})
87
+ render(:partial => '/tr8n_client_sdk/tags/scripts', :locals => {:opts => opts})
106
88
  end
107
89
 
108
90
  def tr8n_select_month(date, options = {}, html_options = {})
@@ -118,16 +100,16 @@ module Tr8nClientSdk
118
100
  return ""
119
101
  end
120
102
 
121
- Tr8n.session.push_block_options(opts)
103
+ Thread.current[:block_options] ||= []
104
+ Thread.current[:block_options].push(opts)
122
105
 
123
106
  if block_given?
124
107
  ret = capture(&block)
125
108
  end
126
109
 
127
- Tr8n.session.pop_block_options
110
+ Thread.current[:block_options].pop
128
111
  ret
129
112
  end
130
- alias_method :tr8n_block, :tr8n_with_options_tag
131
113
 
132
114
  def tr8n_when_string_tag(time, opts = {})
133
115
  elapsed_seconds = Time.now - time
@@ -137,12 +119,12 @@ module Tr8nClientSdk
137
119
  tr('a moment ago', 'Time reference')
138
120
  elsif elapsed_seconds < 55.minutes
139
121
  elapsed_minutes = (elapsed_seconds / 1.minute).to_i
140
- tr('{minutes || minute} ago', 'Time reference', :minutes => elapsed_minutes)
122
+ tr("{minutes||minute} ago", 'Time reference', :minutes => elapsed_minutes)
141
123
  elsif elapsed_seconds < 1.75.hours
142
- tr('about an hour ago', 'Time reference')
124
+ tr("about an hour ago", 'Time reference')
143
125
  elsif elapsed_seconds < 12.hours
144
126
  elapsed_hours = (elapsed_seconds / 1.hour).to_i
145
- tr('{hours || hour} ago', 'Time reference', :hours => elapsed_hours)
127
+ tr("{hours||hour} ago", 'Time reference', :hours => elapsed_hours)
146
128
  elsif time.today_in_time_zone?
147
129
  display_time(time, :time_am_pm)
148
130
  elsif time.yesterday_in_time_zone?
@@ -150,39 +132,27 @@ module Tr8nClientSdk
150
132
  elsif elapsed_seconds < 5.days
151
133
  time.tr(:day_time).gsub('/ ', '/').sub(/^[0:]*/,"")
152
134
  elsif time.same_year_in_time_zone?
153
- time.tr(:monthname_abbr_time).gsub('/ ', '/').sub(/^[0:]*/, '')
135
+ time.tr(:monthname_abbr_time).gsub('/ ', '/').sub(/^[0:]*/,"")
154
136
  else
155
- time.tr(:monthname_abbr_year_time).gsub('/ ', '/').sub(/^[0:]*/, '')
137
+ time.tr(:monthname_abbr_year_time).gsub('/ ', '/').sub(/^[0:]*/,"")
156
138
  end
157
139
  end
158
-
159
- def tr8n_url_tag(path)
160
- tr8n_application.url_for(path)
161
- end
162
-
140
+
163
141
  ######################################################################
164
142
  ## Language Direction Support
165
143
  ######################################################################
166
144
 
167
145
  def tr8n_style_attribute_tag(attr_name = 'float', default = 'right', lang = tr8n_current_language)
168
- return "#{attr_name}:#{default}".html_safe if Tr8n.config.disabled?
169
146
  "#{attr_name}:#{lang.align(default)}".html_safe
170
147
  end
171
148
 
172
149
  def tr8n_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tr8n_current_language)
173
- return "#{attr_name}-#{default}:#{value}".html_safe if Tr8n.config.disabled?
174
150
  "#{attr_name}-#{lang.align(default)}:#{value}".html_safe
175
151
  end
176
152
 
177
153
  def tr8n_dir_attribute_tag(lang = tr8n_current_language)
178
- return "dir='ltr'" if Tr8n.config.disabled?
179
154
  "dir='#{lang.dir}'".html_safe
180
155
  end
181
156
 
182
- def tr8n_lang_attribute_tag(lang = tr8n_current_language)
183
- return "lang='en-US'" if Tr8n.config.disabled?
184
- "lang='#{lang.locale}'".html_safe
185
- end
186
-
187
157
  end
188
158
  end