tml-rails 4.4.1 → 4.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c160510b6789f81b1b1851264330c2940c4a5d40
4
- data.tar.gz: 4ca5ca0a5a41ff31480bb230dbfd90bc595ba402
3
+ metadata.gz: 2e992a68bd9ca23d3a6c095d44db4d4cf4e0bb77
4
+ data.tar.gz: 1a7847dfb32417c88636343cb4570fcd18842067
5
5
  SHA512:
6
- metadata.gz: 0b0b11adeeee73c5ffd57ba1bda1e01a90cd22303dd6066c82fdfc60a2b0df00d73b3f86dc9309365a27788101a40ec7584534347aeb30413fa7073e187f30fc
7
- data.tar.gz: d92eaf0a10c479498fceba9432b05e7cc7eed772311c42de7648ee28192fad8f53d476d0e88225556d7cf7afffa21ef492d630dcab6cf2f08fb3b13575d18635
6
+ metadata.gz: f1c837e64efcdf9136754b9b0d4ad25576bfac7c9c215cf02c2adbf95ec020fe24868438a3081802428293e8f700bb156cc741379f7ab9771123d72ea51e62b6
7
+ data.tar.gz: e57f7967637af87ffa84a1292892c696e517cafdc47e32db0d6f89c4e859ad709f226d598aa6257e7b98fc3dab239835de8794737baaf06a4142835302178aae
data/README.md CHANGED
@@ -43,8 +43,8 @@ Tml.configure do |config|
43
43
  :token => YOUR_APPLICATION_TOKEN,
44
44
  }
45
45
  config.cache = {
46
- :adapter => 'rails',
47
- :version => 1
46
+ :enablec => true,
47
+ :adapter => 'rails'
48
48
  }
49
49
  end
50
50
  ```
@@ -82,8 +82,7 @@ config.cache_store = :redis_store, {
82
82
  :host => 'localhost',
83
83
  :port => 6379,
84
84
  :db => 0,
85
- :namespace => 'my_cache',
86
- :expires_in => 90.minutes
85
+ :namespace => 'my_cache'
87
86
  }
88
87
  ```
89
88
 
@@ -100,8 +99,7 @@ config/initializers/tml.rb
100
99
  ```ruby
101
100
  config.cache = {
102
101
  :enabled => true,
103
- :adapter => 'rails',
104
- :version => 1
102
+ :adapter => 'rails'
105
103
  }
106
104
  ```
107
105
 
@@ -112,9 +110,7 @@ config.cache = {
112
110
  :enabled => true,
113
111
  :adapter => 'memcache',
114
112
  :host => 'localhost:11211',
115
- :namespace => 'translations',
116
- :version => 1,
117
- :timeout => 3600
113
+ :namespace => 'translations'
118
114
  }
119
115
  ```
120
116
 
@@ -127,9 +123,7 @@ config.cache = {
127
123
  :host => 'localhost',
128
124
  :port => 6379,
129
125
  :password => 'password',
130
- :namespace => 'translations',
131
- :version => 1,
132
- :timeout => 3600
126
+ :namespace => 'translations'
133
127
  }
134
128
  ```
135
129
 
@@ -160,26 +154,16 @@ config.cache = {
160
154
  :enabled => true,
161
155
  :adapter => 'file',
162
156
  :path => 'config/tml',
163
- :version => 'current',
164
- :segmented => false
157
+ :version => 'current'
165
158
  }
166
159
  ```
167
160
 
168
- If you set ':segmented' to 'true', the cache will be generated for each source in your application. Otherwise, a single cache file will be generated per language for the entire application.
169
-
170
- The file based cache must be generated before you deploy your application using the following command:
161
+ The file based cache can be generated from your current release using the following command:
171
162
 
172
163
  ```sh
173
164
  $ bundle exec rake tml:cache:generate
174
165
  ```
175
166
 
176
- You can also rollback to the previous file cache using:
177
-
178
- ```sh
179
- $ bundle exec rake tml:cache:rollback
180
- ```
181
-
182
-
183
167
  Integration
184
168
  ===================================
185
169
 
@@ -241,7 +225,7 @@ you can simply use:
241
225
  "Hello World".translate
242
226
  ```
243
227
 
244
- Learn more about TML at: http://TranslationExchange.com/docs
228
+ Learn more about TML at: http://translationexchange.com/docs
245
229
 
246
230
 
247
231
  I18n fallback
@@ -33,9 +33,16 @@ module TmlRails
33
33
  class ToolsController < ApplicationController
34
34
 
35
35
  def upgrade
36
- if params[:access_token] == Tml.config.access_token
36
+ if Tml.config.invalidator[:auth].is_a?(Proc)
37
+ authorized = Tml.config.invalidator[:auth].call(request)
38
+ else
39
+ authorized = params[:access_token] == Tml.config.access_token
40
+ end
41
+
42
+ if authorized
37
43
  Tml.cache.upgrade_version
38
44
  end
45
+
39
46
  redirect_back
40
47
  end
41
48
 
@@ -3,16 +3,18 @@
3
3
  opts[:class] ||= 'dropdown'
4
4
  %>
5
5
 
6
-
7
6
  <style>
8
7
  .trex-dropdown {
9
8
  text-align:<%= tml_current_language.align("left") %>;
10
9
  }
11
-
12
10
  .trex-dropdown .trex-dropdown-menu {
13
11
  min-width:200px;
14
12
  }
15
-
13
+ .trex-native-name {
14
+ padding: 0px 5px;
15
+ color: #ccc;
16
+ font-size: 10px;
17
+ }
16
18
  .trex-dropdown .trex-dropdown-footer {
17
19
  font-size:10px;
18
20
  color:#ccc;
@@ -24,11 +26,13 @@
24
26
  border-bottom-left-radius: 5px;
25
27
  border-bottom-right-radius: 5px;
26
28
  }
27
-
28
29
  </style>
29
30
 
30
31
 
31
- <<%= opts[:element] %> class="trex-dropdown <%= opts[:class] %>" style="<%= opts[:style] %>">
32
+ <% if opts[:element] %>
33
+ <<%= opts[:element] %> class="trex-language-selector trex-dropdown <%= opts[:class] %>" style="<%= opts[:style] %>">
34
+ <% end %>
35
+
32
36
  <a href="#" role="button" class="<%= opts[:class] || 'dropdown' %>-toggle" data-toggle="dropdown" dir="<%= tml_current_language.dir %>">
33
37
  <%= tml_language_name_tag(tml_current_language, opts) %>
34
38
  </a>
@@ -38,8 +42,14 @@
38
42
  <% tml_application.languages.each do |lang| %>
39
43
 
40
44
  <li dir="<%= tml_current_language.dir %>">
41
- <%=link_to({:locale => lang.locale}) do %>
42
- <%= tml_language_name_tag(lang, opts) %>
45
+ <% if Tml.config.locale[:subdomain] %>
46
+ <%=link_to(tml_subdomain_locale_url(lang.locale)) do %>
47
+ <%= tml_language_name_tag(lang, opts) %>
48
+ <% end %>
49
+ <% else %>
50
+ <%=link_to({:locale => lang.locale}) do %>
51
+ <%= tml_language_name_tag(lang, opts) %>
52
+ <% end %>
43
53
  <% end %>
44
54
  </li>
45
55
 
@@ -62,5 +72,8 @@
62
72
  </a>
63
73
  </div>
64
74
  </ul>
65
- </<%= opts[:element] %>>
75
+
76
+ <% if opts[:element] %>
77
+ </<%= opts[:element] %>>
78
+ <% end %>
66
79
 
@@ -1,11 +1,15 @@
1
1
  <%= render(:partial => '/tml_rails/tags/language_selector_js') %>
2
2
 
3
+ <% if opts[:element] %>
4
+ <<%= opts[:element] %> class="trex-language-selector <%= opts[:class] %>" style="<%= opts[:style] %>">
5
+ <% end %>
6
+
3
7
  <select id="tml_language_selector" onchange="tml_change_locale(this.options[this.selectedIndex].value)" style="<%=opts[:style]%>" class="<%=opts[:class]%>">
4
8
  <% tml_application.languages.each do |lang| %>
5
9
  <option dir='ltr' value="<%=lang.locale%>" <%="selected" if lang.locale == tml_current_locale %>>
6
- <% if opts[:language] == :native %>
10
+ <% if opts[:language].to_sym == :native %>
7
11
  <%= lang.native_name %>
8
- <% elsif opts[:language] == :english %>
12
+ <% elsif opts[:language].to_sym == :english %>
9
13
  <%= lang.english_name %>
10
14
  <% else %>
11
15
  <%= lang.english_name %>
@@ -13,3 +17,8 @@
13
17
  </option>
14
18
  <% end %>
15
19
  </select>
20
+
21
+ <% if opts[:element] %>
22
+ </<%= opts[:element] %>>
23
+ <% end %>
24
+
@@ -0,0 +1,19 @@
1
+ <% if opts[:element] %>
2
+ <<%= opts[:element] %> class="trex-language-selector <%= opts[:class] %>" style="<%= opts[:style] %>">
3
+ <% end %>
4
+
5
+ <div style="<%=opts[:style]%>" class="trex-language-selector <%=opts[:class]%>">
6
+
7
+ <% tml_application.languages.each_with_index do |lang, index| %>
8
+
9
+ <%= link_to(params.merge(:locale => lang.locale), :style => (opts[:style] || 'padding-right:5px;text-decoration:none'), :class => opts[:class]) do %>
10
+ <%= image_tag(lang.flag_url) %>
11
+ <% end %>
12
+
13
+ <% end %>
14
+
15
+ </div>
16
+
17
+ <% if opts[:element] %>
18
+ </<%= opts[:element] %>>
19
+ <% end %>
data/config/routes.rb CHANGED
@@ -30,5 +30,9 @@
30
30
  #++
31
31
 
32
32
  Rails.application.routes.draw do
33
- get '/tml/upgrade' => 'tml_rails/tools#upgrade'
33
+
34
+ if Tml.config.invalidator and Tml.config.invalidator[:enabled]
35
+ get Tml.config.invalidator[:path] => 'tml_rails/tools#upgrade'
36
+ end
37
+
34
38
  end
@@ -31,12 +31,14 @@
31
31
 
32
32
  class String
33
33
 
34
+ # marks the string as translated and safe at the same time
34
35
  def tml_translated
35
36
  return self if frozen?
36
37
  @tml_translated = true
37
38
  self.html_safe
38
39
  end
39
40
 
41
+ # indicates whether the string has been translated or not
40
42
  def tml_translated?
41
43
  @tml_translated
42
44
  end
@@ -127,5 +127,17 @@ module TmlRails
127
127
  tml_current_language.dir
128
128
  end
129
129
 
130
+ def tml_subdomain_locale_url(locale = tml_current_locale)
131
+ uri = URI::parse(request.url)
132
+ host = uri.host.split('.')
133
+ if host.count == 2
134
+ host.unshift(locale)
135
+ else
136
+ host[0] = locale
137
+ end
138
+ uri.host = host.join('.')
139
+ uri.to_s
140
+ end
141
+
130
142
  end
131
143
  end
@@ -35,8 +35,8 @@ module TmlRails
35
35
  def self.included(base)
36
36
  base.send(:include, TmlRails::ActionCommonMethods)
37
37
  base.send(:include, InstanceMethods)
38
- base.before_filter :tml_init_client_sdk
39
- base.after_filter :tml_reset_client_sdk
38
+ base.before_filter :tml_init
39
+ base.after_filter :tml_reset
40
40
  if defined? base.rescue_from
41
41
  base.rescue_from 'Tml::Exception' do |e|
42
42
  Tml.logger.error(e)
@@ -68,7 +68,7 @@ module TmlRails
68
68
  self.class.name
69
69
  end
70
70
 
71
- def tml_init_client_sdk
71
+ def tml_init
72
72
  return if Tml.config.disabled?
73
73
 
74
74
  @tml_started_at = Time.now
@@ -95,6 +95,7 @@ module TmlRails
95
95
 
96
96
  unless tml_session_params[:locale]
97
97
  tml_session_params.merge!(:cookies => cookies)
98
+ params[:locale] = request.subdomain if Tml.config.locale[:subdomain]
98
99
  tml_session_params.merge!(:change_locale => true) if params[:locale]
99
100
  tml_session_params.merge!(:locale => params[:locale] || tml_user_preferred_locale)
100
101
  end
@@ -114,7 +115,7 @@ module TmlRails
114
115
  end
115
116
  end
116
117
 
117
- def tml_reset_client_sdk
118
+ def tml_reset
118
119
  return if Tml.config.disabled?
119
120
  @tml_finished_at = Time.now
120
121
  tml_application.submit_missing_keys
@@ -46,15 +46,6 @@ module TmlRails
46
46
  options_for_select(options.tro(description), selected)
47
47
  end
48
48
 
49
- def tml_phrases_link_tag(search = "", phrase_type = :without, phrase_status = :any)
50
- return unless Tml.config.enabled?
51
- return if tml_current_language.default?
52
- return unless tml_current_translator.inline?
53
-
54
- link_to(image_tag(tml_application.url_for("/assets/tml/translate_icn.gif"), :style => "vertical-align:middle; border: 0px;", :title => search),
55
- tml_application.url_for("/tml/app/phrases/index?search=#{search}")).html_safe
56
- end
57
-
58
49
  def tml_language_flag_tag(lang = tml_current_language, opts = {})
59
50
  return '' unless tml_application.feature_enabled?(:language_flags)
60
51
  html = image_tag(lang.flag_url, :style => (opts[:style] || 'vertical-align:middle;'), :title => lang.native_name)
@@ -64,7 +55,7 @@ module TmlRails
64
55
 
65
56
  def tml_language_name_tag(lang = tml_current_language, opts = {})
66
57
  show_flag = opts[:flag].nil? ? true : opts[:flag]
67
- name_type = opts[:language].nil? ? :english : opts[:language] # :full, :native, :english, :locale, :both
58
+ name_type = opts[:language].nil? ? :english : opts[:language].to_sym # :full, :native, :english, :locale, :both
68
59
 
69
60
  html = []
70
61
  html << "<span style='white-space: nowrap'>"
@@ -87,14 +78,16 @@ module TmlRails
87
78
  end
88
79
 
89
80
  html << '</span></span>'
90
- html.join().html_safe
81
+ html.join.html_safe
91
82
  end
92
83
 
93
84
  def tml_language_selector_tag(type = nil, opts = {})
94
85
  return unless Tml.config.enabled?
95
86
 
96
87
  type ||= :default
97
- unless [:bootstrap, :default, :inline, :select, :popup].include?(type.to_sym)
88
+ type = :dropdown if type == :select
89
+
90
+ unless [:bootstrap, :default, :inline, :dropdown, :popup, :flags].include?(type.to_sym)
98
91
  return "Unsupported language selector #{type}"
99
92
  end
100
93
 
@@ -142,6 +135,10 @@ module TmlRails
142
135
  end
143
136
  alias_method :tml_block, :tml_with_options_tag
144
137
 
138
+ def tml_source(source, &block)
139
+ tml_with_options_tag({source: source}, &block)
140
+ end
141
+
145
142
  def tml_when_string_tag(time, opts = {})
146
143
  elapsed_seconds = Time.now - time
147
144
  if elapsed_seconds < 0
@@ -177,21 +174,33 @@ module TmlRails
177
174
  ## Language Direction Support
178
175
  ######################################################################
179
176
 
177
+ # switches CSS positions based on the language direction
178
+ # <%= tml_style_attribute_tag('float', 'right') %> => "float: right" : "float: left"
179
+ # <%= tml_style_attribute_tag('align', 'right') %> => "align: right" : "align: left"
180
180
  def tml_style_attribute_tag(attr_name = 'float', default = 'right', lang = tml_current_language)
181
181
  return "#{attr_name}:#{default}".html_safe if Tml.config.disabled?
182
182
  "#{attr_name}:#{lang.align(default)}".html_safe
183
183
  end
184
184
 
185
+ # supports directional CSS attributes
186
+ # <%= tml_style_directional_attribute_tag('padding', 'right', '5px') %> => "padding-right: 5px" : "padding-left: 5px"
185
187
  def tml_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tml_current_language)
186
188
  return "#{attr_name}-#{default}:#{value}".html_safe if Tml.config.disabled?
187
189
  "#{attr_name}-#{lang.align(default)}:#{value}".html_safe
188
190
  end
189
191
 
192
+ # provides the locale and direction of the language
193
+ def tml_html_attributes_tag(lang = tml_current_language)
194
+ "#{tml_lang_attribute_tag(lang)} #{tml_dir_attribute_tag(lang)}"
195
+ end
196
+
197
+ # providers the direction of the language
190
198
  def tml_dir_attribute_tag(lang = tml_current_language)
191
199
  return "dir='ltr'" if Tml.config.disabled?
192
200
  "dir='#{lang.dir}'".html_safe
193
201
  end
194
202
 
203
+ # provides the locale of the language
195
204
  def tml_lang_attribute_tag(lang = tml_current_language)
196
205
  return "lang='en-US'" if Tml.config.disabled?
197
206
  "lang='#{lang.locale}'".html_safe
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module TmlRails
33
- VERSION = '4.4.1'
33
+ VERSION = '4.4.2'
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: 4.4.1
4
+ version: 4.4.2
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-06-11 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.4'
41
- description: Client SDK for Translation Exchange.
41
+ description: Translation Markup Language from Translation Exchange.
42
42
  email:
43
43
  - michael@translationexchange.com
44
44
  executables: []
@@ -51,10 +51,11 @@ files:
51
51
  - app/controllers/tml_rails/tools_controller.rb
52
52
  - app/views/tml_rails/tags/_language_selector_bootstrap.html.erb
53
53
  - app/views/tml_rails/tags/_language_selector_default.html.erb
54
+ - app/views/tml_rails/tags/_language_selector_dropdown.html.erb
55
+ - app/views/tml_rails/tags/_language_selector_flags.html.erb
54
56
  - app/views/tml_rails/tags/_language_selector_inline.html.erb
55
57
  - app/views/tml_rails/tags/_language_selector_js.html.erb
56
58
  - app/views/tml_rails/tags/_language_selector_popup.html.erb
57
- - app/views/tml_rails/tags/_language_selector_select.html.erb
58
59
  - app/views/tml_rails/tags/_language_strip.html.erb
59
60
  - app/views/tml_rails/tags/_powered_by_trex.html.erb
60
61
  - app/views/tml_rails/tags/_scripts.html.erb