trestle-mobility 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/app/assets/javascript/trestle/mobility.js +3 -1
- data/app/controllers/trestle/mobility/translations_controller.rb +3 -2
- data/app/views/trestle/mobility/_deepl_translation_action.html.erb +1 -1
- data/app/views/trestle/mobility/_text_area.html.erb +25 -3
- data/app/views/trestle/mobility/_text_field.html.erb +19 -3
- data/lib/trestle/mobility/fields/text_area.rb +7 -2
- data/lib/trestle/mobility/fields/text_field.rb +4 -1
- data/lib/trestle/mobility/translators/deepl_translator.rb +2 -2
- data/lib/trestle/mobility/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e0287bd55e3ad8e8bfdc53fbb7c7dc50e79ad7a7059152a8d1c5012d3a8d77
|
4
|
+
data.tar.gz: cff3fc7d63c6933f0d5e76469b2ab6311c842b870c635a60539a0c4bf7425132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0fce0bba275227b9aeb0ae843bde24cd997404a9b2e498810e19ec2d0d6af73617cde24829499701bd7497eb832fc42bd1853191ce07c13435be661ee454bfd
|
7
|
+
data.tar.gz: b99ab55a32050210d38b6a5bd80758d4a4faf21299cf8945c9328193af4923a3a8d892283bee5186bfef8b554b89d12cfdd7a0f93ffbb6add8f731d38949e2d7
|
data/README.md
CHANGED
@@ -68,3 +68,9 @@ Trestle Mobility can automatically populate empty field values with translations
|
|
68
68
|
```ruby
|
69
69
|
config.mobility.deepl_api_key = "YOUR-API-KEY"
|
70
70
|
```
|
71
|
+
|
72
|
+
It is possible to pass any DeepL API options to the field (check out the [deepl-rb documentation](https://github.com/wikiti/deepl-rb#translate) section on params):
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
mobility_text_area :content, rows: 14, deepl_query_params: { tag_handling: "xml" }
|
76
|
+
```
|
@@ -64,11 +64,13 @@ Trestle.init(function(e, root) {
|
|
64
64
|
Mobility.prototype.deeplTranslate = function (fromLocale) {
|
65
65
|
var self = this;
|
66
66
|
var path = this.$deeplTranslationAction.data('remote-path');
|
67
|
+
var queryParams = this.$deeplTranslationAction.data('deepl-query-params');
|
67
68
|
var data = {
|
68
69
|
translation: {
|
69
70
|
text: this.getFieldByLocale(fromLocale).val(),
|
70
71
|
from_locale: fromLocale,
|
71
|
-
to_locale: this.activeLocale
|
72
|
+
to_locale: this.activeLocale,
|
73
|
+
query_params: queryParams
|
72
74
|
}
|
73
75
|
}
|
74
76
|
|
@@ -3,7 +3,8 @@ class Trestle::Mobility::TranslationsController < Trestle::ApplicationController
|
|
3
3
|
translation = Trestle::Mobility::Translators::DeeplTranslator.new.translate(
|
4
4
|
translation_params[:text],
|
5
5
|
translation_params[:from_locale],
|
6
|
-
translation_params[:to_locale]
|
6
|
+
translation_params[:to_locale],
|
7
|
+
translation_params[:query_params] || {}
|
7
8
|
)
|
8
9
|
|
9
10
|
render plain: translation
|
@@ -11,6 +12,6 @@ class Trestle::Mobility::TranslationsController < Trestle::ApplicationController
|
|
11
12
|
|
12
13
|
private
|
13
14
|
def translation_params
|
14
|
-
params.require(:translation).permit(:text, :from_locale, :to_locale)
|
15
|
+
params.require(:translation).permit(:text, :from_locale, :to_locale, query_params: {})
|
15
16
|
end
|
16
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div class="mobility__deepl" data-remote-path="<%= trestle.translate_path %>">
|
1
|
+
<div class="mobility__deepl" data-remote-path="<%= trestle.translate_path %>" data-deepl-query-params="<%= deepl_query_params %>">
|
2
2
|
<small class="mobility__deepl-progress">Translating…</small>
|
3
3
|
|
4
4
|
<div class="btn-group">
|
@@ -9,10 +9,32 @@
|
|
9
9
|
<% end %>
|
10
10
|
</ul>
|
11
11
|
<% locales.each do |locale, index| %>
|
12
|
-
|
12
|
+
<%
|
13
|
+
value = instance.public_send(field_name)
|
14
|
+
value = value.try(:to_json) if options[:json]
|
15
|
+
%>
|
16
|
+
|
17
|
+
<%=
|
18
|
+
form.raw_text_area(
|
19
|
+
"#{field_name}_#{locale}",
|
20
|
+
options.merge(
|
21
|
+
value: value,
|
22
|
+
class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}",
|
23
|
+
placeholder: "#{label} (#{locale.upcase})",
|
24
|
+
data: { locale: locale }
|
25
|
+
)
|
26
|
+
)
|
27
|
+
%>
|
13
28
|
<% end %>
|
14
29
|
</div>
|
15
30
|
|
16
|
-
<%=
|
17
|
-
|
31
|
+
<%=
|
32
|
+
render(
|
33
|
+
partial: "trestle/mobility/deepl_translation_action",
|
34
|
+
locals: {
|
35
|
+
locales: locales,
|
36
|
+
deepl_query_params: deepl_query_params.to_json
|
37
|
+
}
|
38
|
+
) if Trestle.config.mobility.deepl_api_key
|
39
|
+
%>
|
18
40
|
</div>
|
@@ -11,10 +11,26 @@
|
|
11
11
|
</ul>
|
12
12
|
</div>
|
13
13
|
<% locales.each do |locale| %>
|
14
|
-
<%=
|
14
|
+
<%=
|
15
|
+
form.raw_text_field(
|
16
|
+
"#{field_name}_#{locale}",
|
17
|
+
options.merge(
|
18
|
+
class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}",
|
19
|
+
placeholder: "#{label} (#{locale.upcase})",
|
20
|
+
data: { locale: locale }
|
21
|
+
)
|
22
|
+
)
|
23
|
+
%>
|
15
24
|
<% end %>
|
16
25
|
</div>
|
17
26
|
|
18
|
-
<%=
|
19
|
-
|
27
|
+
<%=
|
28
|
+
render(
|
29
|
+
partial: "trestle/mobility/deepl_translation_action",
|
30
|
+
locals: {
|
31
|
+
locales: locales,
|
32
|
+
deepl_query_params: deepl_query_params.to_json
|
33
|
+
}
|
34
|
+
) if Trestle.config.mobility.deepl_api_key
|
35
|
+
%>
|
20
36
|
</div>
|
@@ -2,19 +2,24 @@ module Trestle
|
|
2
2
|
module Mobility
|
3
3
|
module Fields
|
4
4
|
class TextArea < Trestle::Form::Field
|
5
|
+
def defaults
|
6
|
+
super.merge(rows: 5)
|
7
|
+
end
|
8
|
+
|
5
9
|
def field
|
6
10
|
label = options[:label] || name.to_s.humanize
|
7
11
|
locales = options[:locales] || I18n.available_locales.sort
|
8
12
|
selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
|
9
|
-
|
13
|
+
deepl_query_params = options[:deepl_query_params] || {}
|
10
14
|
|
11
15
|
@template.render partial: "trestle/mobility/text_area",
|
12
16
|
locals: {
|
17
|
+
options: options,
|
13
18
|
field_name: name,
|
14
19
|
label: label,
|
15
20
|
locales: locales,
|
16
21
|
selected: selected,
|
17
|
-
|
22
|
+
deepl_query_params: deepl_query_params
|
18
23
|
}
|
19
24
|
end
|
20
25
|
end
|
@@ -6,13 +6,16 @@ module Trestle
|
|
6
6
|
label = options[:label] || name.to_s.humanize
|
7
7
|
locales = options[:locales] || I18n.available_locales.sort
|
8
8
|
selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
|
9
|
+
deepl_query_params = options[:deepl_query_params] || {}
|
9
10
|
|
10
11
|
@template.render partial: "trestle/mobility/text_field",
|
11
12
|
locals: {
|
13
|
+
options: options,
|
12
14
|
field_name: name,
|
13
15
|
label: label,
|
14
16
|
locales: locales,
|
15
|
-
selected: selected
|
17
|
+
selected: selected,
|
18
|
+
deepl_query_params: deepl_query_params
|
16
19
|
}
|
17
20
|
end
|
18
21
|
end
|
@@ -12,8 +12,8 @@ module Trestle::Mobility::Translators
|
|
12
12
|
configure_api_key!
|
13
13
|
end
|
14
14
|
|
15
|
-
def translate(text, from, to)
|
16
|
-
DeepL.translate(text, from, to)
|
15
|
+
def translate(text, from, to, query_params = {})
|
16
|
+
DeepL.translate(text, from, to, query_params)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trestle-mobility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: emoji_flag
|