locizify 7.0.2 → 7.0.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/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +29 -0
- package/CHANGELOG.md +8 -0
- package/README.md +11 -6
- package/dist/commonjs/index.js +12 -6
- package/dist/es/index.js +12 -6
- package/dist/umd/locizify.js +53 -12
- package/dist/umd/locizify.min.js +1 -1
- package/eslint.config.js +41 -0
- package/locizify.js +53 -12
- package/locizify.min.js +1 -1
- package/package.json +7 -7
- package/rollup.config.js +13 -13
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"[javascript]": {
|
|
3
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
4
|
+
},
|
|
5
|
+
"[javascriptreact]": {
|
|
6
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
7
|
+
},
|
|
8
|
+
"[typescript]": {
|
|
9
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
10
|
+
},
|
|
11
|
+
"[typescriptreact]": {
|
|
12
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
13
|
+
},
|
|
14
|
+
// enable ESLint formatting
|
|
15
|
+
"eslint.format.enable": true,
|
|
16
|
+
// run ESLint “fix” on save
|
|
17
|
+
"editor.codeActionsOnSave": {
|
|
18
|
+
"source.fixAll.eslint": "explicit"
|
|
19
|
+
},
|
|
20
|
+
// ensure ESLint runs when you save .js/.jsx/.ts/.tsx files
|
|
21
|
+
"eslint.validate": [
|
|
22
|
+
"javascript",
|
|
23
|
+
"javascriptreact",
|
|
24
|
+
"typescript",
|
|
25
|
+
"typescriptreact"
|
|
26
|
+
],
|
|
27
|
+
// run linting on save
|
|
28
|
+
"eslint.run": "onSave"
|
|
29
|
+
}
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,8 +12,9 @@ Just drop the following line to your header to deliver your content in any langu
|
|
|
12
12
|
id="locizify"
|
|
13
13
|
projectid="[PROJECT_ID]"
|
|
14
14
|
apikey="[API_KEY]"
|
|
15
|
-
src="https://unpkg.com/locizify@^
|
|
15
|
+
src="https://unpkg.com/locizify@^7.0.3"
|
|
16
16
|
autopilot="true"
|
|
17
|
+
cdnType="standard"
|
|
17
18
|
></script>
|
|
18
19
|
|
|
19
20
|
<!-- or -->
|
|
@@ -21,8 +22,9 @@ Just drop the following line to your header to deliver your content in any langu
|
|
|
21
22
|
id="locizify"
|
|
22
23
|
projectid="[PROJECT_ID]"
|
|
23
24
|
apikey="[API_KEY]"
|
|
24
|
-
src="https://cdn.jsdelivr.net/npm/locizify@^
|
|
25
|
+
src="https://cdn.jsdelivr.net/npm/locizify@^7.0.3"
|
|
25
26
|
autopilot="true"
|
|
27
|
+
cdnType="standard"
|
|
26
28
|
></script>
|
|
27
29
|
|
|
28
30
|
```
|
|
@@ -69,8 +71,9 @@ Add the script to your page:
|
|
|
69
71
|
id="locizify"
|
|
70
72
|
projectid="[PROJECT_ID]"
|
|
71
73
|
apikey="[API_KEY]"
|
|
72
|
-
src="https://unpkg.com/locizify@^
|
|
74
|
+
src="https://unpkg.com/locizify@^7.0.3"
|
|
73
75
|
autopilot
|
|
76
|
+
cdnType="standard"
|
|
74
77
|
></script>
|
|
75
78
|
</head>
|
|
76
79
|
...
|
|
@@ -102,7 +105,7 @@ Add the script to your page:
|
|
|
102
105
|
apikey="[API_KEY]"
|
|
103
106
|
referencelng="[LNG]"
|
|
104
107
|
fallbacklng="[LNG]"
|
|
105
|
-
src="https://unpkg.com/locizify@^
|
|
108
|
+
src="https://unpkg.com/locizify@^7.0.3"
|
|
106
109
|
|
|
107
110
|
// all custom attributes can also be prefixed with data-
|
|
108
111
|
// data-projectid="[PROJECT_ID]"
|
|
@@ -117,6 +120,7 @@ Add the script to your page:
|
|
|
117
120
|
debug="[true|false (default false)]"
|
|
118
121
|
autopilot="[true|false (default false)]" // automatically configures fallbackLng and supportedLngs
|
|
119
122
|
load="[all|currentOnly|languageOnly (default all)]" // https://www.i18next.com/overview/configuration-options
|
|
123
|
+
cdnType="[standard|pro (default pro)]"
|
|
120
124
|
|
|
121
125
|
// others
|
|
122
126
|
// you can define any other option below just use the lowercased name and for arrays use comma separated values, eg.:
|
|
@@ -132,7 +136,7 @@ Add the script to your page:
|
|
|
132
136
|
<!DOCTYPE html>
|
|
133
137
|
<html>
|
|
134
138
|
<head>
|
|
135
|
-
<script src="https://unpkg.com/locizify@^
|
|
139
|
+
<script src="https://unpkg.com/locizify@^7.0.3"></script>
|
|
136
140
|
<script>
|
|
137
141
|
locizify.init({
|
|
138
142
|
// required
|
|
@@ -146,7 +150,8 @@ Add the script to your page:
|
|
|
146
150
|
// please keep those to your local system, staging, test servers (not production)
|
|
147
151
|
allowedAddOrUpdateHosts: ['localhost']
|
|
148
152
|
// alternatively, pass a function:
|
|
149
|
-
allowedAddOrUpdateHosts: function(hostname) { return hostname.endsWith('staging.example.com') }
|
|
153
|
+
allowedAddOrUpdateHosts: function(hostname) { return hostname.endsWith('staging.example.com') },
|
|
154
|
+
cdnType: 'standard' // default 'pro'
|
|
150
155
|
},
|
|
151
156
|
|
|
152
157
|
// defaults that are set
|
package/dist/commonjs/index.js
CHANGED
|
@@ -48,7 +48,7 @@ i18next.init = function () {
|
|
|
48
48
|
var backend = {};
|
|
49
49
|
var toRead = ['fallbackLng', 'saveMissing', 'debug', 'autorun', 'ele', 'cleanIndent', 'cleanWhitespace', 'namespace', 'namespaceFromPath', 'load'];
|
|
50
50
|
var toReadAsArray = ['ignoreTags', 'ignoreIds', 'ignoreClasses', 'translateAttributes', 'mergeTags', 'inlineTags', 'ignoreInlineOn', 'ignoreCleanIndentFor', 'ns'];
|
|
51
|
-
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot'];
|
|
51
|
+
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot', 'cdnType', 'noCache'];
|
|
52
52
|
toRead.forEach(function (attr) {
|
|
53
53
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
54
54
|
if (value === 'true') value = true;
|
|
@@ -57,9 +57,11 @@ i18next.init = function () {
|
|
|
57
57
|
});
|
|
58
58
|
toReadAsArray.forEach(function (attr) {
|
|
59
59
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
60
|
-
if (value !== undefined && value !== null)
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if (value !== undefined && value !== null) {
|
|
61
|
+
config[attr] = value.split(',').map(function (item) {
|
|
62
|
+
return item.trim();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
63
65
|
});
|
|
64
66
|
toReadBackend.forEach(function (attr) {
|
|
65
67
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
@@ -91,10 +93,14 @@ i18next.init = function () {
|
|
|
91
93
|
if (!options.backend.apiKey && getQsParameterByName('apikey')) {
|
|
92
94
|
options.backend.apiKey = getQsParameterByName('apikey');
|
|
93
95
|
}
|
|
94
|
-
if (!options.backend.autoPilot || options.backend.autoPilot === 'false')
|
|
96
|
+
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') {
|
|
97
|
+
return originalInit.call(i18next, _objectSpread(_objectSpread({}, options), enforce), handleI18nextInitialized);
|
|
98
|
+
}
|
|
95
99
|
var locizeBackend = new _i18nextLocizeBackend["default"](options.backend);
|
|
96
100
|
locizeBackend.getOptions(function (err, opts) {
|
|
97
|
-
if (err && (typeof console === "undefined" ? "undefined" : (0, _typeof2["default"])(console)) === 'object' && typeof console.error === 'function')
|
|
101
|
+
if (err && (typeof console === "undefined" ? "undefined" : (0, _typeof2["default"])(console)) === 'object' && typeof console.error === 'function') {
|
|
102
|
+
console.error(err);
|
|
103
|
+
}
|
|
98
104
|
originalInit.call(i18next, _objectSpread(_objectSpread(_objectSpread({}, opts), options), enforce), handleI18nextInitialized);
|
|
99
105
|
});
|
|
100
106
|
};
|
package/dist/es/index.js
CHANGED
|
@@ -41,7 +41,7 @@ i18next.init = function () {
|
|
|
41
41
|
var backend = {};
|
|
42
42
|
var toRead = ['fallbackLng', 'saveMissing', 'debug', 'autorun', 'ele', 'cleanIndent', 'cleanWhitespace', 'namespace', 'namespaceFromPath', 'load'];
|
|
43
43
|
var toReadAsArray = ['ignoreTags', 'ignoreIds', 'ignoreClasses', 'translateAttributes', 'mergeTags', 'inlineTags', 'ignoreInlineOn', 'ignoreCleanIndentFor', 'ns'];
|
|
44
|
-
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot'];
|
|
44
|
+
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot', 'cdnType', 'noCache'];
|
|
45
45
|
toRead.forEach(function (attr) {
|
|
46
46
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
47
47
|
if (value === 'true') value = true;
|
|
@@ -50,9 +50,11 @@ i18next.init = function () {
|
|
|
50
50
|
});
|
|
51
51
|
toReadAsArray.forEach(function (attr) {
|
|
52
52
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
53
|
-
if (value !== undefined && value !== null)
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (value !== undefined && value !== null) {
|
|
54
|
+
config[attr] = value.split(',').map(function (item) {
|
|
55
|
+
return item.trim();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
56
58
|
});
|
|
57
59
|
toReadBackend.forEach(function (attr) {
|
|
58
60
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
@@ -84,10 +86,14 @@ i18next.init = function () {
|
|
|
84
86
|
if (!options.backend.apiKey && getQsParameterByName('apikey')) {
|
|
85
87
|
options.backend.apiKey = getQsParameterByName('apikey');
|
|
86
88
|
}
|
|
87
|
-
if (!options.backend.autoPilot || options.backend.autoPilot === 'false')
|
|
89
|
+
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') {
|
|
90
|
+
return originalInit.call(i18next, _objectSpread(_objectSpread({}, options), enforce), handleI18nextInitialized);
|
|
91
|
+
}
|
|
88
92
|
var locizeBackend = new LocizeBackend(options.backend);
|
|
89
93
|
locizeBackend.getOptions(function (err, opts) {
|
|
90
|
-
if (err && (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && typeof console.error === 'function')
|
|
94
|
+
if (err && (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && typeof console.error === 'function') {
|
|
95
|
+
console.error(err);
|
|
96
|
+
}
|
|
91
97
|
originalInit.call(i18next, _objectSpread(_objectSpread(_objectSpread({}, opts), options), enforce), handleI18nextInitialized);
|
|
92
98
|
});
|
|
93
99
|
};
|
package/dist/umd/locizify.js
CHANGED
|
@@ -7273,6 +7273,14 @@
|
|
|
7273
7273
|
}
|
|
7274
7274
|
var resolver = function resolver(response) {
|
|
7275
7275
|
var resourceNotExisting = response.headers && response.headers.get('x-cache') === 'Error from cloudfront';
|
|
7276
|
+
if (options.cdnType === 'standard' && response.status === 404 && (!response.headers || !response.headers.get('x-cache'))) {
|
|
7277
|
+
resourceNotExisting = true;
|
|
7278
|
+
return callback(null, {
|
|
7279
|
+
status: 200,
|
|
7280
|
+
data: '{}',
|
|
7281
|
+
resourceNotExisting: resourceNotExisting
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7276
7284
|
if (!response.ok) return callback(response.statusText || 'Error', {
|
|
7277
7285
|
status: response.status,
|
|
7278
7286
|
resourceNotExisting: resourceNotExisting
|
|
@@ -7314,6 +7322,14 @@
|
|
|
7314
7322
|
}
|
|
7315
7323
|
x.onreadystatechange = function () {
|
|
7316
7324
|
var resourceNotExisting = x.getResponseHeader('x-cache') === 'Error from cloudfront';
|
|
7325
|
+
if (options.cdnType === 'standard' && x.status === 404 && !x.getResponseHeader('x-cache')) {
|
|
7326
|
+
resourceNotExisting = true;
|
|
7327
|
+
return x.readyState > 3 && callback(null, {
|
|
7328
|
+
status: 200,
|
|
7329
|
+
data: '{}',
|
|
7330
|
+
resourceNotExisting: resourceNotExisting
|
|
7331
|
+
});
|
|
7332
|
+
}
|
|
7317
7333
|
x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, {
|
|
7318
7334
|
status: x.status,
|
|
7319
7335
|
data: x.responseText,
|
|
@@ -7377,13 +7393,21 @@
|
|
|
7377
7393
|
}
|
|
7378
7394
|
return ("string" === r ? String : Number)(t);
|
|
7379
7395
|
}
|
|
7380
|
-
var
|
|
7396
|
+
var getApiPaths = function getApiPaths(cdnType) {
|
|
7397
|
+
if (!cdnType) cdnType = 'pro';
|
|
7381
7398
|
return {
|
|
7382
|
-
loadPath:
|
|
7383
|
-
privatePath:
|
|
7384
|
-
getLanguagesPath:
|
|
7385
|
-
addPath:
|
|
7386
|
-
updatePath:
|
|
7399
|
+
loadPath: "https://api".concat(cdnType === 'standard' ? '.lite' : '', ".locize.app/{{projectId}}/{{version}}/{{lng}}/{{ns}}"),
|
|
7400
|
+
privatePath: "https://api".concat(cdnType === 'standard' ? '.lite' : '', ".locize.app/private/{{projectId}}/{{version}}/{{lng}}/{{ns}}"),
|
|
7401
|
+
getLanguagesPath: "https://api".concat(cdnType === 'standard' ? '.lite' : '', ".locize.app/languages/{{projectId}}"),
|
|
7402
|
+
addPath: "https://api".concat(cdnType === 'standard' ? '.lite' : '', ".locize.app/missing/{{projectId}}/{{version}}/{{lng}}/{{ns}}"),
|
|
7403
|
+
updatePath: "https://api".concat(cdnType === 'standard' ? '.lite' : '', ".locize.app/update/{{projectId}}/{{version}}/{{lng}}/{{ns}}")
|
|
7404
|
+
};
|
|
7405
|
+
};
|
|
7406
|
+
var getDefaults$3 = function getDefaults(cdnType) {
|
|
7407
|
+
if (!cdnType) cdnType = 'pro';
|
|
7408
|
+
return defaults$1({
|
|
7409
|
+
cdnType: cdnType,
|
|
7410
|
+
noCache: false,
|
|
7387
7411
|
referenceLng: 'en',
|
|
7388
7412
|
crossDomain: true,
|
|
7389
7413
|
setContentTypeJSON: false,
|
|
@@ -7397,7 +7421,7 @@
|
|
|
7397
7421
|
checkForProjectTimeout: 3 * 1000,
|
|
7398
7422
|
storageExpiration: 60 * 60 * 1000,
|
|
7399
7423
|
writeDebounce: 5 * 1000
|
|
7400
|
-
};
|
|
7424
|
+
}, getApiPaths(cdnType));
|
|
7401
7425
|
};
|
|
7402
7426
|
var hasLocalStorageSupport$1;
|
|
7403
7427
|
try {
|
|
@@ -7519,8 +7543,9 @@
|
|
|
7519
7543
|
options.referenceLng = allOptions.fallbackLng[0];
|
|
7520
7544
|
}
|
|
7521
7545
|
this.services = services;
|
|
7522
|
-
var
|
|
7546
|
+
var orgPassedOptions = defaults$1({}, options);
|
|
7523
7547
|
var passedOpt = defaults$1(options, this.options || {});
|
|
7548
|
+
var defOpt = getDefaults$3(passedOpt.cdnType);
|
|
7524
7549
|
if (passedOpt.reloadInterval && passedOpt.reloadInterval < 5 * 60 * 1000) {
|
|
7525
7550
|
console.warn('Your configured reloadInterval option is to low.');
|
|
7526
7551
|
passedOpt.reloadInterval = defOpt.reloadInterval;
|
|
@@ -7530,9 +7555,19 @@
|
|
|
7530
7555
|
this.somethingLoaded = false;
|
|
7531
7556
|
this.isProjectNotExisting = false;
|
|
7532
7557
|
this.storage = getStorage(this.options.storageExpiration);
|
|
7558
|
+
var apiPaths = getApiPaths(this.options.cdnType);
|
|
7559
|
+
Object.keys(apiPaths).forEach(function (ap) {
|
|
7560
|
+
if (!orgPassedOptions[ap]) _this.options[ap] = apiPaths[ap];
|
|
7561
|
+
});
|
|
7533
7562
|
if (this.options.pull) {
|
|
7534
7563
|
console.warn('The pull API was removed use "private: true" option instead: https://www.locize.com/docs/api#fetch-private-namespace-resources');
|
|
7535
7564
|
}
|
|
7565
|
+
if (allOptions.debug && orgPassedOptions.noCache === undefined && this.options.cdnType === 'standard') {
|
|
7566
|
+
this.options.noCache = true;
|
|
7567
|
+
}
|
|
7568
|
+
if (this.options.noCache && this.options.cdnType !== 'standard') {
|
|
7569
|
+
console.warn("The 'noCache' option is not available for 'cdnType' '".concat(this.options.cdnType, "'!"));
|
|
7570
|
+
}
|
|
7536
7571
|
var hostname = typeof window !== 'undefined' && window.location && window.location.hostname;
|
|
7537
7572
|
if (hostname) {
|
|
7538
7573
|
this.isAddOrUpdateAllowed = typeof this.options.allowedAddOrUpdateHosts === 'function' ? this.options.allowedAddOrUpdateHosts(hostname) : this.options.allowedAddOrUpdateHosts.indexOf(hostname) > -1;
|
|
@@ -11492,7 +11527,7 @@
|
|
|
11492
11527
|
var backend = {};
|
|
11493
11528
|
var toRead = ['fallbackLng', 'saveMissing', 'debug', 'autorun', 'ele', 'cleanIndent', 'cleanWhitespace', 'namespace', 'namespaceFromPath', 'load'];
|
|
11494
11529
|
var toReadAsArray = ['ignoreTags', 'ignoreIds', 'ignoreClasses', 'translateAttributes', 'mergeTags', 'inlineTags', 'ignoreInlineOn', 'ignoreCleanIndentFor', 'ns'];
|
|
11495
|
-
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot'];
|
|
11530
|
+
var toReadBackend = ['projectId', 'apiKey', 'referenceLng', 'version', 'allowedAddOrUpdateHost', 'autoPilot', 'cdnType', 'noCache'];
|
|
11496
11531
|
toRead.forEach(attr => {
|
|
11497
11532
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
11498
11533
|
if (value === 'true') value = true;
|
|
@@ -11501,7 +11536,9 @@
|
|
|
11501
11536
|
});
|
|
11502
11537
|
toReadAsArray.forEach(attr => {
|
|
11503
11538
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
11504
|
-
if (value !== undefined && value !== null)
|
|
11539
|
+
if (value !== undefined && value !== null) {
|
|
11540
|
+
config[attr] = value.split(',').map(item => item.trim());
|
|
11541
|
+
}
|
|
11505
11542
|
});
|
|
11506
11543
|
toReadBackend.forEach(attr => {
|
|
11507
11544
|
var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
|
|
@@ -11533,10 +11570,14 @@
|
|
|
11533
11570
|
if (!options.backend.apiKey && getQsParameterByName$1('apikey')) {
|
|
11534
11571
|
options.backend.apiKey = getQsParameterByName$1('apikey');
|
|
11535
11572
|
}
|
|
11536
|
-
if (!options.backend.autoPilot || options.backend.autoPilot === 'false')
|
|
11573
|
+
if (!options.backend.autoPilot || options.backend.autoPilot === 'false') {
|
|
11574
|
+
return originalInit.call(i18next$1, _objectSpread2(_objectSpread2({}, options), enforce), handleI18nextInitialized);
|
|
11575
|
+
}
|
|
11537
11576
|
var locizeBackend = new I18NextLocizeBackend(options.backend);
|
|
11538
11577
|
locizeBackend.getOptions((err, opts) => {
|
|
11539
|
-
if (err && typeof console === 'object' && typeof console.error === 'function')
|
|
11578
|
+
if (err && typeof console === 'object' && typeof console.error === 'function') {
|
|
11579
|
+
console.error(err);
|
|
11580
|
+
}
|
|
11540
11581
|
originalInit.call(i18next$1, _objectSpread2(_objectSpread2(_objectSpread2({}, opts), options), enforce), handleI18nextInitialized);
|
|
11541
11582
|
});
|
|
11542
11583
|
};
|