locizify 5.2.2 → 5.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +2 -0
- package/dist/commonjs/index.js +5 -2
- package/dist/es/index.js +6 -3
- package/dist/umd/locizify.js +181 -27
- package/dist/umd/locizify.min.js +2 -2
- package/example/index.html +3 -0
- package/locizify.js +181 -27
- package/locizify.min.js +2 -2
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/dist/commonjs/index.js
CHANGED
|
@@ -45,7 +45,9 @@ var originalInit = i18next.init;
|
|
|
45
45
|
i18next.init = function () {
|
|
46
46
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
47
47
|
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
48
|
-
options = _objectSpread(_objectSpread({}, defaults), options)
|
|
48
|
+
options = _objectSpread(_objectSpread(_objectSpread({}, defaults), options), {}, {
|
|
49
|
+
isLocizify: true
|
|
50
|
+
});
|
|
49
51
|
var scriptEle = document.getElementById('locizify');
|
|
50
52
|
|
|
51
53
|
if (scriptEle) {
|
|
@@ -125,7 +127,8 @@ _i18nextify["default"].getOptions = function (callback) {
|
|
|
125
127
|
|
|
126
128
|
_i18nextify["default"].editor = {
|
|
127
129
|
turnOn: _locize.turnOn,
|
|
128
|
-
turnOff: _locize.turnOff
|
|
130
|
+
turnOff: _locize.turnOff,
|
|
131
|
+
showLocizeLink: _locize.showLocizeLink
|
|
129
132
|
};
|
|
130
133
|
var _default = _i18nextify["default"];
|
|
131
134
|
exports["default"] = _default;
|
package/dist/es/index.js
CHANGED
|
@@ -7,7 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
|
|
8
8
|
import i18nextify from 'i18nextify';
|
|
9
9
|
import LocizeBackend from 'i18next-locize-backend';
|
|
10
|
-
import { locizePlugin, turnOn, turnOff } from 'locize';
|
|
10
|
+
import { locizePlugin, turnOn, turnOff, showLocizeLink } from 'locize';
|
|
11
11
|
var i18next = i18nextify.i18next;
|
|
12
12
|
var enforce = {
|
|
13
13
|
saveMissingTo: 'all'
|
|
@@ -32,7 +32,9 @@ var originalInit = i18next.init;
|
|
|
32
32
|
i18next.init = function () {
|
|
33
33
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
34
|
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
35
|
-
options = _objectSpread(_objectSpread({}, defaults), options)
|
|
35
|
+
options = _objectSpread(_objectSpread(_objectSpread({}, defaults), options), {}, {
|
|
36
|
+
isLocizify: true
|
|
37
|
+
});
|
|
36
38
|
var scriptEle = document.getElementById('locizify');
|
|
37
39
|
|
|
38
40
|
if (scriptEle) {
|
|
@@ -112,6 +114,7 @@ i18nextify.getOptions = function (callback) {
|
|
|
112
114
|
|
|
113
115
|
i18nextify.editor = {
|
|
114
116
|
turnOn: turnOn,
|
|
115
|
-
turnOff: turnOff
|
|
117
|
+
turnOff: turnOff,
|
|
118
|
+
showLocizeLink: showLocizeLink
|
|
116
119
|
};
|
|
117
120
|
export default i18nextify;
|
package/dist/umd/locizify.js
CHANGED
|
@@ -9101,6 +9101,11 @@
|
|
|
9101
9101
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
9102
9102
|
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
9103
9103
|
var callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
9104
|
+
|
|
9105
|
+
if (!options.referenceLng && allOptions.fallbackLng && Array.isArray(allOptions.fallbackLng) && allOptions.fallbackLng[0] !== 'dev') {
|
|
9106
|
+
options.referenceLng = allOptions.fallbackLng[0];
|
|
9107
|
+
}
|
|
9108
|
+
|
|
9104
9109
|
this.services = services;
|
|
9105
9110
|
this.options = defaults$2(options, this.options || {}, getDefaults$3());
|
|
9106
9111
|
this.allOptions = allOptions;
|
|
@@ -9668,6 +9673,55 @@
|
|
|
9668
9673
|
return _typeof$4(obj);
|
|
9669
9674
|
}
|
|
9670
9675
|
|
|
9676
|
+
function _defineProperty$4(obj, key, value) {
|
|
9677
|
+
if (key in obj) {
|
|
9678
|
+
Object.defineProperty(obj, key, {
|
|
9679
|
+
value: value,
|
|
9680
|
+
enumerable: true,
|
|
9681
|
+
configurable: true,
|
|
9682
|
+
writable: true
|
|
9683
|
+
});
|
|
9684
|
+
} else {
|
|
9685
|
+
obj[key] = value;
|
|
9686
|
+
}
|
|
9687
|
+
|
|
9688
|
+
return obj;
|
|
9689
|
+
}
|
|
9690
|
+
|
|
9691
|
+
function ownKeys$9(object, enumerableOnly) {
|
|
9692
|
+
var keys = Object.keys(object);
|
|
9693
|
+
|
|
9694
|
+
if (Object.getOwnPropertySymbols) {
|
|
9695
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
9696
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
9697
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
9698
|
+
});
|
|
9699
|
+
keys.push.apply(keys, symbols);
|
|
9700
|
+
}
|
|
9701
|
+
|
|
9702
|
+
return keys;
|
|
9703
|
+
}
|
|
9704
|
+
|
|
9705
|
+
function _objectSpread2$1(target) {
|
|
9706
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9707
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
9708
|
+
|
|
9709
|
+
if (i % 2) {
|
|
9710
|
+
ownKeys$9(Object(source), true).forEach(function (key) {
|
|
9711
|
+
_defineProperty$4(target, key, source[key]);
|
|
9712
|
+
});
|
|
9713
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
9714
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
9715
|
+
} else {
|
|
9716
|
+
ownKeys$9(Object(source)).forEach(function (key) {
|
|
9717
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
9718
|
+
});
|
|
9719
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
|
|
9722
|
+
return target;
|
|
9723
|
+
}
|
|
9724
|
+
|
|
9671
9725
|
function isWindow(obj) {
|
|
9672
9726
|
return obj != null && obj === obj.window;
|
|
9673
9727
|
}
|
|
@@ -9807,7 +9861,7 @@
|
|
|
9807
9861
|
/* eslint-disable import/prefer-default-export */
|
|
9808
9862
|
|
|
9809
9863
|
|
|
9810
|
-
function createClickHandler(cb) {
|
|
9864
|
+
function createClickHandler(cb, options) {
|
|
9811
9865
|
// eslint-disable-next-line consistent-return
|
|
9812
9866
|
var handler = function handler(e) {
|
|
9813
9867
|
var el = getClickedElement(e);
|
|
@@ -9830,11 +9884,17 @@
|
|
|
9830
9884
|
var pR = parseFloat(style.getPropertyValue('padding-right'));
|
|
9831
9885
|
var pL = parseFloat(style.getPropertyValue('padding-left'));
|
|
9832
9886
|
var sizing = style.getPropertyValue('box-sizing');
|
|
9887
|
+
|
|
9888
|
+
function getFallbackNS() {
|
|
9889
|
+
var i18next = options.getI18next();
|
|
9890
|
+
if (i18next && i18next.options && i18next.options.isLocizify) return i18next.options.defaultNS;
|
|
9891
|
+
}
|
|
9892
|
+
|
|
9833
9893
|
cb({
|
|
9834
9894
|
tagName: rectEl.tagName,
|
|
9835
9895
|
text: text,
|
|
9836
9896
|
key: key,
|
|
9837
|
-
ns: getElementNamespace(el),
|
|
9897
|
+
ns: getElementNamespace(el) || getFallbackNS(),
|
|
9838
9898
|
box: {
|
|
9839
9899
|
top: top,
|
|
9840
9900
|
left: left,
|
|
@@ -9848,6 +9908,48 @@
|
|
|
9848
9908
|
return handler;
|
|
9849
9909
|
}
|
|
9850
9910
|
|
|
9911
|
+
var baseBtn = 'font-family: "Helvetica", "Arial", sans-serif; font-size: 14px; color: #fff; border: none; font-weight: 300; height: 30px; line-height: 30px; padding: 0 15px; text-align: center; min-width: 90px; text-decoration: none; text-transform: uppercase; text-overflow: ellipsis; white-space: nowrap; outline: none; cursor: pointer; border-radius: 15px;'; // eslint-disable-next-line import/prefer-default-export
|
|
9912
|
+
|
|
9913
|
+
function initUI(options) {
|
|
9914
|
+
var cont = window.document.createElement('div');
|
|
9915
|
+
var style = 'font-family: "Helvetica", "Arial", sans-serif; bottom: 20px; right: 20px; padding: 10px; background-color: #fff; border: solid 1px #1976d2; box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.5); border-radius: 3px;';
|
|
9916
|
+
style += ' z-index: 2147483647; position: fixed;';
|
|
9917
|
+
cont.setAttribute('style', style);
|
|
9918
|
+
cont.setAttribute('ignorelocizeeditor', '');
|
|
9919
|
+
cont.setAttribute('translated', ''); // if(options.locizeEditorToggle.containerClasses) {
|
|
9920
|
+
// const classes = options.locizeEditorToggle.containerClasses.length > 1 ? options.locizeEditorToggle.containerClasses.split(' ') : options.locizeEditorToggle.containerClasses;
|
|
9921
|
+
// classes.forEach(function(cssClass) {
|
|
9922
|
+
// cont.classList.add(cssClass);
|
|
9923
|
+
// });
|
|
9924
|
+
// }
|
|
9925
|
+
|
|
9926
|
+
var title = window.document.createElement('h4');
|
|
9927
|
+
title.id = 'locize-title';
|
|
9928
|
+
title.innerHTML = 'Translate InContext:';
|
|
9929
|
+
title.setAttribute('style', 'font-family: "Helvetica", "Arial", sans-serif; font-size: 14px; margin: 0 0 5px 0; color: #1976d2; font-weight: 300;');
|
|
9930
|
+
title.setAttribute('ignorelocizeeditor', '');
|
|
9931
|
+
cont.appendChild(title);
|
|
9932
|
+
var turnOn = window.document.createElement('button');
|
|
9933
|
+
turnOn.innerHTML = 'Open in locize';
|
|
9934
|
+
turnOn.setAttribute('style', "".concat(baseBtn, " background-color: #1976d2;"));
|
|
9935
|
+
|
|
9936
|
+
turnOn.onclick = function () {
|
|
9937
|
+
var i18next = options.getI18next();
|
|
9938
|
+
var backendOptions = i18next && i18next.options && i18next.options.backend;
|
|
9939
|
+
|
|
9940
|
+
var _backendOptions$optio = _objectSpread2$1(_objectSpread2$1({}, backendOptions), options),
|
|
9941
|
+
projectId = _backendOptions$optio.projectId,
|
|
9942
|
+
version = _backendOptions$optio.version;
|
|
9943
|
+
|
|
9944
|
+
var editorUrl = options.editorUrl || backendOptions && backendOptions.loadPath && backendOptions.loadPath.indexOf('https://api-dev.locize.app') === 0 && 'https://dev.locize.app' || 'https://www.locize.app';
|
|
9945
|
+
window.location = "".concat(editorUrl, "/cat/").concat(projectId, "/v/").concat(version, "/incontext?sourceurl=").concat(encodeURI(window.location.href));
|
|
9946
|
+
};
|
|
9947
|
+
|
|
9948
|
+
turnOn.setAttribute('ignorelocizeeditor', '');
|
|
9949
|
+
cont.appendChild(turnOn);
|
|
9950
|
+
window.document.body.appendChild(cont);
|
|
9951
|
+
}
|
|
9952
|
+
|
|
9851
9953
|
var isInIframe = true;
|
|
9852
9954
|
|
|
9853
9955
|
try {
|
|
@@ -9884,10 +9986,11 @@
|
|
|
9884
9986
|
}
|
|
9885
9987
|
}
|
|
9886
9988
|
|
|
9989
|
+
var i18next;
|
|
9887
9990
|
var locizePlugin = {
|
|
9888
9991
|
type: '3rdParty',
|
|
9889
9992
|
init: function init(i18n) {
|
|
9890
|
-
|
|
9993
|
+
i18next = i18n;
|
|
9891
9994
|
addLocizeSavedHandler(function (res) {
|
|
9892
9995
|
res.updated.forEach(function (item) {
|
|
9893
9996
|
var lng = item.lng,
|
|
@@ -9906,10 +10009,26 @@
|
|
|
9906
10009
|
if (!isUpdate) onAddedKey(lng, ns, k, val);
|
|
9907
10010
|
};
|
|
9908
10011
|
}
|
|
10012
|
+
|
|
10013
|
+
i18next.on('languageChanged', function (lng) {
|
|
10014
|
+
setEditorLng(lng);
|
|
10015
|
+
});
|
|
9909
10016
|
}
|
|
9910
10017
|
};
|
|
9911
10018
|
|
|
10019
|
+
function getI18next() {
|
|
10020
|
+
return i18next;
|
|
10021
|
+
}
|
|
10022
|
+
|
|
10023
|
+
function showLocizeLink() {
|
|
10024
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10025
|
+
if (!isInIframe) initUI(_objectSpread2$1(_objectSpread2$1({}, options), {}, {
|
|
10026
|
+
getI18next: getI18next
|
|
10027
|
+
}));
|
|
10028
|
+
}
|
|
10029
|
+
|
|
9912
10030
|
if (typeof window !== 'undefined') {
|
|
10031
|
+
// eslint-disable-next-line consistent-return
|
|
9913
10032
|
window.addEventListener('message', function (e) {
|
|
9914
10033
|
if (e.data.message === 'isLocizeEnabled') {
|
|
9915
10034
|
// console.warn("result: ", ev.data);
|
|
@@ -9922,6 +10041,8 @@
|
|
|
9922
10041
|
message: 'clickedElement',
|
|
9923
10042
|
payload: payload
|
|
9924
10043
|
}, origin);
|
|
10044
|
+
}, {
|
|
10045
|
+
getI18next: getI18next
|
|
9925
10046
|
}); // document.body.addEventListener('click', handler, true);
|
|
9926
10047
|
// clickInterceptionEnabled = true;
|
|
9927
10048
|
}
|
|
@@ -9960,7 +10081,7 @@
|
|
|
9960
10081
|
});
|
|
9961
10082
|
}
|
|
9962
10083
|
|
|
9963
|
-
|
|
10084
|
+
function turnOn() {
|
|
9964
10085
|
scriptTurnedOff = false;
|
|
9965
10086
|
if (!clickInterceptionEnabled) window.document.body.addEventListener('click', handler, true);
|
|
9966
10087
|
clickInterceptionEnabled = true;
|
|
@@ -9968,9 +10089,9 @@
|
|
|
9968
10089
|
message: 'turnedOn'
|
|
9969
10090
|
}, origin);
|
|
9970
10091
|
return scriptTurnedOff;
|
|
9971
|
-
}
|
|
10092
|
+
}
|
|
9972
10093
|
|
|
9973
|
-
|
|
10094
|
+
function turnOff() {
|
|
9974
10095
|
scriptTurnedOff = true;
|
|
9975
10096
|
if (clickInterceptionEnabled) window.document.body.removeEventListener('click', handler, true);
|
|
9976
10097
|
clickInterceptionEnabled = false;
|
|
@@ -9981,10 +10102,40 @@
|
|
|
9981
10102
|
message: 'forcedOff'
|
|
9982
10103
|
}, origin);
|
|
9983
10104
|
return scriptTurnedOff;
|
|
9984
|
-
}
|
|
10105
|
+
}
|
|
10106
|
+
|
|
10107
|
+
function setEditorLng(lng) {
|
|
10108
|
+
// console.warn('setLng', lng);
|
|
10109
|
+
if (source) source.postMessage({
|
|
10110
|
+
message: 'setLng',
|
|
10111
|
+
lng: lng
|
|
10112
|
+
}, origin);
|
|
10113
|
+
}
|
|
10114
|
+
|
|
10115
|
+
var oldHref = document.location.href;
|
|
10116
|
+
window.addEventListener('load', function () {
|
|
10117
|
+
var bodyList = document.querySelector('body');
|
|
10118
|
+
var observer = new MutationObserver(function (mutations) {
|
|
10119
|
+
mutations.forEach(function (mutation) {
|
|
10120
|
+
if (oldHref != document.location.href) {
|
|
10121
|
+
// console.warn('url changed', oldHref, document.location.href);
|
|
10122
|
+
oldHref = document.location.href;
|
|
10123
|
+
if (source) source.postMessage({
|
|
10124
|
+
message: 'hrefChanged',
|
|
10125
|
+
href: oldHref
|
|
10126
|
+
}, origin);
|
|
10127
|
+
}
|
|
10128
|
+
});
|
|
10129
|
+
});
|
|
10130
|
+
var config = {
|
|
10131
|
+
childList: true,
|
|
10132
|
+
subtree: true
|
|
10133
|
+
};
|
|
10134
|
+
observer.observe(bodyList, config);
|
|
10135
|
+
});
|
|
9985
10136
|
|
|
9986
10137
|
var {
|
|
9987
|
-
i18next
|
|
10138
|
+
i18next: i18next$1
|
|
9988
10139
|
} = i18nextify;
|
|
9989
10140
|
var enforce = {
|
|
9990
10141
|
saveMissingTo: 'all'
|
|
@@ -9993,16 +10144,18 @@
|
|
|
9993
10144
|
reloadOnSave: true,
|
|
9994
10145
|
bindSavedMissing: true
|
|
9995
10146
|
};
|
|
9996
|
-
i18next.use(I18NextLocizeBackend).use(locizePlugin);
|
|
9997
|
-
i18next.on('editorSaved', () => {
|
|
10147
|
+
i18next$1.use(I18NextLocizeBackend).use(locizePlugin);
|
|
10148
|
+
i18next$1.on('editorSaved', () => {
|
|
9998
10149
|
i18nextify.forceRerender();
|
|
9999
10150
|
});
|
|
10000
|
-
var originalInit = i18next.init;
|
|
10151
|
+
var originalInit = i18next$1.init;
|
|
10001
10152
|
|
|
10002
|
-
i18next.init = function () {
|
|
10153
|
+
i18next$1.init = function () {
|
|
10003
10154
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10004
10155
|
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
10005
|
-
options = _objectSpread2(_objectSpread2({}, defaults$3), options)
|
|
10156
|
+
options = _objectSpread2(_objectSpread2(_objectSpread2({}, defaults$3), options), {}, {
|
|
10157
|
+
isLocizify: true
|
|
10158
|
+
});
|
|
10006
10159
|
var scriptEle = document.getElementById('locizify');
|
|
10007
10160
|
|
|
10008
10161
|
if (scriptEle) {
|
|
@@ -10043,44 +10196,45 @@
|
|
|
10043
10196
|
callback(err, t);
|
|
10044
10197
|
}
|
|
10045
10198
|
|
|
10046
|
-
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') return originalInit.call(i18next, _objectSpread2(_objectSpread2({}, options), enforce), handleI18nextInitialized);
|
|
10199
|
+
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') return originalInit.call(i18next$1, _objectSpread2(_objectSpread2({}, options), enforce), handleI18nextInitialized);
|
|
10047
10200
|
var locizeBackend = new I18NextLocizeBackend(options.backend);
|
|
10048
10201
|
locizeBackend.getOptions((err, opts) => {
|
|
10049
10202
|
if (err && typeof console === 'object' && typeof console.error === 'function') console.error(err);
|
|
10050
|
-
originalInit.call(i18next, _objectSpread2(_objectSpread2(_objectSpread2({}, opts), options), enforce), handleI18nextInitialized);
|
|
10203
|
+
originalInit.call(i18next$1, _objectSpread2(_objectSpread2(_objectSpread2({}, opts), options), enforce), handleI18nextInitialized);
|
|
10051
10204
|
});
|
|
10052
10205
|
};
|
|
10053
10206
|
|
|
10054
10207
|
i18nextify.getLanguages = function (callback) {
|
|
10055
|
-
if (i18next.services.backendConnector) {
|
|
10056
|
-
i18next.services.backendConnector.backend.getLanguages(callback);
|
|
10208
|
+
if (i18next$1.services.backendConnector) {
|
|
10209
|
+
i18next$1.services.backendConnector.backend.getLanguages(callback);
|
|
10057
10210
|
} else {
|
|
10058
10211
|
function ready() {
|
|
10059
|
-
i18next.off('initialized', ready);
|
|
10060
|
-
i18next.services.backendConnector.backend.getLanguages(callback);
|
|
10212
|
+
i18next$1.off('initialized', ready);
|
|
10213
|
+
i18next$1.services.backendConnector.backend.getLanguages(callback);
|
|
10061
10214
|
}
|
|
10062
10215
|
|
|
10063
|
-
i18next.on('initialized', ready);
|
|
10216
|
+
i18next$1.on('initialized', ready);
|
|
10064
10217
|
}
|
|
10065
10218
|
};
|
|
10066
10219
|
|
|
10067
10220
|
i18nextify.getOptions = function (callback) {
|
|
10068
|
-
if (i18next.services.backendConnector) {
|
|
10069
|
-
i18next.services.backendConnector.backend.getOptions(callback);
|
|
10221
|
+
if (i18next$1.services.backendConnector) {
|
|
10222
|
+
i18next$1.services.backendConnector.backend.getOptions(callback);
|
|
10070
10223
|
} else {
|
|
10071
10224
|
function ready() {
|
|
10072
|
-
i18next.off('initialized', ready);
|
|
10073
|
-
i18next.services.backendConnector.backend.getOptions(callback);
|
|
10225
|
+
i18next$1.off('initialized', ready);
|
|
10226
|
+
i18next$1.services.backendConnector.backend.getOptions(callback);
|
|
10074
10227
|
}
|
|
10075
10228
|
|
|
10076
|
-
i18next.on('initialized', ready);
|
|
10229
|
+
i18next$1.on('initialized', ready);
|
|
10077
10230
|
}
|
|
10078
10231
|
}; // add editor functions
|
|
10079
10232
|
|
|
10080
10233
|
|
|
10081
10234
|
i18nextify.editor = {
|
|
10082
|
-
turnOn
|
|
10083
|
-
turnOff
|
|
10235
|
+
turnOn,
|
|
10236
|
+
turnOff,
|
|
10237
|
+
showLocizeLink
|
|
10084
10238
|
};
|
|
10085
10239
|
|
|
10086
10240
|
return i18nextify;
|