lit 1.1.0 → 1.1.5
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 +4 -4
- data/README.md +47 -31
- data/app/assets/javascripts/lit/backend/localizations.js.coffee +13 -6
- data/app/assets/stylesheets/lit/application.css +16 -13
- data/app/assets/stylesheets/lit/lit_frontend.css +16 -15
- data/app/controllers/lit/api/v1/localizations_controller.rb +9 -17
- data/app/controllers/lit/cloud_translations_controller.rb +1 -1
- data/app/controllers/lit/concerns/request_info_store.rb +5 -14
- data/app/controllers/lit/concerns/request_keys_store.rb +5 -13
- data/app/controllers/lit/localization_keys_controller.rb +38 -38
- data/app/controllers/lit/request_info_store.rb +10 -0
- data/app/controllers/lit/request_keys_store.rb +10 -0
- data/app/helpers/lit/frontend_helper.rb +65 -65
- data/app/models/lit/base.rb +1 -1
- data/app/models/lit/incomming_localization.rb +13 -27
- data/app/models/lit/localization.rb +6 -14
- data/app/services/remote_interactor_service.rb +2 -1
- data/app/services/synchronize_source_service.rb +4 -8
- data/app/views/lit/localization_keys/_localizations_list.html.erb +18 -10
- data/app/views/lit/localization_keys/batch_touch.js.erb +1 -0
- data/app/views/lit/localizations/update.js.erb +1 -1
- data/config/routes.rb +1 -0
- data/lib/generators/lit/install/templates/{initializer.rb → initializer.erb} +6 -1
- data/lib/generators/lit/install_generator.rb +8 -10
- data/lib/lit/adapters/hash_storage.rb +2 -2
- data/lib/lit/adapters/redis_storage.rb +8 -11
- data/lib/lit/adapters.rb +2 -0
- data/lib/lit/cache.rb +23 -2
- data/lib/lit/cloud_translation/providers/google.rb +25 -7
- data/lib/lit/engine.rb +4 -6
- data/lib/lit/export.rb +5 -11
- data/lib/lit/i18n_backend.rb +24 -0
- data/lib/lit/import.rb +4 -4
- data/lib/lit/middleware.rb +29 -0
- data/lib/lit/rails.rb +1 -0
- data/lib/lit/railtie.rb +6 -7
- data/lib/lit/services/localization_keys_to_hash_service.rb +18 -15
- data/lib/lit/version.rb +15 -1
- data/lib/lit.rb +11 -11
- metadata +13 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dcf44da1e10a331cafdd9352461c1d9b985c6ea3d97e61744a1390e036be71a
|
4
|
+
data.tar.gz: 3c03d7e70b3c172092d807539543f0389e4e04c7f0420c66ffb5f96f742a4fa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecf7688c8aa6f32c6c01fab3b14024720f75155b66ed1be9494c40f0ed4755855e2b73b9d1d528a7a215513316a27ceb3427a84e72e0420f611a4c7e877b6ce0
|
7
|
+
data.tar.gz: 5f4fe480d203c6ade865f44385b4dfb951aa4a32c33f8e224b9371e3f36f5a16acd444ef73136bc28f7278d6518b7681d29540dca11833e6f7ecfc3b776b1386
|
data/README.md
CHANGED
@@ -22,9 +22,14 @@ Highly inspired by Copycopter by thoughtbot.
|
|
22
22
|
9. (On request) stores paths where translation keys were called
|
23
23
|
10. (On request) is able to show all translation keys used to render current page
|
24
24
|
|
25
|
+
|
25
26
|
### Screenshots
|
26
27
|
|
27
|
-
|
28
|
+
[Feature overview on YouTube](https://www.youtube.com/watch?v=_T9Kg05VvLI)
|
29
|
+
|
30
|
+

|
31
|
+
|
32
|
+
Check wiki for more: [Screenshots](https://github.com/prograils/lit/wiki/Screenshots)
|
28
33
|
|
29
34
|
### Installation
|
30
35
|
|
@@ -37,10 +42,10 @@ gem 'lit'
|
|
37
42
|
|
38
43
|
2. run `bundle install`
|
39
44
|
|
40
|
-
3.
|
41
|
-
(for production/staging environment `redis` is suggested as key value engine. `hash` will not work in multi process environment)
|
45
|
+
3. Add `config.i18n.available_locales = [...]` to `application.rb` - it's required to precompile appropriate language flags in lit backend.
|
42
46
|
|
43
|
-
4.
|
47
|
+
4. run installation generator `bundle exec rails g lit:install`
|
48
|
+
(for production/staging environment `redis` is suggested as key value engine. `hash` will not work in multi process environment)
|
44
49
|
|
45
50
|
5. After doing above and restarting app, point your browser to `http://app/lit`
|
46
51
|
|
@@ -130,6 +135,10 @@ Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::Google
|
|
130
135
|
```
|
131
136
|
gem 'google-cloud-translate', '~> 1.2.4'
|
132
137
|
```
|
138
|
+
...we also support V2 of Google Cloud Translate gem, should you need it:
|
139
|
+
```
|
140
|
+
gem 'google-cloud-translate', '~> 2.1.2'
|
141
|
+
```
|
133
142
|
|
134
143
|
To use translation via Google, you need to obtain a [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) containing all the credentials required by the API.
|
135
144
|
|
@@ -145,10 +154,10 @@ These credentials can be given in three ways:
|
|
145
154
|
... # see Google docs link above for reference
|
146
155
|
}
|
147
156
|
end
|
148
|
-
|
157
|
+
|
149
158
|
# For example, for Rails 6, from encrypted credentials file (HashWithIndifferentAccess is used, because the keys in
|
150
159
|
the credentials.config could be strings or, as well, symbols):
|
151
|
-
|
160
|
+
|
152
161
|
Lit::CloudTranslation.configure do |config|
|
153
162
|
config.keyfile_hash = HashWithIndifferentAccess.new(Rails.application.credentials.config[:google_translate_api])
|
154
163
|
end
|
@@ -199,17 +208,17 @@ Also applies to upgrading from `0.4.pre.alpha` versions.
|
|
199
208
|
|
200
209
|
1. Add `Lit::FrontendHelper` to your `ApplicationController`
|
201
210
|
|
202
|
-
|
203
|
-
|
204
|
-
|
211
|
+
```ruby
|
212
|
+
helper Lit::FrontendHelper
|
213
|
+
```
|
205
214
|
|
206
215
|
2. In you layout file include lit assets
|
207
216
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
217
|
+
```erb
|
218
|
+
<% if admin_user_signed_in? %>
|
219
|
+
<%= lit_frontend_assets %>
|
220
|
+
<% end %>
|
221
|
+
```
|
213
222
|
|
214
223
|
3. You're good to go - now log in to lit (if required) and open your frontend in separate tab (to have session persisted). On the bottom-right of your page you should see "Enable / disable lit highlight" - after enabling it you'll be able to click and translate phrases directly in your frontend
|
215
224
|
|
@@ -217,13 +226,14 @@ Also applies to upgrading from `0.4.pre.alpha` versions.
|
|
217
226
|
|
218
227
|
5. This feature requires jQuery! (at least for now)
|
219
228
|
|
229
|
+
|
220
230
|
### Storing request info
|
221
231
|
|
222
|
-
1. Include `Lit::
|
232
|
+
1. Include `Lit::RequestInfoStore` concern in your `ApplicationController`
|
223
233
|
|
224
|
-
|
225
|
-
|
226
|
-
|
234
|
+
```ruby
|
235
|
+
include Lit::RequestInfoStore
|
236
|
+
```
|
227
237
|
|
228
238
|
2. In lit initializer (`lit.rb`) set `store_request_info` config to true
|
229
239
|
|
@@ -238,25 +248,31 @@ Lit.store_request_info = true
|
|
238
248
|
|
239
249
|
1. Add `Lit::FrontendHelper` in your `ApplicationController`
|
240
250
|
|
241
|
-
|
242
|
-
|
243
|
-
|
251
|
+
```ruby
|
252
|
+
helper Lit::FrontendHelper
|
253
|
+
```
|
254
|
+
|
255
|
+
2. Include `Lit::RequestKeysStore` concern in your `ApplicationController`
|
244
256
|
|
245
|
-
|
257
|
+
```ruby
|
258
|
+
include Lit::RequestKeysStore
|
259
|
+
```
|
260
|
+
|
261
|
+
3. Enable storing of request keys in lit initializer `config/initializers/lit.rb`
|
246
262
|
|
247
|
-
|
248
|
-
|
249
|
-
|
263
|
+
```ruby
|
264
|
+
Lit.store_request_keys = true
|
265
|
+
```
|
250
266
|
|
251
|
-
|
267
|
+
4. On the bottom of you layout file call `lit_translations_info` helper function
|
252
268
|
|
253
|
-
|
254
|
-
|
255
|
-
|
269
|
+
```erb
|
270
|
+
<%= lit_translations_info %>
|
271
|
+
```
|
256
272
|
|
257
|
-
|
273
|
+
5. From now on you'll be able to see all translation keys that were used to render current page. This feature works great with on-site live translations!
|
258
274
|
|
259
|
-
|
275
|
+
6. Lit authorized user must be signed in for this feature to work! This feature requires jQuery!
|
260
276
|
|
261
277
|
|
262
278
|
|
@@ -2,25 +2,32 @@
|
|
2
2
|
$(document).ready ->
|
3
3
|
$('td.localization_row[data-editing=0]').on 'click', ->
|
4
4
|
$this = $(this)
|
5
|
-
if parseInt($this.data('editing'))==0
|
5
|
+
if parseInt($this.data('editing')) == 0
|
6
6
|
edited_rows[$this.data('id')] = $this.html()
|
7
7
|
unless parseInt($this.data('editing'))
|
8
8
|
$this.data('editing', '1')
|
9
9
|
$.get $this.data('edit')
|
10
|
-
$('td.localization_row').on 'click', 'form button.cancel', (e)->
|
10
|
+
$('td.localization_row').on 'click', 'form button.cancel', (e) ->
|
11
11
|
$this = $(this)
|
12
|
-
if $this[0].localName=='button'
|
12
|
+
if $this[0].localName == 'button'
|
13
13
|
$this = $this.parents('td.localization_row')
|
14
14
|
$this.data('editing', 0)
|
15
15
|
$this.html edited_rows[$this.data('id')]
|
16
16
|
e.preventDefault()
|
17
17
|
false
|
18
|
-
$('tr.localization_versions_row').on 'click', '.close_versions', (e)->
|
18
|
+
$('tr.localization_versions_row').on 'click', '.close_versions', (e) ->
|
19
19
|
$this = $(this)
|
20
20
|
$parent = $this.parents('tr.localization_versions_row')
|
21
21
|
$parent.addClass('hidden')
|
22
22
|
$parent.children('td').html('')
|
23
|
-
$('tr.localization_key_row').on 'click', 'input.wysiwyg_switch', (e)->
|
23
|
+
$('tr.localization_key_row').on 'click', 'input.wysiwyg_switch', (e) ->
|
24
24
|
$(this).parents('form').find("textarea").jqte()
|
25
|
-
$('tr.localization_key_row').on 'click', '.request_info_link', (e)->
|
25
|
+
$('tr.localization_key_row').on 'click', '.request_info_link', (e) ->
|
26
26
|
$(this).parents('tr.localization_key_row').find(".request_info_row").toggleClass('hidden')
|
27
|
+
$('tr.localization_key_row').on 'click', '.js-copy_to_clipboard', (e) ->
|
28
|
+
if(!navigator.clipboard)
|
29
|
+
alert('No browser support for clipboard')
|
30
|
+
else
|
31
|
+
navigator.clipboard.writeText($(this).data('key'))
|
32
|
+
e.preventDefault()
|
33
|
+
false
|
@@ -11,17 +11,17 @@
|
|
11
11
|
*= require './backend/jquery-te-1.4.0.css'
|
12
12
|
*= require_self
|
13
13
|
*/
|
14
|
-
.detail_wrapper{
|
15
|
-
padding: 10px 0 0
|
14
|
+
.detail_wrapper {
|
15
|
+
padding: 10px 0 0 10px;
|
16
16
|
}
|
17
|
-
.detail_wrapper table tr td.locale_row{
|
17
|
+
.detail_wrapper table tr td.locale_row {
|
18
18
|
width: 75px;
|
19
19
|
}
|
20
|
-
.localization_key_row .localization_keys_options{
|
20
|
+
.localization_key_row .localization_keys_options {
|
21
21
|
display: none;
|
22
22
|
float: right;
|
23
23
|
}
|
24
|
-
.localization_key_row:hover .localization_keys_options{
|
24
|
+
.localization_key_row:hover .localization_keys_options {
|
25
25
|
display: block;
|
26
26
|
}
|
27
27
|
|
@@ -29,29 +29,29 @@ li.key_prefix .fa-chevron-right {
|
|
29
29
|
float: right;
|
30
30
|
margin-top: 2px;
|
31
31
|
margin-right: -6px;
|
32
|
-
opacity: .25;
|
32
|
+
opacity: 0.25;
|
33
33
|
}
|
34
34
|
|
35
|
-
.hidden{
|
35
|
+
.hidden {
|
36
36
|
display: none;
|
37
37
|
}
|
38
|
-
i.fa{
|
38
|
+
i.fa {
|
39
39
|
color: black;
|
40
40
|
}
|
41
|
-
.nav.nav-stacked>li>a {
|
42
|
-
padding: 5px 7px;
|
41
|
+
.nav.nav-stacked > li > a {
|
42
|
+
padding: 5px 7px;
|
43
43
|
}
|
44
|
-
.well{
|
44
|
+
.well {
|
45
45
|
background-color: white;
|
46
46
|
border-radius: 0px;
|
47
47
|
}
|
48
|
-
.well label{
|
48
|
+
.well label {
|
49
49
|
font-weight: normal;
|
50
50
|
}
|
51
51
|
.well .form-search {
|
52
52
|
margin-bottom: 15px;
|
53
53
|
}
|
54
|
-
.localization_row em{
|
54
|
+
.localization_row em {
|
55
55
|
color: #bbb;
|
56
56
|
}
|
57
57
|
.loading {
|
@@ -60,3 +60,6 @@ padding: 5px 7px;
|
|
60
60
|
.loaded {
|
61
61
|
display: none;
|
62
62
|
}
|
63
|
+
.copy_to_clipboard_btn {
|
64
|
+
cursor: pointer;
|
65
|
+
}
|
@@ -1,9 +1,11 @@
|
|
1
1
|
.lit-key-generic {
|
2
2
|
}
|
3
|
-
.lit-key-highlight{
|
4
|
-
text-decoration: underline
|
3
|
+
.lit-key-highlight {
|
4
|
+
text-decoration: underline !important;
|
5
|
+
text-decoration-color: red !important;
|
6
|
+
text-decoration-style: wavy !important;
|
5
7
|
}
|
6
|
-
#lit_button_wrapper{
|
8
|
+
#lit_button_wrapper {
|
7
9
|
position: fixed;
|
8
10
|
bottom: 20px;
|
9
11
|
right: 20px;
|
@@ -15,16 +17,15 @@
|
|
15
17
|
cursor: pointer;
|
16
18
|
color: white;
|
17
19
|
}
|
18
|
-
#lit_button_wrapper.lit-highlight-enabled{
|
20
|
+
#lit_button_wrapper.lit-highlight-enabled {
|
19
21
|
background-color: lightgreen;
|
20
22
|
}
|
21
|
-
#lit_textarea{
|
23
|
+
#lit_textarea {
|
22
24
|
position: absolute;
|
23
25
|
padding: 0 0 1px 0;
|
24
26
|
margin: 0 0 0 0;
|
25
27
|
border: 0;
|
26
28
|
border-bottom: 1px solid red;
|
27
|
-
|
28
29
|
}
|
29
30
|
.lit-translations-info.collapsed {
|
30
31
|
position: fixed;
|
@@ -38,7 +39,7 @@
|
|
38
39
|
cursor: pointer;
|
39
40
|
color: white;
|
40
41
|
}
|
41
|
-
.lit-translations-info.expanded{
|
42
|
+
.lit-translations-info.expanded {
|
42
43
|
position: absolute;
|
43
44
|
display: block;
|
44
45
|
width: 80%;
|
@@ -52,16 +53,16 @@
|
|
52
53
|
z-index: 90;
|
53
54
|
}
|
54
55
|
|
55
|
-
.lit-translations-info.collapsed span.lit-open-button{
|
56
|
+
.lit-translations-info.collapsed span.lit-open-button {
|
56
57
|
display: block;
|
57
58
|
}
|
58
|
-
.lit-translations-info.expanded span.lit-open-button{
|
59
|
+
.lit-translations-info.expanded span.lit-open-button {
|
59
60
|
display: none;
|
60
61
|
}
|
61
|
-
.lit-translations-info.collapsed span.lit-close-button{
|
62
|
+
.lit-translations-info.collapsed span.lit-close-button {
|
62
63
|
display: none;
|
63
64
|
}
|
64
|
-
.lit-translations-info.expanded span.lit-close-button{
|
65
|
+
.lit-translations-info.expanded span.lit-close-button {
|
65
66
|
display: block;
|
66
67
|
position: fixed;
|
67
68
|
right: 10%;
|
@@ -71,16 +72,16 @@
|
|
71
72
|
background-color: white;
|
72
73
|
padding: 10px 10px 5px;
|
73
74
|
}
|
74
|
-
.lit-translations-info.collapsed ul.lit-translations-list{
|
75
|
+
.lit-translations-info.collapsed ul.lit-translations-list {
|
75
76
|
display: none;
|
76
77
|
}
|
77
|
-
.lit-translations-info.expanded ul.lit-translations-list{
|
78
|
+
.lit-translations-info.expanded ul.lit-translations-list {
|
78
79
|
}
|
79
80
|
|
80
|
-
.lit-translations-info.expanded ul.lit-translations-list li{
|
81
|
+
.lit-translations-info.expanded ul.lit-translations-list li {
|
81
82
|
margin: 5px;
|
82
83
|
}
|
83
84
|
|
84
|
-
.lit-translations-info.expanded #lit_textarea{
|
85
|
+
.lit-translations-info.expanded #lit_textarea {
|
85
86
|
padding: 2px;
|
86
87
|
}
|
@@ -2,34 +2,26 @@ module Lit
|
|
2
2
|
class Api::V1::LocalizationsController < Api::V1::BaseController
|
3
3
|
def index
|
4
4
|
@localizations = fetch_localizations
|
5
|
-
render json:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
]
|
12
|
-
)
|
5
|
+
render json:
|
6
|
+
@localizations.as_json(
|
7
|
+
root: false,
|
8
|
+
only: %i[id localization_key_id locale_id],
|
9
|
+
methods: %i[value localization_key_str locale_str localization_key_is_deleted],
|
10
|
+
)
|
13
11
|
end
|
14
12
|
|
15
13
|
def last_change
|
16
14
|
@localization = Localization.order(updated_at: :desc).first
|
17
|
-
render json: @localization.as_json(
|
18
|
-
root: false, only: [], methods: [:last_change]
|
19
|
-
)
|
15
|
+
render json: @localization.as_json(root: false, only: [], methods: [:last_change])
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
23
19
|
|
24
20
|
def fetch_localizations
|
25
|
-
scope = Localization.includes(
|
26
|
-
:locale,
|
27
|
-
:localization_key
|
28
|
-
)
|
21
|
+
scope = Localization.includes(:locale, :localization_key)
|
29
22
|
|
30
23
|
if params[:after].present?
|
31
|
-
after_date = Time.parse("#{params[:after]} #{Time.zone.name}")
|
32
|
-
.in_time_zone
|
24
|
+
after_date = Time.parse("#{params[:after]} #{Time.zone.name}").in_time_zone
|
33
25
|
scope.after(after_date).to_a
|
34
26
|
else
|
35
27
|
scope.all
|
@@ -18,7 +18,7 @@ module Lit
|
|
18
18
|
from: params[:from],
|
19
19
|
to: @target_localization.locale.locale
|
20
20
|
}.compact
|
21
|
-
@translated_text = Lit::CloudTranslation.translate(opts)
|
21
|
+
@translated_text = Lit::CloudTranslation.translate(**opts)
|
22
22
|
rescue Lit::CloudTranslation::TranslationError => e
|
23
23
|
@error_message = "Translation failed. #{e.message}"
|
24
24
|
end
|
@@ -1,17 +1,8 @@
|
|
1
|
-
module Lit
|
2
|
-
|
3
|
-
module RequestInfoStore
|
4
|
-
extend ::ActiveSupport::Concern
|
5
|
-
included do
|
6
|
-
before_action :store_request_path
|
7
|
-
end
|
1
|
+
module Lit::Concerns::RequestInfoStore
|
2
|
+
extend ActiveSupport::Concern
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Thread.current[:lit_current_request_path] = request&.path
|
13
|
-
end
|
14
|
-
end
|
4
|
+
included do
|
5
|
+
Rails.logger.info 'DEPRECATED: Use include Lit::RequestInfoStore'
|
6
|
+
include Lit::RequestInfoStore
|
15
7
|
end
|
16
8
|
end
|
17
|
-
|
@@ -1,16 +1,8 @@
|
|
1
|
-
module Lit
|
2
|
-
|
3
|
-
module RequestKeysStore
|
4
|
-
extend ::ActiveSupport::Concern
|
5
|
-
included do
|
6
|
-
before_action :init_request_keys
|
7
|
-
end
|
1
|
+
module Lit::Concerns::RequestKeysStore
|
2
|
+
extend ActiveSupport::Concern
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Thread.current[:lit_request_keys] = {}
|
13
|
-
end
|
14
|
-
end
|
4
|
+
included do
|
5
|
+
Rails.logger.info 'DEPRECATED: Use include Lit::RequestKeysStore'
|
6
|
+
include Lit::RequestKeysStore
|
15
7
|
end
|
16
8
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module Lit
|
2
2
|
class LocalizationKeysController < ::Lit::ApplicationController
|
3
|
-
before_action :find_localization_scope,
|
4
|
-
|
5
|
-
before_action :find_localization_key,
|
6
|
-
only: %i[star destroy change_completed restore_deleted]
|
3
|
+
before_action :find_localization_scope, except: %i[destroy find_localization]
|
4
|
+
before_action :find_localization_key, only: %i[star destroy change_completed restore_deleted]
|
7
5
|
|
8
6
|
def index
|
9
7
|
get_localization_keys
|
@@ -20,27 +18,19 @@ module Lit
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def find_localization
|
23
|
-
localization_key = Lit::LocalizationKey.find_by!(
|
24
|
-
localization_key: params[:key]
|
25
|
-
)
|
21
|
+
localization_key = Lit::LocalizationKey.find_by!(localization_key: params[:key])
|
26
22
|
locale = Lit::Locale.find_by!(locale: params[:locale])
|
27
23
|
localization = localization_key.localizations.find_by(locale_id: locale)
|
28
|
-
render json: {
|
29
|
-
path: localization_key_localization_path(localization_key, localization)
|
30
|
-
}
|
24
|
+
render json: { path: localization_key_localization_path(localization_key, localization) }
|
31
25
|
end
|
32
26
|
|
33
27
|
def starred
|
34
28
|
@scope = @scope.where(is_starred: true)
|
35
29
|
|
36
|
-
if defined?(Kaminari) &&
|
37
|
-
@scope.respond_to?(Kaminari.config.page_method_name)
|
30
|
+
if defined?(Kaminari) && @scope.respond_to?(Kaminari.config.page_method_name)
|
38
31
|
@scope = @scope.send(Kaminari.config.page_method_name, params[:page])
|
39
32
|
end
|
40
|
-
if defined?(WillPaginate) &&
|
41
|
-
@scope.respond_to?(:paginate)
|
42
|
-
@scope = @scope.paginate(page: params[:page])
|
43
|
-
end
|
33
|
+
@scope = @scope.paginate(page: params[:page]) if defined?(WillPaginate) && @scope.respond_to?(:paginate)
|
44
34
|
get_localization_keys
|
45
35
|
render action: :index
|
46
36
|
end
|
@@ -66,6 +56,16 @@ module Lit
|
|
66
56
|
respond_to :js
|
67
57
|
end
|
68
58
|
|
59
|
+
def batch_touch
|
60
|
+
get_localization_keys
|
61
|
+
localization_key_ids = @scope.distinct(false).pluck(:id)
|
62
|
+
if localization_key_ids.any?
|
63
|
+
@scope.distinct(false).update_all updated_at: Time.current
|
64
|
+
Localization.where(localization_key_id: localization_key_ids).update_all updated_at: Time.current
|
65
|
+
end
|
66
|
+
respond_to :js
|
67
|
+
end
|
68
|
+
|
69
69
|
private
|
70
70
|
|
71
71
|
def find_localization_key
|
@@ -73,19 +73,16 @@ module Lit
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def find_localization_scope
|
76
|
-
@search_options =
|
77
|
-
|
78
|
-
else
|
79
|
-
params.slice(*valid_keys)
|
80
|
-
end
|
81
|
-
@scope = LocalizationKey.distinct.active
|
82
|
-
.preload(localizations: :locale)
|
83
|
-
.search(@search_options)
|
76
|
+
@search_options = params.respond_to?(:permit) ? params.permit(*valid_keys) : params.slice(*valid_keys)
|
77
|
+
@scope = LocalizationKey.distinct.active.preload(localizations: :locale).search(@search_options)
|
84
78
|
end
|
85
79
|
|
86
80
|
def get_localization_keys
|
87
81
|
key_parts = @search_options[:key_prefix].to_s.split('.').length
|
88
|
-
@prefixes =
|
82
|
+
@prefixes =
|
83
|
+
@scope.reorder(nil).distinct.pluck(:localization_key).map do |lk|
|
84
|
+
lk.split('.').shift(key_parts + 1).join('.')
|
85
|
+
end.uniq.sort
|
89
86
|
if @search_options[:key_prefix].present?
|
90
87
|
parts = @search_options[:key_prefix].split('.')
|
91
88
|
@parent_prefix = parts[0, parts.length - 1].join('.')
|
@@ -104,16 +101,15 @@ module Lit
|
|
104
101
|
end
|
105
102
|
|
106
103
|
def grouped_localizations
|
107
|
-
@_grouped_localizations ||=
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
hash[lk][l.locale.locale.to_sym] = l
|
104
|
+
@_grouped_localizations ||=
|
105
|
+
begin
|
106
|
+
{}.tap do |hash|
|
107
|
+
@localization_keys.each do |lk|
|
108
|
+
hash[lk] = {}
|
109
|
+
lk.localizations.each { |l| hash[lk][l.locale.locale.to_sym] = l }
|
113
110
|
end
|
114
111
|
end
|
115
112
|
end
|
116
|
-
end
|
117
113
|
end
|
118
114
|
|
119
115
|
def localization_for(locale, localization_key)
|
@@ -136,12 +132,16 @@ module Lit
|
|
136
132
|
helper_method :localization_for
|
137
133
|
|
138
134
|
def versions?(localization)
|
139
|
-
@_versions ||=
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
135
|
+
@_versions ||=
|
136
|
+
begin
|
137
|
+
ids = grouped_localizations.values.map(&:values).flatten.map(&:id)
|
138
|
+
Lit::Localization
|
139
|
+
.active
|
140
|
+
.where(id: ids)
|
141
|
+
.joins(:versions)
|
142
|
+
.group("#{Lit::Localization.quoted_table_name}.id")
|
143
|
+
.count
|
144
|
+
end
|
145
145
|
@_versions[localization.id].to_i > 0
|
146
146
|
end
|
147
147
|
helper_method :versions?
|