locize 4.0.11 → 4.0.13
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 +9 -1
- package/dist/cjs/api/handleEditKey.js +3 -1
- package/dist/cjs/api/handleRequestPopupChanges.js +8 -4
- package/dist/cjs/api/handleSendMatchedUninstrumented.js +3 -1
- package/dist/cjs/implementations/dummyImplementation.js +4 -12
- package/dist/cjs/implementations/i18nextImplementation.js +3 -1
- package/dist/cjs/locizePlugin.js +3 -3
- package/dist/cjs/parser.js +3 -3
- package/dist/cjs/process.js +3 -7
- package/dist/cjs/startStandalone.js +3 -1
- package/dist/cjs/ui/highlightNode.js +0 -1
- package/dist/cjs/ui/popup.js +8 -4
- package/dist/cjs/utils.js +9 -3
- package/dist/esm/api/handleEditKey.js +3 -1
- package/dist/esm/api/handleRequestPopupChanges.js +8 -4
- package/dist/esm/api/handleSendMatchedUninstrumented.js +3 -1
- package/dist/esm/implementations/dummyImplementation.js +4 -12
- package/dist/esm/implementations/i18nextImplementation.js +3 -1
- package/dist/esm/locizePlugin.js +3 -3
- package/dist/esm/parser.js +3 -3
- package/dist/esm/process.js +2 -6
- package/dist/esm/startStandalone.js +3 -1
- package/dist/esm/ui/highlightNode.js +0 -1
- package/dist/esm/ui/popup.js +8 -4
- package/dist/esm/utils.js +9 -4
- package/dist/umd/locize.js +836 -191
- package/dist/umd/locize.min.js +1 -1
- package/locize.js +836 -191
- package/locize.min.js +1 -1
- package/package.json +2 -2
- package/src/_startStandalone.js +1 -2
- package/src/api/handleEditKey.js +1 -2
- package/src/api/handleRequestPopupChanges.js +4 -6
- package/src/api/handleSendMatchedUninstrumented.js +1 -2
- package/src/clickHandler.js +3 -6
- package/src/implementations/dummyImplementation.js +5 -4
- package/src/implementations/i18nextImplementation.js +1 -2
- package/src/locizePlugin.js +120 -116
- package/src/parser.js +11 -11
- package/src/process.js +2 -9
- package/src/startStandalone.js +1 -2
- package/src/ui/highlightNode.js +26 -26
- package/src/ui/popup.js +4 -6
- package/src/utils.js +18 -12
- package/src/vars.js +2 -2
package/src/locizePlugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PostProcessor, unwrap } from 'i18next-subliminal'
|
|
2
2
|
import { start } from './process.js'
|
|
3
|
-
|
|
3
|
+
import { isInIframe, getQsParameterByName } from './utils.js'
|
|
4
4
|
import * as implementations from './implementations/index.js'
|
|
5
5
|
|
|
6
6
|
function configurePostProcessor (i18next, options) {
|
|
@@ -17,120 +17,120 @@ function configurePostProcessor (i18next, options) {
|
|
|
17
17
|
options.postProcessPassResolved = true
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function getImplementation (i18n) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
20
|
+
// function getImplementation (i18n) {
|
|
21
|
+
// const impl = {
|
|
22
|
+
// getResource: (lng, ns, key) => {
|
|
23
|
+
// return i18n.getResource && i18n.getResource(lng, ns, key)
|
|
24
|
+
// },
|
|
25
|
+
// setResource: (lng, ns, key, value) => {
|
|
26
|
+
// return i18n.addResource(lng, ns, key, value, { silent: true })
|
|
27
|
+
// },
|
|
28
|
+
// getResourceBundle: (lng, ns, cb) => {
|
|
29
|
+
// i18n.loadNamespaces(ns, () => {
|
|
30
|
+
// cb(i18n.getResourceBundle(lng, ns))
|
|
31
|
+
// })
|
|
32
|
+
// },
|
|
33
|
+
// getDefaultNS: () => {
|
|
34
|
+
// return i18n.options.defaultNS
|
|
35
|
+
// },
|
|
36
|
+
// getLng: () => {
|
|
37
|
+
// return (
|
|
38
|
+
// i18n.resolvedLanguage ||
|
|
39
|
+
// (i18n.languages && i18n.languages[0]) ||
|
|
40
|
+
// i18n.options.lng
|
|
41
|
+
// )
|
|
42
|
+
// },
|
|
43
|
+
// getSourceLng: () => {
|
|
44
|
+
// const fallback = i18n.options.fallbackLng
|
|
45
|
+
// if (typeof fallback === 'string') return fallback
|
|
46
|
+
// if (Array.isArray(fallback)) return fallback[fallback.length - 1]
|
|
47
|
+
|
|
48
|
+
// if (fallback && fallback.default) {
|
|
49
|
+
// if (typeof fallback.default === 'string') return fallback
|
|
50
|
+
// if (Array.isArray(fallback.default))
|
|
51
|
+
// return fallback.default[fallback.default.length - 1]
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// if (typeof fallback === 'function') {
|
|
55
|
+
// const res = fallback(i18n.resolvedLanguage)
|
|
56
|
+
// if (typeof res === 'string') return res
|
|
57
|
+
// if (Array.isArray(res)) return res[res.length - 1]
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
// return 'dev'
|
|
61
|
+
// },
|
|
62
|
+
// getLocizeDetails: () => {
|
|
63
|
+
// let backendName
|
|
64
|
+
// if (
|
|
65
|
+
// i18n.services.backendConnector.backend &&
|
|
66
|
+
// i18n.services.backendConnector.backend.options &&
|
|
67
|
+
// i18n.services.backendConnector.backend.options.loadPath &&
|
|
68
|
+
// i18n.services.backendConnector.backend.options.loadPath.indexOf(
|
|
69
|
+
// '.locize.'
|
|
70
|
+
// ) > 0
|
|
71
|
+
// ) {
|
|
72
|
+
// backendName = 'I18nextLocizeBackend'
|
|
73
|
+
// } else {
|
|
74
|
+
// backendName = i18n.services.backendConnector.backend
|
|
75
|
+
// ? i18n.services.backendConnector.backend.constructor.name
|
|
76
|
+
// : 'options.resources'
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
// const opts = {
|
|
80
|
+
// backendName,
|
|
81
|
+
// sourceLng: impl.getSourceLng(),
|
|
82
|
+
// i18nFormat:
|
|
83
|
+
// i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
84
|
+
// i18nFramework: 'i18next',
|
|
85
|
+
// isLocizify: i18n.options.isLocizify,
|
|
86
|
+
// defaultNS: i18n.options.defaultNS,
|
|
87
|
+
// targetLngs: [
|
|
88
|
+
// ...new Set(
|
|
89
|
+
// [].concat(i18n.options.preload, i18n.options.supportedLngs, [
|
|
90
|
+
// impl.getLng()
|
|
91
|
+
// ])
|
|
92
|
+
// )
|
|
93
|
+
// ].filter(
|
|
94
|
+
// l =>
|
|
95
|
+
// l !== 'cimode' &&
|
|
96
|
+
// l !== false &&
|
|
97
|
+
// l !== 'false' &&
|
|
98
|
+
// l !== undefined &&
|
|
99
|
+
// l !== impl.getSourceLng()
|
|
100
|
+
// ),
|
|
101
|
+
// ns: [
|
|
102
|
+
// ...new Set(
|
|
103
|
+
// [].concat(
|
|
104
|
+
// i18n.options.ns,
|
|
105
|
+
// i18n.options.fallbackNS,
|
|
106
|
+
// i18n.options.defaultNS
|
|
107
|
+
// )
|
|
108
|
+
// )
|
|
109
|
+
// ].filter(n => n !== false && n !== 'false')
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
// if (!i18n.options.backend && !i18n.options.editor) return opts
|
|
113
|
+
// const pickFrom = i18n.options.editor || i18n.options.backend
|
|
114
|
+
// return {
|
|
115
|
+
// ...opts,
|
|
116
|
+
// projectId: pickFrom.projectId,
|
|
117
|
+
// version: pickFrom.version
|
|
118
|
+
// }
|
|
119
|
+
// },
|
|
120
|
+
// bindLanguageChange: cb => {
|
|
121
|
+
// i18n.on('languageChanged', cb)
|
|
122
|
+
// },
|
|
123
|
+
// bindMissingKeyHandler: cb => {
|
|
124
|
+
// i18n.options.missingKeyHandler = (lng, ns, k, val, isUpdate, opts) => {
|
|
125
|
+
// if (!isUpdate) cb(lng, ns, k, val)
|
|
126
|
+
// }
|
|
127
|
+
// },
|
|
128
|
+
// triggerRerender: () => {
|
|
129
|
+
// i18n.emit('editorSaved')
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
// return impl
|
|
133
|
+
// }
|
|
134
134
|
|
|
135
135
|
let i18next
|
|
136
136
|
export const locizeEditorPlugin = (opt = {}) => {
|
|
@@ -147,7 +147,11 @@ export const locizeEditorPlugin = (opt = {}) => {
|
|
|
147
147
|
|
|
148
148
|
const impl = implementations.i18next.getImplementation(i18n)
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
const showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true'
|
|
151
|
+
|
|
152
|
+
// do only manipulate html if incontext popup is shown or if website is rendered in iframe in incontext view of locize ui.
|
|
153
|
+
if (isInIframe || showInContext) configurePostProcessor(i18next, options)
|
|
154
|
+
|
|
151
155
|
start(impl, opt) // we no longer show the legacy process but use the new way without popup opening
|
|
152
156
|
}
|
|
153
157
|
}
|
package/src/parser.js
CHANGED
|
@@ -67,18 +67,18 @@ function extractHiddenMeta (id, type, meta, children) {
|
|
|
67
67
|
[`${invisibleMeta.lng}`]:
|
|
68
68
|
invisibleMeta.source === 'translation' && i18n
|
|
69
69
|
? i18n?.getResource(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
invisibleMeta.lng,
|
|
71
|
+
invisibleMeta.ns,
|
|
72
|
+
invisibleMeta.key
|
|
73
|
+
)
|
|
74
74
|
: null,
|
|
75
75
|
[`${currentSourceLng}`]:
|
|
76
76
|
invisibleMeta.source === 'translation' && i18n
|
|
77
77
|
? i18n?.getResource(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
currentSourceLng,
|
|
79
|
+
invisibleMeta.ns,
|
|
80
|
+
invisibleMeta.key
|
|
81
|
+
)
|
|
82
82
|
: null
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -244,13 +244,13 @@ function handleNode (node) {
|
|
|
244
244
|
// merge and add data-i18n=[html]key
|
|
245
245
|
if (
|
|
246
246
|
nodeI18nMeta &&
|
|
247
|
-
nodeI18nMeta
|
|
247
|
+
nodeI18nMeta.html &&
|
|
248
248
|
i < node.childNodes.length - 1
|
|
249
249
|
) {
|
|
250
250
|
merge.push({ childIndex: i, child, text: txt })
|
|
251
251
|
} else if (
|
|
252
252
|
nodeI18nMeta &&
|
|
253
|
-
nodeI18nMeta
|
|
253
|
+
nodeI18nMeta.html &&
|
|
254
254
|
i === node.childNodes.length - 1
|
|
255
255
|
) {
|
|
256
256
|
merge.push({ childIndex: i, child, text: txt })
|
|
@@ -277,7 +277,7 @@ function handleNode (node) {
|
|
|
277
277
|
// )
|
|
278
278
|
|
|
279
279
|
// add data-i18n=key (inner text)
|
|
280
|
-
if (nodeI18nMeta && nodeI18nMeta
|
|
280
|
+
if (nodeI18nMeta && nodeI18nMeta.text) {
|
|
281
281
|
storeIfQualifiedKey(
|
|
282
282
|
node.uniqueID,
|
|
283
283
|
null,
|
package/src/process.js
CHANGED
|
@@ -5,18 +5,11 @@ import { initDragElement, initResizeElement } from './ui/popup.js'
|
|
|
5
5
|
import { Popup, popupId } from './ui/elements/popup.js'
|
|
6
6
|
import { getIframeUrl } from './vars.js'
|
|
7
7
|
import { api } from './api/index.js'
|
|
8
|
-
import { getQsParameterByName } from './utils.js'
|
|
8
|
+
import { isInIframe, getQsParameterByName } from './utils.js'
|
|
9
9
|
import * as implementations from './implementations/index.js'
|
|
10
10
|
|
|
11
11
|
const dummyImplementation = implementations.dummy.getImplementation()
|
|
12
12
|
|
|
13
|
-
let isInIframe = typeof window !== 'undefined'
|
|
14
|
-
try {
|
|
15
|
-
// eslint-disable-next-line no-undef, no-restricted-globals
|
|
16
|
-
isInIframe = self !== top
|
|
17
|
-
// eslint-disable-next-line no-empty
|
|
18
|
-
} catch (e) {}
|
|
19
|
-
|
|
20
13
|
// eslint-disable-next-line no-unused-vars
|
|
21
14
|
let data = []
|
|
22
15
|
|
|
@@ -108,5 +101,5 @@ export function start (
|
|
|
108
101
|
|
|
109
102
|
if (document.body) return continueToStart()
|
|
110
103
|
|
|
111
|
-
window.addEventListener('load', () => continueToStart())
|
|
104
|
+
if (typeof window !== 'undefined') window.addEventListener('load', () => continueToStart())
|
|
112
105
|
}
|
package/src/startStandalone.js
CHANGED
|
@@ -5,5 +5,4 @@ export function startStandalone (options = {}) {
|
|
|
5
5
|
start(implementation, Object.keys(rest).length > 0 ? rest : undefined)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
if (typeof window !== 'undefined')
|
|
9
|
-
window.locizeStartStandalone = startStandalone
|
|
8
|
+
if (typeof window !== 'undefined') { window.locizeStartStandalone = startStandalone }
|
package/src/ui/highlightNode.js
CHANGED
|
@@ -4,33 +4,33 @@ import { HighlightBox } from './elements/highlightBox.js'
|
|
|
4
4
|
import { computePosition, flip, shift, offset, arrow } from '@floating-ui/dom'
|
|
5
5
|
import { getOptimizedBoundingRectEle } from './utils.js'
|
|
6
6
|
|
|
7
|
-
const eleToOutline = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
23
|
-
const overriddenStyles = [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]
|
|
29
|
-
const originalStyles = {}
|
|
7
|
+
// const eleToOutline = [
|
|
8
|
+
// 'DIV',
|
|
9
|
+
// 'P',
|
|
10
|
+
// 'H1',
|
|
11
|
+
// 'H2',
|
|
12
|
+
// 'H3',
|
|
13
|
+
// 'H4',
|
|
14
|
+
// 'H5',
|
|
15
|
+
// 'H6',
|
|
16
|
+
// 'OL',
|
|
17
|
+
// 'UL',
|
|
18
|
+
// 'ADDRESS',
|
|
19
|
+
// 'BLOCKQUOTE',
|
|
20
|
+
// 'DL',
|
|
21
|
+
// 'PRE'
|
|
22
|
+
// ]
|
|
23
|
+
// const overriddenStyles = [
|
|
24
|
+
// 'outline',
|
|
25
|
+
// 'border-radius',
|
|
26
|
+
// 'outline-offset',
|
|
27
|
+
// 'filter'
|
|
28
|
+
// ]
|
|
29
|
+
// const originalStyles = {}
|
|
30
30
|
const selected = {}
|
|
31
31
|
|
|
32
32
|
export function highlight (item, node, keys) {
|
|
33
|
-
const { id } = item
|
|
33
|
+
// const { id } = item
|
|
34
34
|
|
|
35
35
|
// uncomment below if we do not won't the ribbon box to show on selected
|
|
36
36
|
// if (selected[id]) return
|
|
@@ -113,8 +113,8 @@ export function highlight (item, node, keys) {
|
|
|
113
113
|
side === 'bottom'
|
|
114
114
|
? 'rotate(90deg)'
|
|
115
115
|
: side === 'left'
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
? 'rotate(180deg)'
|
|
117
|
+
: ''
|
|
118
118
|
})
|
|
119
119
|
}
|
|
120
120
|
})
|
package/src/ui/popup.js
CHANGED
|
@@ -25,8 +25,7 @@ export function initDragElement () {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function dragMouseDown (e) {
|
|
28
|
-
if (!overlay)
|
|
29
|
-
overlay = document.getElementById('i18next-editor-popup-overlay')
|
|
28
|
+
if (!overlay) { overlay = document.getElementById('i18next-editor-popup-overlay') }
|
|
30
29
|
if (overlay) overlay.style.display = 'block'
|
|
31
30
|
stopMouseTracking()
|
|
32
31
|
|
|
@@ -63,7 +62,7 @@ export function initDragElement () {
|
|
|
63
62
|
if (overlay) overlay.style.display = 'none'
|
|
64
63
|
|
|
65
64
|
const ele = document.getElementById('i18next-editor-popup')
|
|
66
|
-
localStorage.setItem(
|
|
65
|
+
window.localStorage.setItem(
|
|
67
66
|
'locize_popup_pos',
|
|
68
67
|
JSON.stringify({
|
|
69
68
|
top: parseInt(document.defaultView.getComputedStyle(ele).top, 10),
|
|
@@ -119,8 +118,7 @@ export function initResizeElement () {
|
|
|
119
118
|
|
|
120
119
|
function initDrag (e) {
|
|
121
120
|
stopMouseTracking()
|
|
122
|
-
if (!overlay)
|
|
123
|
-
overlay = document.getElementById('i18next-editor-popup-overlay')
|
|
121
|
+
if (!overlay) { overlay = document.getElementById('i18next-editor-popup-overlay') }
|
|
124
122
|
if (overlay) overlay.style.display = 'block'
|
|
125
123
|
|
|
126
124
|
element = this.parentPopup
|
|
@@ -149,7 +147,7 @@ export function initResizeElement () {
|
|
|
149
147
|
if (overlay) overlay.style.display = 'none'
|
|
150
148
|
|
|
151
149
|
const ele = document.getElementById('i18next-editor-popup')
|
|
152
|
-
localStorage.setItem(
|
|
150
|
+
window.localStorage.setItem(
|
|
153
151
|
'locize_popup_size',
|
|
154
152
|
JSON.stringify({
|
|
155
153
|
width: parseInt(document.defaultView.getComputedStyle(ele).width, 10),
|
package/src/utils.js
CHANGED
|
@@ -72,8 +72,7 @@ export function getClickedElement (e) {
|
|
|
72
72
|
el = e.originalEvent.explicitOriginalTarget
|
|
73
73
|
} else {
|
|
74
74
|
const parent = e.srcElement
|
|
75
|
-
if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '')
|
|
76
|
-
return null
|
|
75
|
+
if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '') { return null }
|
|
77
76
|
|
|
78
77
|
const left = e.pageX
|
|
79
78
|
const top = e.pageY
|
|
@@ -93,13 +92,11 @@ export function getClickedElement (e) {
|
|
|
93
92
|
if (n.nodeType === 1 && nOffset.bottom < top) topStartsAt = i + 1
|
|
94
93
|
|
|
95
94
|
// if node is below top click set end index to this node
|
|
96
|
-
if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top)
|
|
97
|
-
topBreaksAt = i
|
|
95
|
+
if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top) { topBreaksAt = i }
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
// check we are inside children lenght
|
|
101
|
-
if (topStartsAt + 1 > parent.childNodes.length)
|
|
102
|
-
topStartsAt = parent.childNodes.length - 1
|
|
99
|
+
if (topStartsAt + 1 > parent.childNodes.length) { topStartsAt = parent.childNodes.length - 1 }
|
|
103
100
|
if (!topBreaksAt) topBreaksAt = parent.childNodes.length
|
|
104
101
|
// console.warn('bound', topStartsAt, topBreaksAt)
|
|
105
102
|
|
|
@@ -142,14 +139,14 @@ export function getElementI18nKey (el) {
|
|
|
142
139
|
function parseAttrFromKey (key) {
|
|
143
140
|
let attr = 'text'
|
|
144
141
|
|
|
145
|
-
if (key.indexOf('[')
|
|
146
|
-
|
|
142
|
+
if (key.indexOf('[') === 0) {
|
|
143
|
+
const parts = key.split(']')
|
|
147
144
|
key = parts[1]
|
|
148
145
|
attr = parts[0].substr(1, parts[0].length - 1)
|
|
149
146
|
}
|
|
150
147
|
|
|
151
148
|
const newKey =
|
|
152
|
-
key.indexOf(';')
|
|
149
|
+
key.indexOf(';') === key.length - 1 ? key.substr(0, key.length - 2) : key
|
|
153
150
|
|
|
154
151
|
return [newKey, attr]
|
|
155
152
|
}
|
|
@@ -161,8 +158,9 @@ export function getI18nMetaFromNode (el, hasNamespacePrependToKey = true) {
|
|
|
161
158
|
const allKeys = {}
|
|
162
159
|
|
|
163
160
|
if (key && key.indexOf(';') >= 0) {
|
|
164
|
-
|
|
165
|
-
for (let ix = 0,
|
|
161
|
+
const keys = key.split(';')
|
|
162
|
+
for (let ix = 0, lix = keys.length; ix < lix; ix++) {
|
|
163
|
+
// eslint-disable-next-line eqeqeq
|
|
166
164
|
if (keys[ix] != '') {
|
|
167
165
|
const [usedKey, attr] = parseAttrFromKey(keys[ix])
|
|
168
166
|
|
|
@@ -178,7 +176,7 @@ export function getI18nMetaFromNode (el, hasNamespacePrependToKey = true) {
|
|
|
178
176
|
if (Object.keys(allKeys).length < 1) return null
|
|
179
177
|
|
|
180
178
|
const res = Object.keys(allKeys).reduce((mem, attr) => {
|
|
181
|
-
|
|
179
|
+
const key = allKeys[attr]
|
|
182
180
|
let usedNS = ns
|
|
183
181
|
let usedKey = key
|
|
184
182
|
|
|
@@ -235,3 +233,11 @@ export function getQsParameterByName (name, url) {
|
|
|
235
233
|
if (!results[2]) return ''
|
|
236
234
|
return decodeURIComponent(results[2].replace(/\+/g, ' '))
|
|
237
235
|
}
|
|
236
|
+
|
|
237
|
+
let _isInIframe = typeof window !== 'undefined'
|
|
238
|
+
try {
|
|
239
|
+
// eslint-disable-next-line no-undef, no-restricted-globals
|
|
240
|
+
_isInIframe = self !== top
|
|
241
|
+
// eslint-disable-next-line no-empty
|
|
242
|
+
} catch (e) {}
|
|
243
|
+
export const isInIframe = _isInIframe
|
package/src/vars.js
CHANGED
|
@@ -15,6 +15,6 @@ export const getIframeUrl = () => {
|
|
|
15
15
|
return env === 'development'
|
|
16
16
|
? 'http://localhost:3003/'
|
|
17
17
|
: env === 'staging'
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
? 'https://incontext-dev.locize.app'
|
|
19
|
+
: 'https://incontext.locize.app'
|
|
20
20
|
}
|