locize 3.0.5 → 3.1.1
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.
- package/CHANGELOG.md +8 -0
- package/README.md +67 -31
- package/dist/cjs/api/handleConfirmInitialized.js +1 -0
- package/dist/cjs/api/handleRequestPopupChanges.js +8 -7
- package/dist/cjs/index.d.ts +30 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/locizePlugin.js +103 -77
- package/dist/cjs/observer.js +28 -1
- package/dist/cjs/process.js +7 -5
- package/dist/cjs/ui/elements/popup.js +3 -1
- package/dist/cjs/utils.js +11 -0
- package/dist/esm/api/handleConfirmInitialized.js +1 -0
- package/dist/esm/api/handleRequestPopupChanges.js +2 -1
- package/dist/esm/index.d.ts +30 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/locizePlugin.js +103 -78
- package/dist/esm/observer.js +28 -1
- package/dist/esm/process.js +8 -6
- package/dist/esm/ui/elements/popup.js +3 -2
- package/dist/esm/utils.js +11 -1
- package/dist/umd/locize.js +539 -472
- package/dist/umd/locize.min.js +1 -1
- package/index.d.ts +30 -0
- package/locize.js +539 -472
- package/locize.min.js +1 -1
- package/package.json +1 -1
- package/src/api/handleConfirmInitialized.js +1 -0
- package/src/api/handleRequestPopupChanges.js +2 -1
- package/src/index.js +3 -1
- package/src/locizePlugin.js +123 -85
- package/src/observer.js +48 -1
- package/src/process.js +10 -8
- package/src/ui/elements/popup.js +3 -1
- package/src/ui/utils.js +5 -5
- package/src/utils.js +12 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { locizePlugin } from './locizePlugin.js';
|
|
2
|
-
export { locizePlugin } from './locizePlugin.js';
|
|
1
|
+
import { locizePlugin, locizeEditorPlugin } from './locizePlugin.js';
|
|
2
|
+
export { locizeEditorPlugin, locizePlugin } from './locizePlugin.js';
|
|
3
3
|
import { startStandalone } from './startStandalone.js';
|
|
4
4
|
export { startStandalone } from './startStandalone.js';
|
|
5
5
|
import './api/handleEditKey.js';
|
|
@@ -24,6 +24,7 @@ var index = {
|
|
|
24
24
|
PostProcessor: PostProcessor,
|
|
25
25
|
addLocizeSavedHandler: addLocizeSavedHandler,
|
|
26
26
|
locizePlugin: locizePlugin,
|
|
27
|
+
locizeEditorPlugin: locizeEditorPlugin,
|
|
27
28
|
turnOn: turnOn,
|
|
28
29
|
turnOff: turnOff,
|
|
29
30
|
setEditorLng: setEditorLng,
|
package/dist/esm/locizePlugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { PostProcessor } from 'i18next-subliminal';
|
|
|
3
3
|
export { unwrap } from 'i18next-subliminal';
|
|
4
4
|
import { start } from './process.js';
|
|
5
5
|
import { startLegacy } from './processLegacy.js';
|
|
6
|
+
import { getQsParameterByName } from './utils.js';
|
|
6
7
|
|
|
7
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -10,89 +11,94 @@ var isInIframe = typeof window !== 'undefined';
|
|
|
10
11
|
try {
|
|
11
12
|
isInIframe = self !== top;
|
|
12
13
|
} catch (e) {}
|
|
14
|
+
function configurePostProcessor(i18next, options) {
|
|
15
|
+
i18next.use(PostProcessor);
|
|
16
|
+
if (typeof options.postProcess === 'string') {
|
|
17
|
+
options.postProcess = [options.postProcess, 'subliminal'];
|
|
18
|
+
} else if (Array.isArray(options.postProcess)) {
|
|
19
|
+
options.postProcess.push('subliminal');
|
|
20
|
+
} else {
|
|
21
|
+
options.postProcess = 'subliminal';
|
|
22
|
+
}
|
|
23
|
+
options.postProcessPassResolved = true;
|
|
24
|
+
}
|
|
25
|
+
function getImplementation(i18n) {
|
|
26
|
+
var impl = {
|
|
27
|
+
getResource: function getResource(lng, ns, key) {
|
|
28
|
+
return i18n.getResource(lng, ns, key);
|
|
29
|
+
},
|
|
30
|
+
setResource: function setResource(lng, ns, key, value) {
|
|
31
|
+
return i18n.addResource(lng, ns, key, value, {
|
|
32
|
+
silent: true
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
36
|
+
i18n.loadNamespaces(ns, function () {
|
|
37
|
+
cb(i18n.getResourceBundle(lng, ns));
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
getLng: function getLng() {
|
|
41
|
+
return i18n.languages[0];
|
|
42
|
+
},
|
|
43
|
+
getSourceLng: function getSourceLng() {
|
|
44
|
+
var fallback = i18n.options.fallbackLng;
|
|
45
|
+
if (typeof fallback === 'string') return fallback;
|
|
46
|
+
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
47
|
+
if (fallback && fallback["default"]) {
|
|
48
|
+
if (typeof fallback["default"] === 'string') return fallback;
|
|
49
|
+
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
50
|
+
}
|
|
51
|
+
if (typeof fallback === 'function') {
|
|
52
|
+
var res = fallback(i18n.resolvedLanguage);
|
|
53
|
+
if (typeof res === 'string') return res;
|
|
54
|
+
if (Array.isArray(res)) return res[res.length - 1];
|
|
55
|
+
}
|
|
56
|
+
return 'dev';
|
|
57
|
+
},
|
|
58
|
+
getLocizeDetails: function getLocizeDetails() {
|
|
59
|
+
var backendName;
|
|
60
|
+
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
61
|
+
backendName = 'I18NextLocizeBackend';
|
|
62
|
+
} else {
|
|
63
|
+
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
64
|
+
}
|
|
65
|
+
var opts = {
|
|
66
|
+
backendName: backendName,
|
|
67
|
+
sourceLng: impl.getSourceLng(),
|
|
68
|
+
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
69
|
+
i18nFramework: 'i18next',
|
|
70
|
+
isLocizify: i18n.options.isLocizify,
|
|
71
|
+
defaultNS: i18n.options.defaultNS
|
|
72
|
+
};
|
|
73
|
+
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
74
|
+
var pickFrom = i18n.options.backend || i18n.options.editor;
|
|
75
|
+
return _objectSpread(_objectSpread({}, opts), {}, {
|
|
76
|
+
projectId: pickFrom.projectId,
|
|
77
|
+
version: pickFrom.version
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
bindLanguageChange: function bindLanguageChange(cb) {
|
|
81
|
+
i18n.on('languageChanged', cb);
|
|
82
|
+
},
|
|
83
|
+
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
84
|
+
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
85
|
+
if (!isUpdate) cb(lng, ns, k, val);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
triggerRerender: function triggerRerender() {
|
|
89
|
+
i18n.emit('editorSaved');
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return impl;
|
|
93
|
+
}
|
|
13
94
|
var i18next;
|
|
14
95
|
var locizePlugin = {
|
|
15
96
|
type: '3rdParty',
|
|
16
97
|
init: function init(i18n) {
|
|
17
98
|
var options = i18n.options;
|
|
18
99
|
i18next = i18n;
|
|
19
|
-
if (!isInIframe)
|
|
20
|
-
|
|
21
|
-
if (typeof options.postProcess === 'string') {
|
|
22
|
-
options.postProcess = [options.postProcess, 'subliminal'];
|
|
23
|
-
} else if (Array.isArray(options.postProcess)) {
|
|
24
|
-
options.postProcess.push('subliminal');
|
|
25
|
-
} else {
|
|
26
|
-
options.postProcess = 'subliminal';
|
|
27
|
-
}
|
|
28
|
-
options.postProcessPassResolved = true;
|
|
29
|
-
}
|
|
30
|
-
var impl = {
|
|
31
|
-
getResource: function getResource(lng, ns, key) {
|
|
32
|
-
return i18n.getResource(lng, ns, key);
|
|
33
|
-
},
|
|
34
|
-
setResource: function setResource(lng, ns, key, value) {
|
|
35
|
-
return i18n.addResource(lng, ns, key, value, {
|
|
36
|
-
silent: true
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
40
|
-
i18n.loadNamespaces(ns, function () {
|
|
41
|
-
cb(i18n.getResourceBundle(lng, ns));
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
getLng: function getLng() {
|
|
45
|
-
return i18n.languages[0];
|
|
46
|
-
},
|
|
47
|
-
getSourceLng: function getSourceLng() {
|
|
48
|
-
var fallback = i18n.options.fallbackLng;
|
|
49
|
-
if (typeof fallback === 'string') return fallback;
|
|
50
|
-
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
51
|
-
if (fallback && fallback["default"]) {
|
|
52
|
-
if (typeof fallback["default"] === 'string') return fallback;
|
|
53
|
-
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
54
|
-
}
|
|
55
|
-
if (typeof fallback === 'function') {
|
|
56
|
-
var res = fallback(i18n.resolvedLanguage);
|
|
57
|
-
if (typeof res === 'string') return res;
|
|
58
|
-
if (Array.isArray(res)) return res[res.length - 1];
|
|
59
|
-
}
|
|
60
|
-
return 'dev';
|
|
61
|
-
},
|
|
62
|
-
getLocizeDetails: function getLocizeDetails() {
|
|
63
|
-
var backendName;
|
|
64
|
-
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
65
|
-
backendName = 'I18NextLocizeBackend';
|
|
66
|
-
} else {
|
|
67
|
-
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
68
|
-
}
|
|
69
|
-
var opts = {
|
|
70
|
-
backendName: backendName,
|
|
71
|
-
sourceLng: impl.getSourceLng(),
|
|
72
|
-
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
73
|
-
i18nFramework: 'i18next',
|
|
74
|
-
isLocizify: i18n.options.isLocizify,
|
|
75
|
-
defaultNS: i18n.options.defaultNS
|
|
76
|
-
};
|
|
77
|
-
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
78
|
-
var pickFrom = i18n.options.backend || i18n.options.editor;
|
|
79
|
-
return _objectSpread(_objectSpread({}, opts), {}, {
|
|
80
|
-
projectId: pickFrom.projectId,
|
|
81
|
-
version: pickFrom.version
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
bindLanguageChange: function bindLanguageChange(cb) {
|
|
85
|
-
i18n.on('languageChanged', cb);
|
|
86
|
-
},
|
|
87
|
-
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
88
|
-
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
89
|
-
if (!isUpdate) cb(lng, ns, k, val);
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
triggerRerender: function triggerRerender() {
|
|
93
|
-
i18n.emit('editorSaved');
|
|
94
|
-
}
|
|
95
|
-
};
|
|
100
|
+
if (!isInIframe) configurePostProcessor(i18next, options);
|
|
101
|
+
var impl = getImplementation(i18n);
|
|
96
102
|
if (!isInIframe) {
|
|
97
103
|
start(impl);
|
|
98
104
|
} else {
|
|
@@ -100,5 +106,24 @@ var locizePlugin = {
|
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
};
|
|
109
|
+
var locizeEditorPlugin = function locizeEditorPlugin() {
|
|
110
|
+
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
111
|
+
opt.qsProp = opt.qsProp || 'incontext';
|
|
112
|
+
return {
|
|
113
|
+
type: '3rdParty',
|
|
114
|
+
init: function init(i18n) {
|
|
115
|
+
var options = i18n.options;
|
|
116
|
+
i18next = i18n;
|
|
117
|
+
var showInContext = getQsParameterByName(opt.qsProp) === 'true';
|
|
118
|
+
if (!isInIframe && showInContext) configurePostProcessor(i18next, options);
|
|
119
|
+
var impl = getImplementation(i18n);
|
|
120
|
+
if (!isInIframe && showInContext) {
|
|
121
|
+
start(impl);
|
|
122
|
+
} else {
|
|
123
|
+
startLegacy(impl);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
};
|
|
103
128
|
|
|
104
|
-
export { locizePlugin };
|
|
129
|
+
export { locizeEditorPlugin, locizePlugin };
|
package/dist/esm/observer.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { debounce } from './utils.js';
|
|
2
2
|
import { validAttributes } from './vars.js';
|
|
3
3
|
|
|
4
|
+
var mutationTriggeringElements = {};
|
|
4
5
|
function ignoreMutation(ele) {
|
|
6
|
+
if (ele.uniqueID) {
|
|
7
|
+
var info = mutationTriggeringElements[ele.uniqueID];
|
|
8
|
+
if (info && info.triggered > 10 && info.lastTriggerDate + 500 < Date.now()) {
|
|
9
|
+
if (!info.warned && console) {
|
|
10
|
+
console.warn('locize ::: ignoring element change - an element is rerendering too often in short interval', '\n', 'consider adding the "data-locize-editor-ignore:" attribute to the element:', ele);
|
|
11
|
+
info.warned = true;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
5
16
|
var ret = ele.dataset && (ele.dataset.i18nextEditorElement === 'true' || ele.dataset.locizeEditorIgnore === 'true');
|
|
6
17
|
if (!ret && ele.parentElement) return ignoreMutation(ele.parentElement);
|
|
7
18
|
return ret;
|
|
@@ -30,6 +41,12 @@ function createObserver(ele, handle) {
|
|
|
30
41
|
if (mutation.type === 'attributes' && !validAttributes.includes(mutation.attributeName)) {
|
|
31
42
|
return;
|
|
32
43
|
}
|
|
44
|
+
Object.keys(mutationTriggeringElements).forEach(function (k) {
|
|
45
|
+
var info = mutationTriggeringElements[k];
|
|
46
|
+
if (info.lastTriggerDate + 60000 < Date.now()) {
|
|
47
|
+
delete mutationTriggeringElements[k];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
33
50
|
if (mutation.type === 'childList') {
|
|
34
51
|
var notOurs = 0;
|
|
35
52
|
if (!ignoreMutation(mutation.target)) {
|
|
@@ -45,8 +62,18 @@ function createObserver(ele, handle) {
|
|
|
45
62
|
if (notOurs === 0) return;
|
|
46
63
|
}
|
|
47
64
|
triggerMutation = true;
|
|
65
|
+
if (mutation.target && mutation.target.uniqueID) {
|
|
66
|
+
var info = mutationTriggeringElements[mutation.target.uniqueID] || {
|
|
67
|
+
triggered: 0
|
|
68
|
+
};
|
|
69
|
+
info.triggered = info.triggered + 1;
|
|
70
|
+
info.lastTriggerDate = Date.now();
|
|
71
|
+
mutationTriggeringElements[mutation.target.uniqueID] = info;
|
|
72
|
+
}
|
|
48
73
|
var includedAlready = targetEles.reduce(function (mem, element) {
|
|
49
|
-
if (mem || element.contains(mutation.target) || !mutation.target.parentElement)
|
|
74
|
+
if (mem || element.contains(mutation.target) || !mutation.target.parentElement) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
50
77
|
return false;
|
|
51
78
|
}, false);
|
|
52
79
|
if (!includedAlready) {
|
package/dist/esm/process.js
CHANGED
|
@@ -3,7 +3,7 @@ import { parseTree, setImplementation } from './parser.js';
|
|
|
3
3
|
import { createObserver } from './observer.js';
|
|
4
4
|
import { startMouseTracking } from './ui/mouseDistance.js';
|
|
5
5
|
import { initDragElement, initResizeElement } from './ui/popup.js';
|
|
6
|
-
import { Popup } from './ui/elements/popup.js';
|
|
6
|
+
import { popupId, Popup } from './ui/elements/popup.js';
|
|
7
7
|
import { getIframeUrl } from './vars.js';
|
|
8
8
|
import './api/handleEditKey.js';
|
|
9
9
|
import './api/handleCommitKey.js';
|
|
@@ -46,11 +46,13 @@ function start() {
|
|
|
46
46
|
});
|
|
47
47
|
observer.start();
|
|
48
48
|
startMouseTracking(observer);
|
|
49
|
-
document.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
if (!document.getElementById(popupId)) {
|
|
50
|
+
document.body.append(Popup(getIframeUrl(), function () {
|
|
51
|
+
api.requestInitialize(config);
|
|
52
|
+
}));
|
|
53
|
+
initDragElement();
|
|
54
|
+
initResizeElement();
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
if (document.body) return continueToStart();
|
|
56
58
|
window.addEventListener('load', function () {
|
|
@@ -37,9 +37,10 @@ function Minimize(popupEle, onMinimize) {
|
|
|
37
37
|
};
|
|
38
38
|
return image;
|
|
39
39
|
}
|
|
40
|
+
var popupId = 'i18next-editor-popup';
|
|
40
41
|
function Popup(url, cb) {
|
|
41
42
|
var popup = document.createElement('div');
|
|
42
|
-
popup.setAttribute('id',
|
|
43
|
+
popup.setAttribute('id', popupId);
|
|
43
44
|
popup.classList.add('i18next-editor-popup');
|
|
44
45
|
popup.style = "\n z-index: 9;\n background-color: transparent;\n border: 1px solid rgba(200, 200, 200, 0.9);\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n --i18next-editor-popup-height: 200px;\n height: var(--i18next-editor-popup-height);\n min-height: 150px;\n min-width: 300px;\n --i18next-editor-popup-width: 400px;\n width: var(--i18next-editor-popup-width);\n max-height: 600px;\n max-width: 800px;\n\n position: fixed;\n --i18next-editor-popup-position-top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n --i18next-editor-popup-position-left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n\n overflow: visible;\n ";
|
|
45
46
|
popup.setAttribute('data-i18next-editor-element', 'true');
|
|
@@ -73,4 +74,4 @@ function Popup(url, cb) {
|
|
|
73
74
|
return popup;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
export { Popup };
|
|
77
|
+
export { Popup, popupId };
|
package/dist/esm/utils.js
CHANGED
|
@@ -119,5 +119,15 @@ function getElementNamespace(el) {
|
|
|
119
119
|
find(el);
|
|
120
120
|
return found;
|
|
121
121
|
}
|
|
122
|
+
function getQsParameterByName(name, url) {
|
|
123
|
+
if (typeof window === 'undefined') return null;
|
|
124
|
+
if (!url) url = window.location.href.toLowerCase();
|
|
125
|
+
name = name.replace(/[\[\]]/g, '\\$&');
|
|
126
|
+
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
127
|
+
var results = regex.exec(url);
|
|
128
|
+
if (!results) return null;
|
|
129
|
+
if (!results[2]) return '';
|
|
130
|
+
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
|
131
|
+
}
|
|
122
132
|
|
|
123
|
-
export { debounce, getClickedElement, getElementI18nKey, getElementNamespace, getElementText, getWindow, isWindow, offset };
|
|
133
|
+
export { debounce, getClickedElement, getElementI18nKey, getElementNamespace, getElementText, getQsParameterByName, getWindow, isWindow, offset };
|