aloha-vue 1.0.144 → 1.0.145
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/package.json
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
toRef,
|
|
3
|
-
} from "vue";
|
|
4
|
-
|
|
5
1
|
import APageTabTitleAPI from "../compositionAPI/APageTabTitleAPI";
|
|
6
2
|
|
|
7
3
|
// @vue/component
|
|
@@ -12,11 +8,13 @@ export default {
|
|
|
12
8
|
type: String,
|
|
13
9
|
required: true,
|
|
14
10
|
},
|
|
11
|
+
extra: {
|
|
12
|
+
type: Object,
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
15
|
},
|
|
16
16
|
setup(props) {
|
|
17
|
-
APageTabTitleAPI(
|
|
18
|
-
title: toRef(props, "title"),
|
|
19
|
-
});
|
|
17
|
+
APageTabTitleAPI(props);
|
|
20
18
|
},
|
|
21
19
|
render() {
|
|
22
20
|
return "";
|
|
@@ -5,63 +5,63 @@ import {
|
|
|
5
5
|
} from "lodash-es";
|
|
6
6
|
|
|
7
7
|
export default function UtilsAPI() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const spliceString = ({
|
|
15
|
-
text = "",
|
|
16
|
-
replaceText = "",
|
|
17
|
-
firstIndex,
|
|
18
|
-
lastindex,
|
|
19
|
-
}) => {
|
|
20
|
-
return `${ text.slice(0, firstIndex) }${ replaceText }${ text.slice(lastindex, text.length) }`;
|
|
8
|
+
return {
|
|
9
|
+
getTranslatedText,
|
|
10
|
+
isPlaceholderTranslate,
|
|
11
|
+
replaceText,
|
|
12
|
+
spliceString,
|
|
21
13
|
};
|
|
14
|
+
}
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let searchIndexStart = 0;
|
|
29
|
-
while (true) {
|
|
30
|
-
const firstIndex = textClone.indexOf("{{", searchIndexStart);
|
|
31
|
-
const lastIndex = textClone.indexOf("}}", searchIndexStart);
|
|
16
|
+
export function isPlaceholderTranslate(text = "") {
|
|
17
|
+
return !(!isString(text) ||
|
|
18
|
+
text[0] !== "_" ||
|
|
19
|
+
text[text.length - 1] !== "_");
|
|
20
|
+
}
|
|
32
21
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
export function getTranslatedText({ placeholder, translationObj, extra }) {
|
|
23
|
+
if (extra) {
|
|
24
|
+
return replaceText({
|
|
25
|
+
text: translationObj[placeholder],
|
|
26
|
+
object: extra,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return translationObj[placeholder];
|
|
30
|
+
}
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
function replaceText({ text = "", object }) {
|
|
33
|
+
if (!isPlainObject(object)) {
|
|
34
|
+
return text;
|
|
35
|
+
}
|
|
36
|
+
let textClone = text;
|
|
37
|
+
let searchIndexStart = 0;
|
|
38
|
+
while (true) {
|
|
39
|
+
const firstIndex = textClone.indexOf("{{", searchIndexStart);
|
|
40
|
+
const lastIndex = textClone.indexOf("}}", searchIndexStart);
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
replaceText: valueFromObject,
|
|
43
|
-
firstIndex,
|
|
44
|
-
lastindex: lastIndex + 2,
|
|
45
|
-
});
|
|
46
|
-
searchIndexStart = firstIndex + `${ valueFromObject }`.length;
|
|
42
|
+
if (firstIndex === -1 || lastIndex === -1) {
|
|
43
|
+
break;
|
|
47
44
|
}
|
|
48
|
-
return textClone;
|
|
49
|
-
};
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return replaceText({
|
|
54
|
-
text: translationObj[placeholder],
|
|
55
|
-
object: extra,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return translationObj[placeholder];
|
|
59
|
-
};
|
|
46
|
+
const PATH = textClone.slice(firstIndex + 2, lastIndex).trim();
|
|
47
|
+
const valueFromObject = get(object, PATH);
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
textClone = spliceString({
|
|
50
|
+
text: textClone,
|
|
51
|
+
replaceText: valueFromObject,
|
|
52
|
+
firstIndex,
|
|
53
|
+
lastindex: lastIndex + 2,
|
|
54
|
+
});
|
|
55
|
+
searchIndexStart = firstIndex + `${ valueFromObject }`.length;
|
|
56
|
+
}
|
|
57
|
+
return textClone;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function spliceString({
|
|
61
|
+
text = "",
|
|
62
|
+
replaceText = "",
|
|
63
|
+
firstIndex,
|
|
64
|
+
lastindex,
|
|
65
|
+
}) {
|
|
66
|
+
return `${ text.slice(0, firstIndex) }${ replaceText }${ text.slice(lastindex, text.length) }`;
|
|
67
67
|
}
|
|
@@ -1,21 +1,57 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
computed,
|
|
3
|
+
ref,
|
|
4
|
+
toRef,
|
|
5
|
+
watch,
|
|
3
6
|
} from "vue";
|
|
4
7
|
|
|
8
|
+
import ATranslationAPI from "../ATranslation/compositionAPI/ATranslationAPI";
|
|
9
|
+
import UtilsAPI from "../ATranslation/compositionAPI/UtilsAPI";
|
|
10
|
+
|
|
5
11
|
const baseTitle = ref("");
|
|
6
12
|
|
|
7
|
-
export default function APageTabTitleAPI({
|
|
8
|
-
title =
|
|
9
|
-
|
|
13
|
+
export default function APageTabTitleAPI(props) {
|
|
14
|
+
const title = toRef(props, "title");
|
|
15
|
+
const extra = toRef(props, "extra");
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
translation,
|
|
19
|
+
} = ATranslationAPI();
|
|
20
|
+
const {
|
|
21
|
+
isPlaceholderTranslate,
|
|
22
|
+
getTranslatedText,
|
|
23
|
+
} = UtilsAPI();
|
|
24
|
+
|
|
25
|
+
const baseTitleTranslated = computed(() => {
|
|
26
|
+
if (isPlaceholderTranslate(baseTitle.value)) {
|
|
27
|
+
return getTranslatedText({
|
|
28
|
+
placeholder: baseTitle.value,
|
|
29
|
+
translationObj: translation.value,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return baseTitle.value;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const titleTranslated = computed(() => {
|
|
36
|
+
if (isPlaceholderTranslate(title.value)) {
|
|
37
|
+
return getTranslatedText({
|
|
38
|
+
placeholder: title.value,
|
|
39
|
+
translationObj: translation.value,
|
|
40
|
+
extra: extra.value,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return title.value;
|
|
44
|
+
});
|
|
45
|
+
|
|
10
46
|
const setPageTabTitle = () => {
|
|
11
47
|
let pageTitle = "";
|
|
12
|
-
if (
|
|
13
|
-
pageTitle =
|
|
14
|
-
if (
|
|
15
|
-
pageTitle += ` - ${
|
|
48
|
+
if (titleTranslated.value) {
|
|
49
|
+
pageTitle = titleTranslated.value;
|
|
50
|
+
if (baseTitleTranslated.value) {
|
|
51
|
+
pageTitle += ` - ${ baseTitleTranslated.value }`;
|
|
16
52
|
}
|
|
17
|
-
} else if (
|
|
18
|
-
pageTitle =
|
|
53
|
+
} else if (baseTitleTranslated.value) {
|
|
54
|
+
pageTitle = baseTitleTranslated.value;
|
|
19
55
|
}
|
|
20
56
|
document.title = pageTitle;
|
|
21
57
|
};
|