j1-template 2021.2.5 → 2021.2.9
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/_includes/themes/j1/modules/connectors/translators/google-translator.html +2 -1
- data/_layouts/default.html +0 -1
- data/assets/data/iso-639-language-codes-flags.json +224 -0
- data/assets/data/{translator_languages.json → iso-639-language-codes.json} +111 -142
- data/assets/data/translator.html +23 -19
- data/assets/themes/j1/adapter/js/translator.1.js +525 -0
- data/assets/themes/j1/adapter/js/translator.js +107 -168
- data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.css +27 -12
- data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.min.css +1 -1
- data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.css +27 -12
- data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.min.css +1 -1
- data/assets/themes/j1/core/css/themes/uno-light/bootstrap.css +59 -22
- data/assets/themes/j1/core/css/themes/uno-light/bootstrap.min.css +1 -1
- data/assets/themes/j1/modules/translator/js/translator.js +217 -242
- data/assets/themes/j1/modules/translator/js/translator.min.js +2 -2
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/Gemfile +1 -1
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/j1_config.yml +2 -22
- data/lib/starter_web/_data/modules/defaults/translator.yml +77 -64
- data/lib/starter_web/_data/modules/translator.yml +1 -0
- data/lib/starter_web/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/_plugins/lunr_index.rb +1 -1
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/400_asciidoc_extensions.adoc +3 -3
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +5 -4
- data/assets/data/msdropdown.json +0 -155
data/assets/data/translator.html
CHANGED
@@ -64,20 +64,22 @@ exclude_from_search: true
|
|
64
64
|
{% comment %} i18n: translations
|
65
65
|
-------------------------------------------------------------------------------- {% endcomment %}
|
66
66
|
|
67
|
-
{% comment %} Modal
|
67
|
+
{% comment %} Modal Google Translator dialog (default: en-EN)
|
68
68
|
-------------------------------------------------------------------------------- {% endcomment %}
|
69
69
|
<div id="google-data-en">
|
70
70
|
<div id="modal-google-translate-en" class="modal-dialog modal-frame modal-top modal-notify modal-primary" role="document">
|
71
71
|
<div class="modal-content">
|
72
72
|
|
73
73
|
<div class="modal-header">
|
74
|
-
<p class="lead">{{translate_options.modal_settings.title.en}}</p>
|
74
|
+
<p class="lead">{{translate_options.google.modal_settings.title.en}}</p>
|
75
75
|
</div>
|
76
76
|
|
77
77
|
<div class="modal-body">
|
78
78
|
<div class="modal-body-text" style="font-size: 90%">
|
79
|
-
<p class="mb-3">{{translate_options.modal_settings.body_text.en}}</p>
|
79
|
+
<p class="mb-3">{{translate_options.google.modal_settings.body_text.en}}</p>
|
80
80
|
</div>
|
81
|
+
<p style="font-size: 90%">{{translate_options.google.modal_settings.language_selector_title.en}}</p>
|
82
|
+
<div id="dropdownJSON" class="mb-4" style="display:none"></div>
|
81
83
|
<p>
|
82
84
|
<a href="#google-privacy" data-toggle="collapse" class="">Privacy Notice</a>
|
83
85
|
<a href="#google-options" data-toggle="collapse" class="float-right">My Settings</a>
|
@@ -85,7 +87,7 @@ exclude_from_search: true
|
|
85
87
|
|
86
88
|
<div id="google-privacy" class="collapse">
|
87
89
|
<div class="modal-body-text" style="font-size: 90%">
|
88
|
-
<p class="mb-4">{{translate_options.modal_settings.privacy_notice.en}}</p>
|
90
|
+
<p class="mb-4">{{translate_options.google.modal_settings.privacy_notice.en}}</p>
|
89
91
|
</div>
|
90
92
|
</div>
|
91
93
|
|
@@ -148,16 +150,16 @@ exclude_from_search: true
|
|
148
150
|
</div>
|
149
151
|
|
150
152
|
<div class="modal-footer">
|
151
|
-
<button id="translator-buttonDoNotAgree" type="button" class="btn btn-link text-decoration-none" style="">
|
153
|
+
<button id="translator-buttonDoNotAgree" type="button" class="btn btn-link text-decoration-none" style="min-width: 20rem">
|
152
154
|
No, disable translation
|
153
155
|
</button>
|
154
|
-
<button id="translator-buttonAgree" type="button" class="btn btn-primary btn-raised" style="">
|
156
|
+
<button id="translator-buttonAgree" type="button" class="btn btn-primary btn-raised" style="min-width: 20rem">
|
155
157
|
Yes, please translate
|
156
158
|
</button>
|
157
|
-
<button id="translator-buttonSave" type="button" class="btn btn-primary" style="display:
|
159
|
+
<button id="translator-buttonSave" type="button" class="btn btn-primary" style="display:none; min-width: 20rem">
|
158
160
|
Save selection
|
159
161
|
</button>
|
160
|
-
<button id="translator-buttonAgreeAll" type="button" class="btn btn-primary btn-raised" style="display:
|
162
|
+
<button id="translator-buttonAgreeAll" type="button" class="btn btn-primary btn-raised" style="display:none; min-width: 20rem">
|
161
163
|
I Agree on all
|
162
164
|
</button>
|
163
165
|
</div>
|
@@ -166,21 +168,23 @@ exclude_from_search: true
|
|
166
168
|
</div>
|
167
169
|
</div>
|
168
170
|
|
169
|
-
{% comment %} END Modal
|
171
|
+
{% comment %} END Modal Google Translator dialog (en-EN)
|
170
172
|
-------------------------------------------------------------------------------- {% endcomment %}
|
171
173
|
|
172
|
-
{% comment %} Modal
|
174
|
+
{% comment %} Modal Google Translator dialog (de-DE)
|
173
175
|
-------------------------------------------------------------------------------- {% endcomment %}
|
174
176
|
<div id="google-data-de">
|
175
177
|
<div id="modal-google-translate-de" class="modal-dialog modal-frame modal-top modal-notify modal-primary" role="document">
|
176
178
|
<div class="modal-content">
|
177
179
|
<div class="modal-header">
|
178
|
-
<p class="lead">{{translate_options.modal_settings.title.de}}</p>
|
180
|
+
<p class="lead">{{translate_options.google.modal_settings.title.de}}</p>
|
179
181
|
</div>
|
180
182
|
<div class="modal-body">
|
181
183
|
<div class="modal-body-text" style="font-size: 90%">
|
182
|
-
<p class="mb-4">{{translate_options.modal_settings.body_text.de}}</p>
|
184
|
+
<p class="mb-4">{{translate_options.google.modal_settings.body_text.de}}</p>
|
183
185
|
</div>
|
186
|
+
<p style="font-size: 90%">{{translate_options.google.modal_settings.language_selector_title.de}}</p>
|
187
|
+
<div id="dropdownJSON" class="mb-4" style="display:none"></div>
|
184
188
|
<p>
|
185
189
|
<a href="#google-privacy" data-toggle="collapse" class="">Datenschutzerklärung</a>
|
186
190
|
<a href="#google-options" data-toggle="collapse" class="float-right">Meine Einstellungen</a>
|
@@ -188,7 +192,7 @@ exclude_from_search: true
|
|
188
192
|
|
189
193
|
<div id="google-privacy" class="collapse">
|
190
194
|
<div class="modal-body-text" style="font-size: 90%">
|
191
|
-
<p class="mb-4">{{translate_options.modal_settings.privacy_notice.de}}</p>
|
195
|
+
<p class="mb-4">{{translate_options.google.modal_settings.privacy_notice.de}}</p>
|
192
196
|
</div>
|
193
197
|
</div>
|
194
198
|
|
@@ -261,16 +265,16 @@ exclude_from_search: true
|
|
261
265
|
</div>
|
262
266
|
|
263
267
|
<div class="modal-footer">
|
264
|
-
<button id="translator-buttonDoNotAgree" type="button" class="btn btn-link text-decoration-none" style="">
|
265
|
-
Nein,
|
268
|
+
<button id="translator-buttonDoNotAgree" type="button" class="btn btn-link text-decoration-none" style="min-width: 20rem">
|
269
|
+
Nein, Übersetzung abschalten
|
266
270
|
</button>
|
267
|
-
<button id="translator-buttonAgree" type="button" class="btn btn-primary btn-raised" style="">
|
271
|
+
<button id="translator-buttonAgree" type="button" class="btn btn-primary btn-raised" style="min-width: 20rem">
|
268
272
|
Ja, bitte übersetzen
|
269
273
|
</button>
|
270
|
-
<button id="translator-buttonSave" type="button" class="btn btn-primary" style="display:
|
274
|
+
<button id="translator-buttonSave" type="button" class="btn btn-primary" style="display:none; min-width: 20rem">
|
271
275
|
Auswahl speichern
|
272
276
|
</button>
|
273
|
-
<button id="translator-buttonAgreeAll" type="button" class="btn btn-primary btn-raised" style="display:
|
277
|
+
<button id="translator-buttonAgreeAll" type="button" class="btn btn-primary btn-raised" style="display:none; min-width: 20rem">
|
274
278
|
Allen zustimmen
|
275
279
|
</button>
|
276
280
|
</div>
|
@@ -278,7 +282,7 @@ exclude_from_search: true
|
|
278
282
|
</div>
|
279
283
|
</div>
|
280
284
|
</div>
|
281
|
-
{% comment %} END Modal
|
285
|
+
{% comment %} END Modal Google Translator dialog (de-DE)
|
282
286
|
-------------------------------------------------------------------------------- {% endcomment %}
|
283
287
|
|
284
288
|
{% endcapture %}
|
@@ -0,0 +1,525 @@
|
|
1
|
+
---
|
2
|
+
regenerate: true
|
3
|
+
---
|
4
|
+
|
5
|
+
{% capture cache %}
|
6
|
+
|
7
|
+
{% comment %}
|
8
|
+
# -----------------------------------------------------------------------------
|
9
|
+
# ~/assets/themes/j1/adapter/js/translator.js
|
10
|
+
# Liquid template to create the Template Adapter for J1 Translator
|
11
|
+
#
|
12
|
+
# Product/Info:
|
13
|
+
# http://jekyll.one
|
14
|
+
#
|
15
|
+
# Copyright (C) 2021 Juergen Adams
|
16
|
+
#
|
17
|
+
# J1 Template is licensed under the MIT License.
|
18
|
+
# For details, see https://jekyll.one
|
19
|
+
# -----------------------------------------------------------------------------
|
20
|
+
# Test data:
|
21
|
+
# {{ liquid_var | debug }}
|
22
|
+
# -----------------------------------------------------------------------------
|
23
|
+
{% endcomment %}
|
24
|
+
|
25
|
+
{% comment %} Liquid var initialization
|
26
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
27
|
+
|
28
|
+
{% comment %} Set config files
|
29
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
30
|
+
{% assign environment = site.environment %}
|
31
|
+
{% assign blocks = site.data.blocks %}
|
32
|
+
{% assign modules = site.data.modules %}
|
33
|
+
{% assign template_config = site.data.j1_config %}
|
34
|
+
|
35
|
+
{% comment %} Set config data
|
36
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
37
|
+
{% assign translator_defaults = modules.defaults.translator.defaults %}
|
38
|
+
{% assign translator_settings = modules.translator.settings %}
|
39
|
+
{% assign tracking_enabled = template_config.analytics.enabled %}
|
40
|
+
|
41
|
+
|
42
|
+
{% comment %} Set config options
|
43
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
44
|
+
{% assign translator_options = translator_defaults | merge: translator_settings %}
|
45
|
+
|
46
|
+
{% assign production = false %}
|
47
|
+
{% if environment == 'prod' or environment == 'production' %}
|
48
|
+
{% assign production = true %}
|
49
|
+
{% endif %}
|
50
|
+
|
51
|
+
/*
|
52
|
+
# -----------------------------------------------------------------------------
|
53
|
+
# ~/assets/themes/j1/adapter/js/translator.js
|
54
|
+
# JS Adapter for J1 Translate
|
55
|
+
#
|
56
|
+
# Product/Info:
|
57
|
+
# http://jekyll.one
|
58
|
+
#
|
59
|
+
# Copyright (C) 2021 Juergen Adams
|
60
|
+
#
|
61
|
+
# J1 Template is licensed under MIT License.
|
62
|
+
# See: https://github.com/jekyll-one/J1 Template/blob/master/LICENSE
|
63
|
+
# -----------------------------------------------------------------------------
|
64
|
+
# Adapter generated: {{site.time}}
|
65
|
+
# -----------------------------------------------------------------------------
|
66
|
+
*/
|
67
|
+
|
68
|
+
// -----------------------------------------------------------------------------
|
69
|
+
// ESLint shimming
|
70
|
+
// -----------------------------------------------------------------------------
|
71
|
+
/* eslint indent: "off" */
|
72
|
+
/* eslint quotes: "off" */
|
73
|
+
// -----------------------------------------------------------------------------
|
74
|
+
// https://github.com/EdwardBalaj/Simple-DeepL-API-Integration
|
75
|
+
// https://github.com/marghoobsuleman/ms-Dropdown
|
76
|
+
// https://www.marghoobsuleman.com/image-dropdown/help
|
77
|
+
// https://www.marghoobsuleman.com/image-dropdown/advanced-help
|
78
|
+
'use strict';
|
79
|
+
|
80
|
+
{% comment %} Main
|
81
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
82
|
+
j1.adapter['translator'] = (function (j1, window) {
|
83
|
+
|
84
|
+
var environment = '{{environment}}';
|
85
|
+
var tracking_enabled = ('{{tracking_enabled}}' === 'true') ? true: false; // Analytics/GA enabled?
|
86
|
+
var moduleOptions = {};
|
87
|
+
var user_translate = {};
|
88
|
+
var _this;
|
89
|
+
var $modal;
|
90
|
+
var domain;
|
91
|
+
var cookie_names;
|
92
|
+
var user_consent;
|
93
|
+
var logger;
|
94
|
+
var url;
|
95
|
+
var baseUrl;
|
96
|
+
var hostname;
|
97
|
+
var domain;
|
98
|
+
var cookie_sub_domains;
|
99
|
+
var secure;
|
100
|
+
var logText;
|
101
|
+
var cookie_written;
|
102
|
+
var modal_language;
|
103
|
+
var navigator_language;
|
104
|
+
var translation_language;
|
105
|
+
var ddSourceLanguage;
|
106
|
+
var head;
|
107
|
+
var script;
|
108
|
+
var languageList;
|
109
|
+
|
110
|
+
// ---------------------------------------------------------------------------
|
111
|
+
// helper functions
|
112
|
+
// ---------------------------------------------------------------------------
|
113
|
+
|
114
|
+
// ---------------------------------------------------------------------------
|
115
|
+
// setCookie()
|
116
|
+
// writes a flat cookie (not using an encoded JSON string)
|
117
|
+
// ---------------------------------------------------------------------------
|
118
|
+
function setCookie(options /*cName, cValue, expDays*/) {
|
119
|
+
var defaults = {};
|
120
|
+
var settings;
|
121
|
+
var document_cookie;
|
122
|
+
var stringifiedAttributes = '';
|
123
|
+
|
124
|
+
defaults = {
|
125
|
+
name: '',
|
126
|
+
path: '/',
|
127
|
+
expires: 0,
|
128
|
+
domain: 'localhost',
|
129
|
+
samesite: 'Strict',
|
130
|
+
http_only: false,
|
131
|
+
secure: false
|
132
|
+
};
|
133
|
+
settings = $.extend(defaults, options);
|
134
|
+
|
135
|
+
stringifiedAttributes += '; ' + 'path=' + settings.path;
|
136
|
+
|
137
|
+
if (settings.expires > 0) {
|
138
|
+
date.setTime(date.getTime() + (settings.expires * 24 * 60 * 60 * 1000));
|
139
|
+
stringifiedAttributes += '; ' + 'expires=' + date.toUTCString();
|
140
|
+
}
|
141
|
+
|
142
|
+
stringifiedAttributes += '; ' + 'SameSite=' + settings.samesite;
|
143
|
+
|
144
|
+
if (settings.secure) {
|
145
|
+
stringifiedAttributes += '; ' + 'secure=' + settings.secure;
|
146
|
+
}
|
147
|
+
|
148
|
+
// document_cookie = settings.name + '=' + settings.data + '; path=' + settings.path + '; ' + 'domain=' + settings.domain + '; ' + 'SameSite=' + settings.samesite + ';';
|
149
|
+
document_cookie = settings.name + '=' + settings.data + stringifiedAttributes;
|
150
|
+
|
151
|
+
document.cookie = document_cookie;
|
152
|
+
};
|
153
|
+
|
154
|
+
// ---------------------------------------------------------------------------
|
155
|
+
// Main object
|
156
|
+
// ---------------------------------------------------------------------------
|
157
|
+
return {
|
158
|
+
|
159
|
+
// -------------------------------------------------------------------------
|
160
|
+
// Initializer
|
161
|
+
// -------------------------------------------------------------------------
|
162
|
+
init: function (options) {
|
163
|
+
|
164
|
+
// -----------------------------------------------------------------------
|
165
|
+
// globals
|
166
|
+
// -----------------------------------------------------------------------
|
167
|
+
_this = j1.adapter.translator;
|
168
|
+
logger = log4javascript.getLogger('j1.adapter.translator');
|
169
|
+
url = new liteURL(window.location.href);
|
170
|
+
baseUrl = url.origin;
|
171
|
+
hostname = url.hostname;
|
172
|
+
domain = hostname.substring(hostname.lastIndexOf('.', hostname.lastIndexOf('.') - 1) + 1);
|
173
|
+
secure = (url.protocol.includes('https')) ? true : false;
|
174
|
+
modal_language = "{{site.language}}";
|
175
|
+
navigator_language = navigator.language || navigator.userLanguage; // userLanguage for MS IE compatibility
|
176
|
+
translation_language = navigator_language.split('-')[0];
|
177
|
+
cookie_names = j1.getCookieNames();
|
178
|
+
head = document.getElementsByTagName('head')[0];
|
179
|
+
script = document.createElement('script');
|
180
|
+
script.id = 'google-translate';
|
181
|
+
script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
|
182
|
+
|
183
|
+
user_translate = {
|
184
|
+
'translatorName': 'google',
|
185
|
+
'translationEnabled': false,
|
186
|
+
'analysis': true,
|
187
|
+
'personalization': true,
|
188
|
+
'translateAllPages': true,
|
189
|
+
'useLanguageFromBrowser': true,
|
190
|
+
'translationLanguage': translation_language,
|
191
|
+
};
|
192
|
+
|
193
|
+
// set domain used by cookies
|
194
|
+
if(domain !== 'localhost') {
|
195
|
+
cookie_sub_domains = '.' + hostname;
|
196
|
+
} else {
|
197
|
+
cookie_sub_domains = hostname;
|
198
|
+
}
|
199
|
+
|
200
|
+
if (j1.existsCookie(cookie_names.user_translate)) {
|
201
|
+
user_translate = j1.readCookie(cookie_names.user_translate);
|
202
|
+
} else {
|
203
|
+
logger.debug('\n' + 'write to cookie : ' + cookie_names.user_translate);
|
204
|
+
cookie_written = j1.writeCookie({
|
205
|
+
name: cookie_names.user_translate,
|
206
|
+
data: user_translate,
|
207
|
+
samesite: 'Strict',
|
208
|
+
expires: 365
|
209
|
+
});
|
210
|
+
}
|
211
|
+
|
212
|
+
// set domain used by cookies
|
213
|
+
if(domain !== 'localhost') {
|
214
|
+
cookie_sub_domains = '.' + hostname;
|
215
|
+
} else {
|
216
|
+
cookie_sub_domains = hostname;
|
217
|
+
}
|
218
|
+
|
219
|
+
// initialize state flag
|
220
|
+
_this.state = 'pending';
|
221
|
+
// _this.settings.languageList = '/assets/data/ms_select.json';
|
222
|
+
|
223
|
+
// -----------------------------------------------------------------------
|
224
|
+
// Default module settings
|
225
|
+
// -----------------------------------------------------------------------
|
226
|
+
var settings = $.extend({
|
227
|
+
module_name: 'j1.adapter.translator',
|
228
|
+
generated: '{{site.time}}'
|
229
|
+
}, options);
|
230
|
+
|
231
|
+
{% comment %} Load module config from yml data
|
232
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
233
|
+
// Load module DEFAULTS|CONFIG
|
234
|
+
/* eslint-disable */
|
235
|
+
moduleOptions = $.extend({}, {{translator_options | replace: '=>', ':' | replace: 'nil', '""'}});
|
236
|
+
/* eslint-enable */
|
237
|
+
|
238
|
+
if (typeof settings !== 'undefined') {
|
239
|
+
moduleOptions = j1.mergeData(moduleOptions, settings);
|
240
|
+
}
|
241
|
+
|
242
|
+
// -----------------------------------------------------------------------
|
243
|
+
// initializer
|
244
|
+
// -----------------------------------------------------------------------
|
245
|
+
var dependencies_met_page_ready = setInterval (function (options) {
|
246
|
+
user_consent = j1.readCookie(cookie_names.user_consent);
|
247
|
+
|
248
|
+
if ( j1.getState() === 'finished' ) {
|
249
|
+
_this.setState('started');
|
250
|
+
logger.info('\n' + 'state: ' + _this.getState());
|
251
|
+
logger.info('\n' + 'module is being initialized');
|
252
|
+
|
253
|
+
if ($('google_translate_element')) {
|
254
|
+
$('google_translate_element').hide();
|
255
|
+
}
|
256
|
+
|
257
|
+
// show|hide translate button if enabled
|
258
|
+
if (moduleOptions.hideTranslatorIcon) {
|
259
|
+
if (!user_consent.analysis || !user_consent.personalization) {
|
260
|
+
// disable google translate button if visible
|
261
|
+
if ($('#quickLinksTranslateButton').css('display') === 'block') {
|
262
|
+
$('#quickLinksTranslateButton').css('display', 'none');
|
263
|
+
}
|
264
|
+
}
|
265
|
+
if (user_consent.analysis && user_consent.personalization) {
|
266
|
+
// enable google translate button if not visible
|
267
|
+
if ($('#quickLinksTranslateButton').css('display') === 'none') {
|
268
|
+
$('#quickLinksTranslateButton').css('display', 'block');
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
// update user_translate cookie
|
274
|
+
user_translate.analysis = user_consent.analysis;
|
275
|
+
user_translate.personalization = user_consent.personalization;
|
276
|
+
cookie_written = j1.writeCookie({
|
277
|
+
name: cookie_names.user_translate,
|
278
|
+
data: user_translate,
|
279
|
+
samesite: 'Strict',
|
280
|
+
secure: secure
|
281
|
+
});
|
282
|
+
|
283
|
+
j1.translator = new Translator({
|
284
|
+
contentURL: moduleOptions.contentURL, // dialog content (modals) for all supported languages
|
285
|
+
cookieName: moduleOptions.cookieName, // the name of the User State Cookie (primary data)
|
286
|
+
cookieConsentName: moduleOptions.cookieConsentName, // the name of the Cookie Consent Cookie (secondary data)
|
287
|
+
disableLanguageSelector: moduleOptions.disableLanguageSelector, // disable language dropdown for translation in dialog (modal)
|
288
|
+
dialogContainerID: moduleOptions.dialogContainerID, // dest container, the dialog modal is loaded (dynamically)
|
289
|
+
dialogLanguage: moduleOptions.dialogLanguage, // language for the dialog (modal)
|
290
|
+
translationLanguage: moduleOptions.translationLanguage, // default language for translation
|
291
|
+
translationLanguages: moduleOptions.google.translationLanguages,// supported languages for translation
|
292
|
+
translationEnabled: moduleOptions.translationEnabled, // run translation enabled|disabled
|
293
|
+
translatorName: moduleOptions.translatorName, // translator used for translation
|
294
|
+
xhrDataElement: moduleOptions.xhrDataElement, // container for all language-specific dialogs (modals)
|
295
|
+
postSelectionCallback: moduleOptions.google.postSelectionCallback
|
296
|
+
});
|
297
|
+
|
298
|
+
if (user_consent.analysis && user_consent.personalization && user_translate.translationEnabled) {
|
299
|
+
if (moduleOptions.translatorName === 'google') {
|
300
|
+
head.appendChild(script);
|
301
|
+
if ($('google_translate_element')) {
|
302
|
+
$('google_translate_element').hide();
|
303
|
+
}
|
304
|
+
}
|
305
|
+
} else {
|
306
|
+
if (moduleOptions.translatorName === 'google') {
|
307
|
+
j1.removeCookie({name: 'googtrans', domain: domain});
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
_this.setState('finished');
|
312
|
+
logger.info('\n' + 'state: ' + _this.getState());
|
313
|
+
logger.debug('\n' + 'module initialized successfully');
|
314
|
+
clearInterval(dependencies_met_page_ready);
|
315
|
+
}
|
316
|
+
});
|
317
|
+
}, // END init
|
318
|
+
|
319
|
+
// -------------------------------------------------------------------------
|
320
|
+
// messageHandler: MessageHandler for J1 google_translate module
|
321
|
+
// Manage messages send from other J1 modules
|
322
|
+
// -------------------------------------------------------------------------
|
323
|
+
messageHandler: function (sender, message) {
|
324
|
+
var json_message = JSON.stringify(message, undefined, 2);
|
325
|
+
|
326
|
+
logText = '\n' + 'received message from ' + sender + ': ' + json_message;
|
327
|
+
logger.debug(logText);
|
328
|
+
|
329
|
+
// -----------------------------------------------------------------------
|
330
|
+
// Process commands|actions
|
331
|
+
// -----------------------------------------------------------------------
|
332
|
+
if (message.type === 'command' && message.action === 'module_initialized') {
|
333
|
+
//
|
334
|
+
// Place handling of command|action here
|
335
|
+
//
|
336
|
+
logger.info('\n' + message.text);
|
337
|
+
}
|
338
|
+
|
339
|
+
//
|
340
|
+
// Place handling of other command|action here
|
341
|
+
//
|
342
|
+
|
343
|
+
return true;
|
344
|
+
}, // END messageHandler
|
345
|
+
|
346
|
+
// -------------------------------------------------------------------------
|
347
|
+
// setState()
|
348
|
+
// Sets the current (processing) state of the module
|
349
|
+
// -------------------------------------------------------------------------
|
350
|
+
setState: function (stat) {
|
351
|
+
_this.state = stat;
|
352
|
+
}, // END setState
|
353
|
+
|
354
|
+
// -------------------------------------------------------------------------
|
355
|
+
// getState()
|
356
|
+
// Returns the current (processing) state of the module
|
357
|
+
// -------------------------------------------------------------------------
|
358
|
+
getState: function () {
|
359
|
+
return _this.state;
|
360
|
+
}, // END getState
|
361
|
+
|
362
|
+
// -------------------------------------------------------------------------
|
363
|
+
// postTranslateElementInit()
|
364
|
+
// ???
|
365
|
+
// -------------------------------------------------------------------------
|
366
|
+
postTranslateElementInit: function () {
|
367
|
+
// var transCode = '/en/de';
|
368
|
+
//
|
369
|
+
// // set the transCode cookie (googtrans)
|
370
|
+
// setCookie({
|
371
|
+
// name: 'googtrans',
|
372
|
+
// data: transCode
|
373
|
+
// });
|
374
|
+
// j1.removeCookie({name: 'googtrans', domain: domain});
|
375
|
+
return;
|
376
|
+
}, // END postTranslateElementInit
|
377
|
+
|
378
|
+
// -------------------------------------------------------------------------
|
379
|
+
// cbGoogle()
|
380
|
+
// Called by the translator CORE module after the user
|
381
|
+
// has made the lanuage selection for translation (callback)
|
382
|
+
// -------------------------------------------------------------------------
|
383
|
+
cbGoogle: function () {
|
384
|
+
var cookie_names = j1.getCookieNames();
|
385
|
+
var user_state = j1.readCookie(cookie_names.user_state);
|
386
|
+
var user_consent = j1.readCookie(cookie_names.user_consent);
|
387
|
+
var user_translate = j1.readCookie(cookie_names.user_translate);
|
388
|
+
var msDropdownLang = document.getElementById('dropdownJSON').msDropdown;
|
389
|
+
var msDropdown = document.getElementById('dropdownJSON').msDropdown;
|
390
|
+
var head;
|
391
|
+
var script;
|
392
|
+
var srcLang;
|
393
|
+
var destLang;
|
394
|
+
var transCode;
|
395
|
+
var cookie_written;
|
396
|
+
var htmlScriptElement;
|
397
|
+
var selectedTranslationLanguage;
|
398
|
+
|
399
|
+
logger.info('\n' + 'entered post selection callback from google_translate');
|
400
|
+
logger.debug('\n' + 'current values from cookie consent: ' + JSON.stringify(user_consent));
|
401
|
+
logger.debug('\n' + 'current values from user state: ' + JSON.stringify(user_state));
|
402
|
+
|
403
|
+
selectedTranslationLanguage = msDropdownLang.value;
|
404
|
+
logger.info('\n' + 'selected translation language: ' + selectedTranslationLanguage);
|
405
|
+
|
406
|
+
// update cookie consent settings
|
407
|
+
user_consent.analysis = user_translate.analysis;
|
408
|
+
user_consent.personalization = user_translate.personalization;
|
409
|
+
|
410
|
+
cookie_written = j1.writeCookie({
|
411
|
+
name: cookie_names.user_consent,
|
412
|
+
data: user_consent,
|
413
|
+
samesite: 'Strict',
|
414
|
+
secure: secure,
|
415
|
+
expires: 0
|
416
|
+
});
|
417
|
+
|
418
|
+
// translation allowed
|
419
|
+
if (user_consent.analysis && user_consent.personalization) {
|
420
|
+
head = document.getElementsByTagName('head')[0];
|
421
|
+
script = document.createElement('script');
|
422
|
+
script.id = 'google-translate';
|
423
|
+
script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
|
424
|
+
htmlScriptElement = document.getElementById(script.id);
|
425
|
+
|
426
|
+
if (user_translate.translationEnabled && moduleOptions.translatorName === 'google') {
|
427
|
+
// head.appendChild(script);
|
428
|
+
|
429
|
+
if ($('google_translate_element')) {
|
430
|
+
$('google_translate_element').hide();
|
431
|
+
}
|
432
|
+
|
433
|
+
// set transCode settings
|
434
|
+
srcLang = "{{site.language}}";
|
435
|
+
destLang = translation_language;
|
436
|
+
transCode = '/' + srcLang + '/' + selectedTranslationLanguage;
|
437
|
+
|
438
|
+
// set the transCode cookie (googtrans)
|
439
|
+
setCookie({
|
440
|
+
name: 'googtrans',
|
441
|
+
data: transCode
|
442
|
+
});
|
443
|
+
|
444
|
+
// enable google transalate button if not visible
|
445
|
+
if ($('#quickLinksTranslateButton').css('display') === 'none') {
|
446
|
+
$('#quickLinksTranslateButton').css('display', 'block');
|
447
|
+
}
|
448
|
+
} else { // translation NOT allowed
|
449
|
+
|
450
|
+
// update cookie user translate settings
|
451
|
+
user_translate.translationEnabled = false;
|
452
|
+
cookie_written = j1.writeCookie({
|
453
|
+
name: cookie_names.user_translate,
|
454
|
+
data: user_translate,
|
455
|
+
samesite: 'Strict',
|
456
|
+
secure: secure
|
457
|
+
});
|
458
|
+
|
459
|
+
// stop translation for all pages
|
460
|
+
if (htmlScriptElement) { htmlScriptElement.remove(); }
|
461
|
+
j1.removeCookie({name: 'googtrans', domain: domain});
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
// translation NOT allowed
|
466
|
+
if (!user_translate.analysis || !user_translate.personalization) {
|
467
|
+
head = document.getElementsByTagName('head')[0];
|
468
|
+
script = document.createElement('script');
|
469
|
+
script.id = 'google-translate';
|
470
|
+
|
471
|
+
// update cookie consent settings
|
472
|
+
user_consent.analysis = user_translate.analysis;
|
473
|
+
user_consent.personalization = user_translate.personalization;
|
474
|
+
cookie_written = j1.writeCookie({
|
475
|
+
name: cookie_names.user_consent,
|
476
|
+
data: user_consent,
|
477
|
+
samesite: 'Strict',
|
478
|
+
secure: secure,
|
479
|
+
expires: 0
|
480
|
+
});
|
481
|
+
|
482
|
+
// update cookie user translate settings
|
483
|
+
user_translate.translationEnabled = false;
|
484
|
+
cookie_written = j1.writeCookie({
|
485
|
+
name: cookie_names.user_translate,
|
486
|
+
data: user_consent,
|
487
|
+
samesite: 'Strict',
|
488
|
+
secure: secure,
|
489
|
+
expires: 0
|
490
|
+
});
|
491
|
+
|
492
|
+
// stop translation for all pages
|
493
|
+
if (htmlScriptElement) { htmlScriptElement.remove(); }
|
494
|
+
j1.removeCookie({name: 'googtrans', domain: domain});
|
495
|
+
}
|
496
|
+
|
497
|
+
if (moduleOptions.reloadPageOnChange) {
|
498
|
+
// reload current page (skip cache)
|
499
|
+
location.reload(true);
|
500
|
+
}
|
501
|
+
|
502
|
+
// disable google translate button if visible
|
503
|
+
if ($('#quickLinksTranslateButton').css('display') === 'block') {
|
504
|
+
$('#quickLinksTranslateButton').css('display', 'none');
|
505
|
+
}
|
506
|
+
|
507
|
+
}, // END cbGoogle
|
508
|
+
|
509
|
+
// -------------------------------------------------------------------------
|
510
|
+
// cbDeepl()
|
511
|
+
// Called by the translator CORE module after the user
|
512
|
+
// has made the lanuage selection for translation (callback)
|
513
|
+
// -------------------------------------------------------------------------
|
514
|
+
cbDeepl: function () {
|
515
|
+
|
516
|
+
// code for post procession on Deepl translations
|
517
|
+
|
518
|
+
} // END cbDeepl
|
519
|
+
|
520
|
+
}; // END return
|
521
|
+
})(j1, window);
|
522
|
+
|
523
|
+
{% endcapture %}
|
524
|
+
{{ cache | strip_empty_lines }}
|
525
|
+
{% assign cache = nil %}
|