locizify 5.2.3 → 5.2.4
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 +4 -0
- package/README.md +2 -0
- package/dist/commonjs/index.js +2 -1
- package/dist/es/index.js +3 -2
- package/dist/umd/locizify.js +123 -32
- package/dist/umd/locizify.min.js +2 -2
- package/example/index.html +3 -0
- package/locizify.js +123 -32
- package/locizify.min.js +2 -2
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/dist/commonjs/index.js
CHANGED
|
@@ -125,7 +125,8 @@ _i18nextify["default"].getOptions = function (callback) {
|
|
|
125
125
|
|
|
126
126
|
_i18nextify["default"].editor = {
|
|
127
127
|
turnOn: _locize.turnOn,
|
|
128
|
-
turnOff: _locize.turnOff
|
|
128
|
+
turnOff: _locize.turnOff,
|
|
129
|
+
showLocizeLink: _locize.showLocizeLink
|
|
129
130
|
};
|
|
130
131
|
var _default = _i18nextify["default"];
|
|
131
132
|
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'
|
|
@@ -112,6 +112,7 @@ i18nextify.getOptions = function (callback) {
|
|
|
112
112
|
|
|
113
113
|
i18nextify.editor = {
|
|
114
114
|
turnOn: turnOn,
|
|
115
|
-
turnOff: turnOff
|
|
115
|
+
turnOff: turnOff,
|
|
116
|
+
showLocizeLink: showLocizeLink
|
|
116
117
|
};
|
|
117
118
|
export default i18nextify;
|
package/dist/umd/locizify.js
CHANGED
|
@@ -9657,20 +9657,55 @@
|
|
|
9657
9657
|
|
|
9658
9658
|
I18NextLocizeBackend.type = 'backend';
|
|
9659
9659
|
|
|
9660
|
+
function ownKeys$9(object, enumerableOnly) {
|
|
9661
|
+
var keys = Object.keys(object);
|
|
9662
|
+
|
|
9663
|
+
if (Object.getOwnPropertySymbols) {
|
|
9664
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
9665
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
9666
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
9667
|
+
})), keys.push.apply(keys, symbols);
|
|
9668
|
+
}
|
|
9669
|
+
|
|
9670
|
+
return keys;
|
|
9671
|
+
}
|
|
9672
|
+
|
|
9673
|
+
function _objectSpread2$1(target) {
|
|
9674
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9675
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
9676
|
+
i % 2 ? ownKeys$9(Object(source), !0).forEach(function (key) {
|
|
9677
|
+
_defineProperty$4(target, key, source[key]);
|
|
9678
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$9(Object(source)).forEach(function (key) {
|
|
9679
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
9680
|
+
});
|
|
9681
|
+
}
|
|
9682
|
+
|
|
9683
|
+
return target;
|
|
9684
|
+
}
|
|
9685
|
+
|
|
9660
9686
|
function _typeof$4(obj) {
|
|
9661
9687
|
"@babel/helpers - typeof";
|
|
9662
9688
|
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9689
|
+
return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
9690
|
+
return typeof obj;
|
|
9691
|
+
} : function (obj) {
|
|
9692
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
9693
|
+
}, _typeof$4(obj);
|
|
9694
|
+
}
|
|
9695
|
+
|
|
9696
|
+
function _defineProperty$4(obj, key, value) {
|
|
9697
|
+
if (key in obj) {
|
|
9698
|
+
Object.defineProperty(obj, key, {
|
|
9699
|
+
value: value,
|
|
9700
|
+
enumerable: true,
|
|
9701
|
+
configurable: true,
|
|
9702
|
+
writable: true
|
|
9703
|
+
});
|
|
9667
9704
|
} else {
|
|
9668
|
-
|
|
9669
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
9670
|
-
};
|
|
9705
|
+
obj[key] = value;
|
|
9671
9706
|
}
|
|
9672
9707
|
|
|
9673
|
-
return
|
|
9708
|
+
return obj;
|
|
9674
9709
|
}
|
|
9675
9710
|
|
|
9676
9711
|
function isWindow(obj) {
|
|
@@ -9853,6 +9888,48 @@
|
|
|
9853
9888
|
return handler;
|
|
9854
9889
|
}
|
|
9855
9890
|
|
|
9891
|
+
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
|
|
9892
|
+
|
|
9893
|
+
function initUI(options) {
|
|
9894
|
+
var cont = window.document.createElement('div');
|
|
9895
|
+
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;';
|
|
9896
|
+
style += ' z-index: 2147483647; position: fixed;';
|
|
9897
|
+
cont.setAttribute('style', style);
|
|
9898
|
+
cont.setAttribute('ignorelocizeeditor', '');
|
|
9899
|
+
cont.setAttribute('translated', ''); // if(options.locizeEditorToggle.containerClasses) {
|
|
9900
|
+
// const classes = options.locizeEditorToggle.containerClasses.length > 1 ? options.locizeEditorToggle.containerClasses.split(' ') : options.locizeEditorToggle.containerClasses;
|
|
9901
|
+
// classes.forEach(function(cssClass) {
|
|
9902
|
+
// cont.classList.add(cssClass);
|
|
9903
|
+
// });
|
|
9904
|
+
// }
|
|
9905
|
+
|
|
9906
|
+
var title = window.document.createElement('h4');
|
|
9907
|
+
title.id = 'locize-title';
|
|
9908
|
+
title.innerHTML = 'Translate InContext:';
|
|
9909
|
+
title.setAttribute('style', 'font-family: "Helvetica", "Arial", sans-serif; font-size: 14px; margin: 0 0 5px 0; color: #1976d2; font-weight: 300;');
|
|
9910
|
+
title.setAttribute('ignorelocizeeditor', '');
|
|
9911
|
+
cont.appendChild(title);
|
|
9912
|
+
var turnOn = window.document.createElement('button');
|
|
9913
|
+
turnOn.innerHTML = 'Open in locize';
|
|
9914
|
+
turnOn.setAttribute('style', "".concat(baseBtn, " background-color: #1976d2;"));
|
|
9915
|
+
|
|
9916
|
+
turnOn.onclick = function () {
|
|
9917
|
+
var i18next = options.getI18next();
|
|
9918
|
+
var backendOptions = i18next && i18next.options && i18next.options.backend;
|
|
9919
|
+
|
|
9920
|
+
var _backendOptions$optio = _objectSpread2$1(_objectSpread2$1({}, backendOptions), options),
|
|
9921
|
+
projectId = _backendOptions$optio.projectId,
|
|
9922
|
+
version = _backendOptions$optio.version;
|
|
9923
|
+
|
|
9924
|
+
var editorUrl = options.editorUrl || backendOptions && backendOptions.loadPath && backendOptions.loadPath.indexOf('https://api-dev.locize.app') === 0 && 'https://dev.locize.app' || 'https://www.locize.app';
|
|
9925
|
+
window.location = "".concat(editorUrl, "/cat/").concat(projectId, "/v/").concat(version, "/incontext?sourceurl=").concat(encodeURI(window.location.href));
|
|
9926
|
+
};
|
|
9927
|
+
|
|
9928
|
+
turnOn.setAttribute('ignorelocizeeditor', '');
|
|
9929
|
+
cont.appendChild(turnOn);
|
|
9930
|
+
window.document.body.appendChild(cont);
|
|
9931
|
+
}
|
|
9932
|
+
|
|
9856
9933
|
var isInIframe = true;
|
|
9857
9934
|
|
|
9858
9935
|
try {
|
|
@@ -9889,10 +9966,11 @@
|
|
|
9889
9966
|
}
|
|
9890
9967
|
}
|
|
9891
9968
|
|
|
9969
|
+
var i18next;
|
|
9892
9970
|
var locizePlugin = {
|
|
9893
9971
|
type: '3rdParty',
|
|
9894
9972
|
init: function init(i18n) {
|
|
9895
|
-
|
|
9973
|
+
i18next = i18n;
|
|
9896
9974
|
addLocizeSavedHandler(function (res) {
|
|
9897
9975
|
res.updated.forEach(function (item) {
|
|
9898
9976
|
var lng = item.lng,
|
|
@@ -9914,7 +9992,19 @@
|
|
|
9914
9992
|
}
|
|
9915
9993
|
};
|
|
9916
9994
|
|
|
9995
|
+
function getI18next() {
|
|
9996
|
+
return i18next;
|
|
9997
|
+
}
|
|
9998
|
+
|
|
9999
|
+
function showLocizeLink() {
|
|
10000
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10001
|
+
if (!isInIframe) initUI(_objectSpread2$1(_objectSpread2$1({}, options), {}, {
|
|
10002
|
+
getI18next: getI18next
|
|
10003
|
+
}));
|
|
10004
|
+
}
|
|
10005
|
+
|
|
9917
10006
|
if (typeof window !== 'undefined') {
|
|
10007
|
+
// eslint-disable-next-line consistent-return
|
|
9918
10008
|
window.addEventListener('message', function (e) {
|
|
9919
10009
|
if (e.data.message === 'isLocizeEnabled') {
|
|
9920
10010
|
// console.warn("result: ", ev.data);
|
|
@@ -9965,7 +10055,7 @@
|
|
|
9965
10055
|
});
|
|
9966
10056
|
}
|
|
9967
10057
|
|
|
9968
|
-
|
|
10058
|
+
function turnOn() {
|
|
9969
10059
|
scriptTurnedOff = false;
|
|
9970
10060
|
if (!clickInterceptionEnabled) window.document.body.addEventListener('click', handler, true);
|
|
9971
10061
|
clickInterceptionEnabled = true;
|
|
@@ -9973,9 +10063,9 @@
|
|
|
9973
10063
|
message: 'turnedOn'
|
|
9974
10064
|
}, origin);
|
|
9975
10065
|
return scriptTurnedOff;
|
|
9976
|
-
}
|
|
10066
|
+
}
|
|
9977
10067
|
|
|
9978
|
-
|
|
10068
|
+
function turnOff() {
|
|
9979
10069
|
scriptTurnedOff = true;
|
|
9980
10070
|
if (clickInterceptionEnabled) window.document.body.removeEventListener('click', handler, true);
|
|
9981
10071
|
clickInterceptionEnabled = false;
|
|
@@ -9986,10 +10076,10 @@
|
|
|
9986
10076
|
message: 'forcedOff'
|
|
9987
10077
|
}, origin);
|
|
9988
10078
|
return scriptTurnedOff;
|
|
9989
|
-
}
|
|
10079
|
+
}
|
|
9990
10080
|
|
|
9991
10081
|
var {
|
|
9992
|
-
i18next
|
|
10082
|
+
i18next: i18next$1
|
|
9993
10083
|
} = i18nextify;
|
|
9994
10084
|
var enforce = {
|
|
9995
10085
|
saveMissingTo: 'all'
|
|
@@ -9998,13 +10088,13 @@
|
|
|
9998
10088
|
reloadOnSave: true,
|
|
9999
10089
|
bindSavedMissing: true
|
|
10000
10090
|
};
|
|
10001
|
-
i18next.use(I18NextLocizeBackend).use(locizePlugin);
|
|
10002
|
-
i18next.on('editorSaved', () => {
|
|
10091
|
+
i18next$1.use(I18NextLocizeBackend).use(locizePlugin);
|
|
10092
|
+
i18next$1.on('editorSaved', () => {
|
|
10003
10093
|
i18nextify.forceRerender();
|
|
10004
10094
|
});
|
|
10005
|
-
var originalInit = i18next.init;
|
|
10095
|
+
var originalInit = i18next$1.init;
|
|
10006
10096
|
|
|
10007
|
-
i18next.init = function () {
|
|
10097
|
+
i18next$1.init = function () {
|
|
10008
10098
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10009
10099
|
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
10010
10100
|
options = _objectSpread2(_objectSpread2({}, defaults$3), options);
|
|
@@ -10048,44 +10138,45 @@
|
|
|
10048
10138
|
callback(err, t);
|
|
10049
10139
|
}
|
|
10050
10140
|
|
|
10051
|
-
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') return originalInit.call(i18next, _objectSpread2(_objectSpread2({}, options), enforce), handleI18nextInitialized);
|
|
10141
|
+
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') return originalInit.call(i18next$1, _objectSpread2(_objectSpread2({}, options), enforce), handleI18nextInitialized);
|
|
10052
10142
|
var locizeBackend = new I18NextLocizeBackend(options.backend);
|
|
10053
10143
|
locizeBackend.getOptions((err, opts) => {
|
|
10054
10144
|
if (err && typeof console === 'object' && typeof console.error === 'function') console.error(err);
|
|
10055
|
-
originalInit.call(i18next, _objectSpread2(_objectSpread2(_objectSpread2({}, opts), options), enforce), handleI18nextInitialized);
|
|
10145
|
+
originalInit.call(i18next$1, _objectSpread2(_objectSpread2(_objectSpread2({}, opts), options), enforce), handleI18nextInitialized);
|
|
10056
10146
|
});
|
|
10057
10147
|
};
|
|
10058
10148
|
|
|
10059
10149
|
i18nextify.getLanguages = function (callback) {
|
|
10060
|
-
if (i18next.services.backendConnector) {
|
|
10061
|
-
i18next.services.backendConnector.backend.getLanguages(callback);
|
|
10150
|
+
if (i18next$1.services.backendConnector) {
|
|
10151
|
+
i18next$1.services.backendConnector.backend.getLanguages(callback);
|
|
10062
10152
|
} else {
|
|
10063
10153
|
function ready() {
|
|
10064
|
-
i18next.off('initialized', ready);
|
|
10065
|
-
i18next.services.backendConnector.backend.getLanguages(callback);
|
|
10154
|
+
i18next$1.off('initialized', ready);
|
|
10155
|
+
i18next$1.services.backendConnector.backend.getLanguages(callback);
|
|
10066
10156
|
}
|
|
10067
10157
|
|
|
10068
|
-
i18next.on('initialized', ready);
|
|
10158
|
+
i18next$1.on('initialized', ready);
|
|
10069
10159
|
}
|
|
10070
10160
|
};
|
|
10071
10161
|
|
|
10072
10162
|
i18nextify.getOptions = function (callback) {
|
|
10073
|
-
if (i18next.services.backendConnector) {
|
|
10074
|
-
i18next.services.backendConnector.backend.getOptions(callback);
|
|
10163
|
+
if (i18next$1.services.backendConnector) {
|
|
10164
|
+
i18next$1.services.backendConnector.backend.getOptions(callback);
|
|
10075
10165
|
} else {
|
|
10076
10166
|
function ready() {
|
|
10077
|
-
i18next.off('initialized', ready);
|
|
10078
|
-
i18next.services.backendConnector.backend.getOptions(callback);
|
|
10167
|
+
i18next$1.off('initialized', ready);
|
|
10168
|
+
i18next$1.services.backendConnector.backend.getOptions(callback);
|
|
10079
10169
|
}
|
|
10080
10170
|
|
|
10081
|
-
i18next.on('initialized', ready);
|
|
10171
|
+
i18next$1.on('initialized', ready);
|
|
10082
10172
|
}
|
|
10083
10173
|
}; // add editor functions
|
|
10084
10174
|
|
|
10085
10175
|
|
|
10086
10176
|
i18nextify.editor = {
|
|
10087
|
-
turnOn
|
|
10088
|
-
turnOff
|
|
10177
|
+
turnOn,
|
|
10178
|
+
turnOff,
|
|
10179
|
+
showLocizeLink
|
|
10089
10180
|
};
|
|
10090
10181
|
|
|
10091
10182
|
return i18nextify;
|