j1-template 2021.2.7 → 2021.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_includes/themes/j1/modules/connectors/translators/google-translator.html +2 -1
- data/assets/themes/j1/adapter/js/translator.1.js +525 -0
- data/assets/themes/j1/adapter/js/translator.js +66 -137
- 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/_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/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38798bfdd94fe5814b0219fc7a5f7ea954dc58d8c119f7bead89ffafacf17aca
|
4
|
+
data.tar.gz: ab5ea5633b81a0b40eb6580348fd517d1cb0d0662ec2550aee1704af46a872f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de432f844dc08b37180ecc5335f8738a9a00de5f7691e133029b67b8b9aef64bcf69801e2fb31d56cf6ac702f43ce7b0c72233429b3e4f653fef487962acdc6
|
7
|
+
data.tar.gz: b9e7d4ec2d40e8792df712a50e225fde6386c60475ff8742b6878f4044ec68161e4e47f99b201d94d291bdcaca051556a06fe373b92872e0b793bdee06199f76
|
@@ -28,10 +28,11 @@
|
|
28
28
|
<!-- [INFO ] [j1.modules.connectors.translation ] [ place callback for the Google Translator API ] -->
|
29
29
|
<script>
|
30
30
|
function googleTranslateElementInit() {
|
31
|
-
new google.translate.TranslateElement({
|
31
|
+
var gtAPI = new google.translate.TranslateElement({
|
32
32
|
pageLanguage: 'en',
|
33
33
|
layout: google.translate.TranslateElement.FloatPosition.TOP_LEFT
|
34
34
|
},
|
35
35
|
'google_translate_element');
|
36
|
+
j1.adapter.translator.postTranslateElementInit(gtAPI);
|
36
37
|
}
|
37
38
|
</script>
|
@@ -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 %}
|
@@ -95,7 +95,7 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
95
95
|
var baseUrl;
|
96
96
|
var hostname;
|
97
97
|
var domain;
|
98
|
-
var
|
98
|
+
var cookie_sub_domains;
|
99
99
|
var secure;
|
100
100
|
var logText;
|
101
101
|
var cookie_written;
|
@@ -118,16 +118,37 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
118
118
|
function setCookie(options /*cName, cValue, expDays*/) {
|
119
119
|
var defaults = {};
|
120
120
|
var settings;
|
121
|
+
var document_cookie;
|
122
|
+
var stringifiedAttributes = '';
|
121
123
|
|
122
124
|
defaults = {
|
123
125
|
name: '',
|
124
126
|
path: '/',
|
125
127
|
expires: 0,
|
126
|
-
domain: 'localhost'
|
128
|
+
domain: 'localhost',
|
129
|
+
samesite: 'Strict',
|
130
|
+
http_only: false,
|
131
|
+
secure: false
|
127
132
|
};
|
128
133
|
settings = $.extend(defaults, options);
|
129
134
|
|
130
|
-
|
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;
|
131
152
|
};
|
132
153
|
|
133
154
|
// ---------------------------------------------------------------------------
|
@@ -169,13 +190,14 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
169
190
|
'translationLanguage': translation_language,
|
170
191
|
};
|
171
192
|
|
172
|
-
// set domain
|
193
|
+
// set sub domain settings for cookies
|
173
194
|
if(domain !== 'localhost') {
|
174
|
-
|
195
|
+
cookie_sub_domains = '.' + hostname;
|
175
196
|
} else {
|
176
|
-
|
197
|
+
cookie_sub_domains = hostname;
|
177
198
|
}
|
178
199
|
|
200
|
+
// load|initialize user translate cookie
|
179
201
|
if (j1.existsCookie(cookie_names.user_translate)) {
|
180
202
|
user_translate = j1.readCookie(cookie_names.user_translate);
|
181
203
|
} else {
|
@@ -188,13 +210,6 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
188
210
|
});
|
189
211
|
}
|
190
212
|
|
191
|
-
// set domain used by cookies
|
192
|
-
if(domain !== 'localhost') {
|
193
|
-
cookie_domain = '.' + hostname;
|
194
|
-
} else {
|
195
|
-
cookie_domain = hostname;
|
196
|
-
}
|
197
|
-
|
198
213
|
// initialize state flag
|
199
214
|
_this.state = 'pending';
|
200
215
|
// _this.settings.languageList = '/assets/data/ms_select.json';
|
@@ -229,6 +244,7 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
229
244
|
logger.info('\n' + 'state: ' + _this.getState());
|
230
245
|
logger.info('\n' + 'module is being initialized');
|
231
246
|
|
247
|
+
// hide the google translate element if exists
|
232
248
|
if ($('google_translate_element')) {
|
233
249
|
$('google_translate_element').hide();
|
234
250
|
}
|
@@ -274,15 +290,18 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
274
290
|
postSelectionCallback: moduleOptions.google.postSelectionCallback
|
275
291
|
});
|
276
292
|
|
293
|
+
// enable|disable translation (after callback)
|
277
294
|
if (user_consent.analysis && user_consent.personalization && user_translate.translationEnabled) {
|
278
295
|
if (moduleOptions.translatorName === 'google') {
|
279
296
|
head.appendChild(script);
|
280
|
-
$('google_translate_element')
|
297
|
+
if ($('google_translate_element')) {
|
298
|
+
$('google_translate_element').hide();
|
299
|
+
}
|
281
300
|
}
|
282
301
|
} else {
|
283
302
|
if (moduleOptions.translatorName === 'google') {
|
284
|
-
j1.removeCookie({name: 'googtrans', domain:
|
285
|
-
|
303
|
+
j1.removeCookie({name: 'googtrans', domain: domain});
|
304
|
+
}
|
286
305
|
}
|
287
306
|
|
288
307
|
_this.setState('finished');
|
@@ -336,146 +355,56 @@ j1.adapter['translator'] = (function (j1, window) {
|
|
336
355
|
return _this.state;
|
337
356
|
}, // END getState
|
338
357
|
|
358
|
+
// -------------------------------------------------------------------------
|
359
|
+
// postTranslateElementInit()
|
360
|
+
// ???
|
361
|
+
// -------------------------------------------------------------------------
|
362
|
+
postTranslateElementInit: function (response) {
|
363
|
+
// code for post processing
|
364
|
+
logger.info('\n' + 'postTranslateElementInit entered');
|
365
|
+
logger.info('\n' + response.T.Dh);
|
366
|
+
return;
|
367
|
+
}, // END postTranslateElementInit
|
368
|
+
|
339
369
|
// -------------------------------------------------------------------------
|
340
370
|
// cbGoogle()
|
341
|
-
// Called by the translator CORE module after the user
|
342
|
-
//
|
371
|
+
// Called by the translator CORE module after the user made the
|
372
|
+
// selection for a translation|language
|
343
373
|
// -------------------------------------------------------------------------
|
344
374
|
cbGoogle: function () {
|
345
|
-
var
|
346
|
-
var
|
347
|
-
var
|
348
|
-
var user_translate = j1.readCookie(cookie_names.user_translate);
|
349
|
-
var msDropdownLang = document.getElementById('dropdownJSON').msDropdown;
|
350
|
-
var msDropdown = document.getElementById('dropdownJSON').msDropdown;
|
351
|
-
var head;
|
352
|
-
var script;
|
375
|
+
var logger = log4javascript.getLogger('j1.adapter.translator.cbGoogle');
|
376
|
+
var msDropdown = document.getElementById('dropdownJSON').msDropdown;
|
377
|
+
var selectedTranslationLanguage;
|
353
378
|
var srcLang;
|
354
379
|
var destLang;
|
355
380
|
var transCode;
|
356
|
-
var cookie_written;
|
357
|
-
var htmlScriptElement;
|
358
|
-
var selectedTranslationLanguage;
|
359
381
|
|
360
|
-
|
361
|
-
logger.debug('\n' + 'current values from cookie consent: ' + JSON.stringify(user_consent));
|
362
|
-
logger.debug('\n' + 'current values from user state: ' + JSON.stringify(user_state));
|
363
|
-
|
364
|
-
selectedTranslationLanguage = msDropdownLang.value;
|
382
|
+
selectedTranslationLanguage = msDropdown.value;
|
365
383
|
logger.info('\n' + 'selected translation language: ' + selectedTranslationLanguage);
|
366
384
|
|
367
|
-
//
|
368
|
-
|
369
|
-
|
385
|
+
// set transCode settings
|
386
|
+
srcLang = "{{site.language}}";
|
387
|
+
destLang = translation_language;
|
388
|
+
transCode = '/' + srcLang + '/' + selectedTranslationLanguage;
|
370
389
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
secure: secure,
|
376
|
-
expires: 0
|
390
|
+
// write the googtrans cookie
|
391
|
+
setCookie({
|
392
|
+
name: 'googtrans',
|
393
|
+
data: transCode
|
377
394
|
});
|
378
395
|
|
379
|
-
//
|
380
|
-
|
381
|
-
head = document.getElementsByTagName('head')[0];
|
382
|
-
script = document.createElement('script');
|
383
|
-
script.id = 'google-translate';
|
384
|
-
script.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
|
385
|
-
htmlScriptElement = document.getElementById(script.id);
|
386
|
-
|
387
|
-
if (user_translate.translationEnabled && moduleOptions.translatorName === 'google') {
|
388
|
-
head.appendChild(script);
|
389
|
-
|
390
|
-
if ($('google_translate_element')) {
|
391
|
-
$('google_translate_element').hide();
|
392
|
-
}
|
393
|
-
|
394
|
-
// set transCode settings
|
395
|
-
srcLang = "{{site.language}}";
|
396
|
-
destLang = translation_language;
|
397
|
-
transCode = '/' + srcLang + '/' + selectedTranslationLanguage;
|
398
|
-
|
399
|
-
// set the transCode cookie (googtrans)
|
400
|
-
setCookie({
|
401
|
-
name: 'googtrans',
|
402
|
-
data: transCode
|
403
|
-
});
|
404
|
-
|
405
|
-
// enable google transalate button if not visible
|
406
|
-
if ($('#quickLinksTranslateButton').css('display') === 'none') {
|
407
|
-
$('#quickLinksTranslateButton').css('display', 'block');
|
408
|
-
}
|
409
|
-
} else { // translation NOT allowed
|
410
|
-
|
411
|
-
// update cookie user translate settings
|
412
|
-
user_translate.translationEnabled = false;
|
413
|
-
cookie_written = j1.writeCookie({
|
414
|
-
name: cookie_names.user_translate,
|
415
|
-
data: user_translate,
|
416
|
-
samesite: 'Strict',
|
417
|
-
secure: secure
|
418
|
-
});
|
419
|
-
|
420
|
-
// stop translation for all pages
|
421
|
-
if (htmlScriptElement) { htmlScriptElement.remove(); }
|
422
|
-
j1.removeCookie({name: 'googtrans', domain: cookie_domain});
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
// translation NOT allowed
|
427
|
-
if (!user_translate.analysis || !user_translate.personalization) {
|
428
|
-
head = document.getElementsByTagName('head')[0];
|
429
|
-
script = document.createElement('script');
|
430
|
-
script.id = 'google-translate';
|
431
|
-
|
432
|
-
// update cookie consent settings
|
433
|
-
user_consent.analysis = user_translate.analysis;
|
434
|
-
user_consent.personalization = user_translate.personalization;
|
435
|
-
cookie_written = j1.writeCookie({
|
436
|
-
name: cookie_names.user_consent,
|
437
|
-
data: user_consent,
|
438
|
-
samesite: 'Strict',
|
439
|
-
secure: secure,
|
440
|
-
expires: 0
|
441
|
-
});
|
442
|
-
|
443
|
-
// update cookie user translate settings
|
444
|
-
user_translate.translationEnabled = false;
|
445
|
-
cookie_written = j1.writeCookie({
|
446
|
-
name: cookie_names.user_translate,
|
447
|
-
data: user_consent,
|
448
|
-
samesite: 'Strict',
|
449
|
-
secure: secure,
|
450
|
-
expires: 0
|
451
|
-
});
|
452
|
-
|
453
|
-
// stop translation for all pages
|
454
|
-
if (htmlScriptElement) { htmlScriptElement.remove(); }
|
455
|
-
j1.removeCookie({name: 'googtrans', domain: cookie_domain});
|
456
|
-
}
|
457
|
-
|
458
|
-
if (moduleOptions.reloadPageOnChange) {
|
459
|
-
// reload current page (skip cache)
|
460
|
-
location.reload(true);
|
461
|
-
}
|
462
|
-
|
463
|
-
// disable google translate button if visible
|
464
|
-
if ($('#quickLinksTranslateButton').css('display') === 'block') {
|
465
|
-
$('#quickLinksTranslateButton').css('display', 'none');
|
466
|
-
}
|
467
|
-
|
396
|
+
// reload current page (skip cache)
|
397
|
+
location.reload(true);
|
468
398
|
}, // END cbGoogle
|
469
399
|
|
470
400
|
// -------------------------------------------------------------------------
|
471
401
|
// cbDeepl()
|
472
|
-
// Called by the translator CORE module after the user
|
473
|
-
//
|
402
|
+
// Called by the translator CORE module after the user made the
|
403
|
+
// selection for a translation language
|
474
404
|
// -------------------------------------------------------------------------
|
475
405
|
cbDeepl: function () {
|
476
|
-
|
477
|
-
// code for post
|
478
|
-
|
406
|
+
var logger = log4javascript.getLogger('j1.adapter.translator.cbDeepl');
|
407
|
+
// code for post processing
|
479
408
|
} // END cbDeepl
|
480
409
|
|
481
410
|
}; // END return
|
data/lib/j1/version.rb
CHANGED
data/lib/starter_web/Gemfile
CHANGED
@@ -53,7 +53,7 @@ gem 'jekyll', '~> 4.2'
|
|
53
53
|
|
54
54
|
# Theme Rubies, default: J1 Template (NOT used for the development system)
|
55
55
|
#
|
56
|
-
gem 'j1-template', '~> 2021.2.
|
56
|
+
gem 'j1-template', '~> 2021.2.8'
|
57
57
|
|
58
58
|
# ------------------------------------------------------------------------------
|
59
59
|
# PRODUCTION: Gem needed for the Jekyll and J1 prod environment
|
data/lib/starter_web/_config.yml
CHANGED
@@ -53,7 +53,7 @@ environment: development
|
|
53
53
|
# ------------------------------------------------------------------------------
|
54
54
|
# Sets the build version of J1 Template Gem
|
55
55
|
#
|
56
|
-
version: 2021.2.
|
56
|
+
version: 2021.2.8
|
57
57
|
|
58
58
|
# version
|
59
59
|
# ------------------------------------------------------------------------------
|
@@ -433,7 +433,7 @@ end::tables[]
|
|
433
433
|
// -----------------------------------------------------------------------------
|
434
434
|
tag::products[]
|
435
435
|
:j1--license: MIT License
|
436
|
-
:j1--version: 2021.2.
|
436
|
+
:j1--version: 2021.2.8
|
437
437
|
:j1--site-name: Jekyll One
|
438
438
|
end::products[]
|
439
439
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: j1-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2021.2.
|
4
|
+
version: 2021.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juergen_jekyll_one
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- assets/themes/j1/adapter/js/rtextResizer.js
|
401
401
|
- assets/themes/j1/adapter/js/themer.js
|
402
402
|
- assets/themes/j1/adapter/js/toccer.js
|
403
|
+
- assets/themes/j1/adapter/js/translator.1.js
|
403
404
|
- assets/themes/j1/adapter/js/translator.js
|
404
405
|
- assets/themes/j1/core/country-flags/1x1/ad.svg
|
405
406
|
- assets/themes/j1/core/country-flags/1x1/ae.svg
|