tml-rails 4.3.6 → 4.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -12
- data/app/views/tml_rails/tags/_language_selector_bootstrap.html.erb +46 -0
- data/app/views/tml_rails/tags/_language_selector_default.html.erb +17 -0
- data/app/views/tml_rails/tags/_language_selector_inline.html.erb +15 -0
- data/app/views/tml_rails/tags/_language_selector_js.html.erb +32 -0
- data/app/views/tml_rails/tags/_language_selector_select.html.erb +15 -0
- data/lib/tasks/tml.rake +3 -3
- data/lib/tml/cache_adapters/rails.rb +1 -2
- data/lib/tml_rails/extensions/action_controller_extension.rb +8 -7
- data/lib/tml_rails/extensions/action_view_extension.rb +18 -12
- data/lib/tml_rails/version.rb +1 -1
- metadata +7 -3
- data/app/views/tml_rails/tags/_language_selector.html.erb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9326f9cd017dbc9d697e2c7dab50c0ff2d70c41b
|
4
|
+
data.tar.gz: 1898fcb898316d57b4de91356a66524dd18c5a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 598ce0a929c08a22c956d35857bb63f5e52959b3e2381e5a3a1ec79bd0c5df1223b56efdee91bf72edd1f5c3bda03659a271639a7a61921b704724d7be442b6e
|
7
|
+
data.tar.gz: 2470d1f1ac1f5024299fadaf636e7408e5cc38c50a251493d00c1ae7263bf7fc65904b69385d218a6f28f16a1fcda1c5bfe73932156797403ffbd6c6b91eebd8
|
data/README.md
CHANGED
@@ -53,11 +53,44 @@ Tml must be used with caching enabled.
|
|
53
53
|
|
54
54
|
If you are already using Rails caching, you probably already specify it in your production file, like the following:
|
55
55
|
|
56
|
+
Memcache
|
57
|
+
|
56
58
|
config/environments/production.rb
|
57
59
|
|
58
60
|
```ruby
|
59
|
-
config.cache_store = :mem_cache_store,
|
60
|
-
|
61
|
+
config.cache_store = :mem_cache_store, { :namespace => 'my_cache' }
|
62
|
+
```
|
63
|
+
|
64
|
+
Memcache for multiple servers
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
config.cache_store = :mem_cache_store, '123.456.78.9:1001', '123.456.78.9:1002'
|
68
|
+
```
|
69
|
+
|
70
|
+
Memcache with Dalli
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
config.cache_store = :mem_cache_store, Dalli::Client.new('localhost:11211', {
|
74
|
+
:namespace => 'my_cache'
|
75
|
+
})
|
76
|
+
```
|
77
|
+
|
78
|
+
Redis
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
config.cache_store = :redis_store, {
|
82
|
+
:host => 'localhost',
|
83
|
+
:port => 6379,
|
84
|
+
:db => 0,
|
85
|
+
:namespace => 'my_cache',
|
86
|
+
:expires_in => 90.minutes
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
Tip: to clear up Redis cache
|
91
|
+
|
92
|
+
```sh
|
93
|
+
$ redis-cli FLUSHALL
|
61
94
|
```
|
62
95
|
|
63
96
|
Then all you need to do is specify that you want to use the Rails cache adapter:
|
@@ -76,11 +109,12 @@ Alternatively, you can provide a separate memcache server to store your translat
|
|
76
109
|
|
77
110
|
```ruby
|
78
111
|
config.cache = {
|
79
|
-
:enabled
|
80
|
-
:adapter
|
81
|
-
:host
|
82
|
-
:
|
83
|
-
:
|
112
|
+
:enabled => true,
|
113
|
+
:adapter => 'memcache',
|
114
|
+
:host => 'localhost:11211',
|
115
|
+
:namespace => 'translations',
|
116
|
+
:version => 1,
|
117
|
+
:timeout => 3600
|
84
118
|
}
|
85
119
|
```
|
86
120
|
|
@@ -88,11 +122,14 @@ You can also use Redis to persist your translations cache:
|
|
88
122
|
|
89
123
|
```ruby
|
90
124
|
config.cache = {
|
91
|
-
:enabled
|
92
|
-
:adapter
|
93
|
-
:host
|
94
|
-
:
|
95
|
-
:
|
125
|
+
:enabled => true,
|
126
|
+
:adapter => 'redis',
|
127
|
+
:host => 'localhost',
|
128
|
+
:port => 6379,
|
129
|
+
:password => 'password',
|
130
|
+
:namespace => 'translations',
|
131
|
+
:version => 1,
|
132
|
+
:timeout => 3600
|
96
133
|
}
|
97
134
|
```
|
98
135
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<%
|
2
|
+
opts[:element] ||= 'div'
|
3
|
+
opts[:class] ||= 'dropdown'
|
4
|
+
%>
|
5
|
+
|
6
|
+
<<%= opts[:element] %> class="<%= opts[:class] %>" style="<%= opts[:style] %>">
|
7
|
+
<a href="#" role="button" class="<%= opts[:class] || 'dropdown' %>-toggle" data-toggle="dropdown">
|
8
|
+
<%= tml_language_name_tag(tml_current_language, opts) %>
|
9
|
+
</a>
|
10
|
+
|
11
|
+
<ul class="dropdown-menu" role="menu">
|
12
|
+
|
13
|
+
<% tml_application.languages.each do |lang| %>
|
14
|
+
|
15
|
+
<li role="presentation">
|
16
|
+
<%=link_to({:locale => lang.locale}) do %>
|
17
|
+
|
18
|
+
<%= tml_language_name_tag(lang, opts) %>
|
19
|
+
|
20
|
+
<% end %>
|
21
|
+
</li>
|
22
|
+
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<% if opts[:toggle] %>
|
26
|
+
<li role='presentation' class='divider'></li>
|
27
|
+
<li role='presentation'>
|
28
|
+
<a href='javascript:void(0);' onclick='Tml.Utils.toggleInlineTranslations()'>
|
29
|
+
<%= tr(opts[:toggle_label] || 'Help Us Translate') %>
|
30
|
+
</a>
|
31
|
+
</li>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<li role='presentation' class='divider'></li>
|
35
|
+
|
36
|
+
<div style="font-size:8px;color:#ccc;text-align: center">
|
37
|
+
<a href="http://translationexchange.com">
|
38
|
+
<img style="padding: 10px;border: 0px;background-repeat: no-repeat;background-size: 14px 17px;
|
39
|
+
background-image:url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABQCAYAAABCiMhGAAAAGX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>
|
44
|
+
</ul>
|
45
|
+
</<%= opts[:element] %>>
|
46
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= link_to('#',
|
2
|
+
:onclick => opts[:method] || 'Tml.UI.LanguageSelector.show(); return false;',
|
3
|
+
:style => (opts[:style] || 'padding-right:5px;text-decoration:none'),
|
4
|
+
:class => opts[:class]
|
5
|
+
) do %>
|
6
|
+
<% unless opts[:hide_flag] %>
|
7
|
+
<%= image_tag(tml_current_language.flag_url, :style => "align:middle") %>
|
8
|
+
|
9
|
+
<% end %>
|
10
|
+
<% if opts[:language] == :native %>
|
11
|
+
<%= tml_current_language.native_name %>
|
12
|
+
<% elsif opts[:language] == :english %>
|
13
|
+
<%= tml_current_language.english_name %>
|
14
|
+
<% else %>
|
15
|
+
<%= tml_current_language.english_name %>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div style="<%=opts[:style]%>" class="<%=opts[:class]%>">
|
2
|
+
<% tml_application.languages.each_with_index do |lang, index| %>
|
3
|
+
<% next if opts[:limit] and index >= opts[:limit] %>
|
4
|
+
|
5
|
+
|
6
|
+
<%= link_to(params.merge(:locale => lang.locale), :style => (opts[:style] || 'padding-right:5px;text-decoration:none'), :class => opts[:class]) do %>
|
7
|
+
<% if opts[:flags_only] or opts[:flags] %>
|
8
|
+
<%= image_tag(lang.flag_url) %>
|
9
|
+
<% else %>
|
10
|
+
<%= tml_language_name_tag(lang, opts) %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<% end %>
|
15
|
+
</div>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<script>
|
2
|
+
function tml_change_locale(locale) {
|
3
|
+
var query_parts = window.location.href.split('#');
|
4
|
+
var anchor = query_parts.length > 1 ? query_parts[1] : null;
|
5
|
+
query_parts = query_parts[0].split('?');
|
6
|
+
var query = query_parts.length > 1 ? query_parts[1] : null;
|
7
|
+
|
8
|
+
var params = {};
|
9
|
+
if (query) {
|
10
|
+
var vars = query.split('&');
|
11
|
+
for (var i = 0; i < vars.length; i++) {
|
12
|
+
var pair = vars[i].split('=');
|
13
|
+
params[pair[0]] = pair[1];
|
14
|
+
}
|
15
|
+
}
|
16
|
+
params['locale'] = locale;
|
17
|
+
|
18
|
+
query = [];
|
19
|
+
var keys = Object.keys(params);
|
20
|
+
for (i = 0; i < keys.length; i++) {
|
21
|
+
query.push(keys[i] + "=" + params[keys[i]]);
|
22
|
+
}
|
23
|
+
|
24
|
+
var destination = query_parts[0];
|
25
|
+
if (query.length > 0)
|
26
|
+
destination = destination + '?' + query.join("&");
|
27
|
+
if (anchor)
|
28
|
+
destination = destination + '#' + anchor;
|
29
|
+
|
30
|
+
window.location = destination;
|
31
|
+
}
|
32
|
+
</script>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= render(:partial => '/tml_rails/tags/language_selector_js') %>
|
2
|
+
|
3
|
+
<select id="tml_language_selector" onchange="tml_change_locale(this.options[this.selectedIndex].value)" style="<%=opts[:style]%>" class="<%=opts[:class]%>">
|
4
|
+
<% tml_application.languages.each do |lang| %>
|
5
|
+
<option dir='ltr' value="<%=lang.locale%>" <%="selected" if lang.locale == tml_current_locale %>>
|
6
|
+
<% if opts[:language] == :native %>
|
7
|
+
<%= lang.native_name %>
|
8
|
+
<% elsif opts[:language] == :english %>
|
9
|
+
<%= lang.english_name %>
|
10
|
+
<% else %>
|
11
|
+
<%= lang.english_name %>
|
12
|
+
<% end %>
|
13
|
+
</option>
|
14
|
+
<% end %>
|
15
|
+
</select>
|
data/lib/tasks/tml.rake
CHANGED
@@ -42,17 +42,17 @@ namespace :tml do
|
|
42
42
|
|
43
43
|
desc 'generates local file cache'
|
44
44
|
task :generate => :environment do
|
45
|
-
Tml::Generators::
|
45
|
+
Tml::Generators::File.new.run
|
46
46
|
end
|
47
47
|
|
48
48
|
desc 'rolls back to the previous version'
|
49
49
|
task :rollback => :environment do
|
50
|
-
Tml::Generators::
|
50
|
+
Tml::Generators::File.new.rollback
|
51
51
|
end
|
52
52
|
|
53
53
|
desc 'rolls up to the next version'
|
54
54
|
task :rollup => :environment do
|
55
|
-
Tml::Generators::
|
55
|
+
Tml::Generators::File.new.rollup
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -33,7 +33,6 @@
|
|
33
33
|
class Tml::CacheAdapters::Rails < Tml::Cache
|
34
34
|
|
35
35
|
def initialize
|
36
|
-
Tml.logger.info('Initializing Rails cache...')
|
37
36
|
@cache = Rails.cache
|
38
37
|
end
|
39
38
|
|
@@ -91,7 +90,7 @@ class Tml::CacheAdapters::Rails < Tml::Cache
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def clear(opts = {})
|
94
|
-
info(
|
93
|
+
info('Cache clear')
|
95
94
|
rescue Exception => ex
|
96
95
|
warn("Failed to clear cache: #{ex.message}")
|
97
96
|
end
|
@@ -113,17 +113,18 @@ module TmlRails
|
|
113
113
|
end
|
114
114
|
|
115
115
|
unless tml_session_params[:locale]
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
session[:locale] = tml_user_preferred_locale unless session[:locale]
|
120
|
-
session[:locale] = params[:locale] if params[:locale]
|
121
|
-
tml_session_params.merge!(:locale => session[:locale] || Tml.config.default_locale)
|
122
|
-
end
|
116
|
+
tml_session_params.merge!(:cookies => cookies)
|
117
|
+
tml_session_params.merge!(:change_locale => true) if params[:locale]
|
118
|
+
tml_session_params.merge!(:locale => params[:locale] || tml_user_preferred_locale)
|
123
119
|
end
|
124
120
|
|
125
121
|
Tml.session.init(tml_session_params)
|
126
122
|
|
123
|
+
# if user sets locale manually, update the cookie for future use
|
124
|
+
if tml_session_params[:change_locale]
|
125
|
+
cookies[Tml.session.cookie_name] = Tml::Utils.encode(Tml.session.cookie_params)
|
126
|
+
end
|
127
|
+
|
127
128
|
if defined? I18n.enforce_available_locales
|
128
129
|
I18n.enforce_available_locales = false
|
129
130
|
end
|
@@ -56,36 +56,42 @@ module TmlRails
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def tml_language_flag_tag(lang = tml_current_language, opts = {})
|
59
|
-
return
|
60
|
-
html = image_tag(lang.flag_url, :style =>
|
61
|
-
html <<
|
59
|
+
return '' unless tml_application.feature_enabled?(:language_flags)
|
60
|
+
html = image_tag(lang.flag_url, :style => (opts[:style] || 'vertical-align:middle;'), :title => lang.native_name)
|
61
|
+
html << ' '.html_safe
|
62
62
|
html.html_safe
|
63
63
|
end
|
64
64
|
|
65
65
|
def tml_language_name_tag(lang = tml_current_language, opts = {})
|
66
66
|
show_flag = opts[:flag].nil? ? true : opts[:flag]
|
67
|
-
name_type = opts[:
|
68
|
-
linked = opts[:linked].nil? ? true : opts[:linked]
|
67
|
+
name_type = opts[:language].nil? ? :english : opts[:language] # :full, :native, :english, :locale
|
69
68
|
|
70
|
-
html =
|
69
|
+
html = []
|
70
|
+
html << "<span style='white-space: nowrap'>"
|
71
71
|
html << tml_language_flag_tag(lang, opts) if show_flag
|
72
72
|
html << "<span dir='ltr'>"
|
73
73
|
|
74
74
|
name = case name_type
|
75
75
|
when :native then lang.native_name
|
76
|
-
when :
|
76
|
+
when :full then lang.full_name
|
77
77
|
when :locale then lang.locale
|
78
|
-
else lang.
|
78
|
+
else lang.english_name
|
79
79
|
end
|
80
80
|
|
81
|
-
html << name
|
82
|
-
html <<
|
83
|
-
html.html_safe
|
81
|
+
html << name.to_s
|
82
|
+
html << '</span></span>'
|
83
|
+
html.join().html_safe
|
84
84
|
end
|
85
85
|
|
86
86
|
def tml_language_selector_tag(type = nil, opts = {})
|
87
87
|
return unless Tml.config.enabled?
|
88
|
-
|
88
|
+
|
89
|
+
type ||= :default
|
90
|
+
unless [:bootstrap, :default, :inline, :select].include?(type.to_sym)
|
91
|
+
return "Unsupported language selector #{type}"
|
92
|
+
end
|
93
|
+
|
94
|
+
render(:partial => "/tml_rails/tags/language_selector_#{type}", :locals => {:opts => opts})
|
89
95
|
end
|
90
96
|
|
91
97
|
def tml_language_strip_tag(opts = {})
|
data/lib/tml_rails/version.rb
CHANGED
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.3.
|
4
|
+
version: 4.3.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-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -49,7 +49,11 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- app/controllers/tml_rails/tools_controller.rb
|
52
|
-
- app/views/tml_rails/tags/
|
52
|
+
- app/views/tml_rails/tags/_language_selector_bootstrap.html.erb
|
53
|
+
- app/views/tml_rails/tags/_language_selector_default.html.erb
|
54
|
+
- app/views/tml_rails/tags/_language_selector_inline.html.erb
|
55
|
+
- app/views/tml_rails/tags/_language_selector_js.html.erb
|
56
|
+
- app/views/tml_rails/tags/_language_selector_select.html.erb
|
53
57
|
- app/views/tml_rails/tags/_language_strip.html.erb
|
54
58
|
- app/views/tml_rails/tags/_powered_by_trex.html.erb
|
55
59
|
- app/views/tml_rails/tags/_scripts.html.erb
|
@@ -1,82 +0,0 @@
|
|
1
|
-
<% if tml_session.tools_enabled? or type.blank? %>
|
2
|
-
<%
|
3
|
-
if tml_session.tools_enabled?
|
4
|
-
opts[:method] = 'Tml.UI.LanguageSelector.show(); return false;'
|
5
|
-
end
|
6
|
-
%>
|
7
|
-
|
8
|
-
<%= link_to('#',
|
9
|
-
:onclick => (opts[:method] || "alert('Custom language selector can be specified by passing it in the method attribute of the language selector tag.');"),
|
10
|
-
:style => (opts[:style] || 'padding-right:5px;text-decoration:none'),
|
11
|
-
:class => opts[:class]
|
12
|
-
) do %>
|
13
|
-
<% unless opts[:hide_flag] %>
|
14
|
-
<%= image_tag(tml_current_language.flag_url, :style => "align:middle") %>
|
15
|
-
|
16
|
-
<% end %>
|
17
|
-
<% if opts[:language] == :native %>
|
18
|
-
<%= tml_current_language.native_name %>
|
19
|
-
<% elsif opts[:language] == :english %>
|
20
|
-
<%= tml_current_language.english_name %>
|
21
|
-
<% else %>
|
22
|
-
<%= tml_current_language.english_name %>
|
23
|
-
<% end %>
|
24
|
-
<% end %>
|
25
|
-
|
26
|
-
<% elsif type == :list %>
|
27
|
-
<div style="padding-top:10px;">
|
28
|
-
<% tml_application.languages.each_with_index do |lang, index| %>
|
29
|
-
<% next if opts[:limit] and index >= opts[:limit] %>
|
30
|
-
<%= link_to(params.merge(:locale => lang.locale), :style => (opts[:style] || 'padding-right:5px;text-decoration:none'), :class => opts[:class]) do %>
|
31
|
-
<% if opts[:flags_only] or opts[:flags] %>
|
32
|
-
<%= image_tag(lang.flag_url) %>
|
33
|
-
<% end %>
|
34
|
-
<% unless opts[:flags_only] %>
|
35
|
-
<%= lang.english_name %>
|
36
|
-
<% end %>
|
37
|
-
<% end %>
|
38
|
-
<% end %>
|
39
|
-
</div>
|
40
|
-
|
41
|
-
<% elsif type == :dropdown %>
|
42
|
-
|
43
|
-
<script>
|
44
|
-
function tml_change_locale(selector) {
|
45
|
-
var query_parts = window.location.href.split('?');
|
46
|
-
var query = query_parts.length > 1 ? query_parts[1] : null;
|
47
|
-
var params = {};
|
48
|
-
if (query) {
|
49
|
-
var vars = query.split('&');
|
50
|
-
for (var i = 0; i < vars.length; i++) {
|
51
|
-
var pair = vars[i].split('=');
|
52
|
-
params[pair[0]] = pair[1];
|
53
|
-
}
|
54
|
-
}
|
55
|
-
params['locale'] = selector.options[selector.selectedIndex].value;
|
56
|
-
|
57
|
-
query = [];
|
58
|
-
var keys = Object.keys(params);
|
59
|
-
for (var i = 0; i < keys.length; i++) {
|
60
|
-
query.push(encodeURIComponent(keys[i]) + "=" + encodeURIComponent(params[keys[i]]));
|
61
|
-
}
|
62
|
-
|
63
|
-
var destination = query_parts[0] + '?' + query.join("&");
|
64
|
-
window.location = destination;
|
65
|
-
}
|
66
|
-
</script>
|
67
|
-
|
68
|
-
<select id="tml_language_selector" onchange="tml_change_locale(this)" style="<%=opts[:style]%>" class="<%=opts[:class]%>">
|
69
|
-
<% tml_application.languages.each do |lang| %>
|
70
|
-
<option dir='ltr' value="<%=lang.locale%>" <%="selected" if lang.locale == tml_current_locale %>>
|
71
|
-
<% if opts[:language] == :native %>
|
72
|
-
<%= lang.native_name %>
|
73
|
-
<% elsif opts[:language] == :english %>
|
74
|
-
<%= lang.english_name %>
|
75
|
-
<% else %>
|
76
|
-
<%= lang.english_name %>
|
77
|
-
<% end %>
|
78
|
-
</option>
|
79
|
-
<% end %>
|
80
|
-
</select>
|
81
|
-
|
82
|
-
<% end %>
|