aloha-vue 1.0.142 → 1.0.144
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/docs/src/components/TheNavbar/TheNavbar.js +5 -4
- package/package.json +1 -1
- package/src/ATranslation/ATranslation.js +69 -179
- package/src/ATranslation/compositionAPI/ATranslationAPI.js +30 -0
- package/src/ATranslation/compositionAPI/AriaLabelAPI.js +38 -0
- package/src/ATranslation/compositionAPI/AttributesAPI.js +58 -0
- package/src/ATranslation/compositionAPI/HtmlAPI.js +57 -0
- package/src/ATranslation/compositionAPI/PlaceholderAPI.js +38 -0
- package/src/ATranslation/compositionAPI/TextAPI.js +45 -0
- package/src/ATranslation/compositionAPI/TitleAPI.js +38 -0
- package/src/ATranslation/compositionAPI/UtilsAPI.js +67 -0
- package/src/compositionAPI/APageTabTitleAPI.js +10 -5
- package/src/plugins/AI18nPlugin.js +5 -4
- package/src/plugins/APageTabTitlePlugin.js +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import AIcon from "../../../../src/AIcon/AIcon";
|
|
2
2
|
import AMenuButtonToggle from "../../../../src/AMenu/AMenuButtonToggle";
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
setLanguage,
|
|
6
|
+
} from "../../../../src/ATranslation/compositionAPI/ATranslationAPI";
|
|
7
|
+
|
|
4
8
|
export default {
|
|
5
9
|
name: "TheNavbar",
|
|
6
10
|
components: {
|
|
@@ -30,13 +34,10 @@ export default {
|
|
|
30
34
|
],
|
|
31
35
|
};
|
|
32
36
|
},
|
|
33
|
-
created() {
|
|
34
|
-
this.changeLanguage();
|
|
35
|
-
},
|
|
36
37
|
methods: {
|
|
37
38
|
changeLanguage() {
|
|
38
39
|
setTimeout(() => {
|
|
39
|
-
this
|
|
40
|
+
setLanguage(this.modelLanguage);
|
|
40
41
|
});
|
|
41
42
|
},
|
|
42
43
|
},
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
h,
|
|
3
3
|
} from "vue";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
|
|
5
|
+
import AttributesAPI from "./compositionAPI/AttributesAPI";
|
|
6
|
+
import ATranslationAPI from "./compositionAPI/ATranslationAPI";
|
|
7
|
+
import HtmlAPI from "./compositionAPI/HtmlAPI";
|
|
8
|
+
import TextAPI from "./compositionAPI/TextAPI";
|
|
9
|
+
import TitleAPI from "./compositionAPI/TitleAPI";
|
|
10
|
+
import PlaceholderAPI from "./compositionAPI/PlaceholderAPI";
|
|
11
|
+
import AriaLabelAPI from "./compositionAPI/AriaLabelAPI";
|
|
9
12
|
|
|
10
13
|
export default {
|
|
11
14
|
name: "ATranslation",
|
|
@@ -50,180 +53,67 @@ export default {
|
|
|
50
53
|
default: "",
|
|
51
54
|
},
|
|
52
55
|
},
|
|
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
|
-
isTranslatePlaceholder() {
|
|
117
|
-
return !(!this.placeholder || !this.isPlaceholderTranslate(this.placeholder));
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
ariaLabelLocal() {
|
|
121
|
-
if (this.isTranslateAriaLabel) {
|
|
122
|
-
return this.getTranslatedText({
|
|
123
|
-
placeholder: this.ariaLabel,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return this.ariaLabel;
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
isTranslateAriaLabel() {
|
|
130
|
-
return !(!this.ariaLabel || !this.isPlaceholderTranslate(this.ariaLabel));
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
attributesLocal() {
|
|
134
|
-
const ATTRIBUTES = {};
|
|
135
|
-
if (this.isTranslateText) {
|
|
136
|
-
ATTRIBUTES["data-translate-text"] = this.text;
|
|
137
|
-
}
|
|
138
|
-
if (this.isTranslateHtml) {
|
|
139
|
-
ATTRIBUTES["data-translate-html"] = this.html;
|
|
140
|
-
}
|
|
141
|
-
if (this.html) {
|
|
142
|
-
ATTRIBUTES.innerHTML = this.htmlLocal;
|
|
143
|
-
}
|
|
144
|
-
if (this.title) {
|
|
145
|
-
ATTRIBUTES.title = this.titleLocal;
|
|
146
|
-
}
|
|
147
|
-
if (this.isTranslateTitle) {
|
|
148
|
-
ATTRIBUTES["data-translate-title"] = this.title;
|
|
149
|
-
}
|
|
150
|
-
if (this.placeholder) {
|
|
151
|
-
ATTRIBUTES.placeholder = this.placeholderLocal;
|
|
152
|
-
}
|
|
153
|
-
if (this.isTranslatePlaceholder) {
|
|
154
|
-
ATTRIBUTES["data-translate-placeholder"] = this.placeholder;
|
|
155
|
-
}
|
|
156
|
-
if (this.ariaLabel) {
|
|
157
|
-
ATTRIBUTES["aria-label"] = this.ariaLabelLocal;
|
|
158
|
-
}
|
|
159
|
-
if (this.isTranslateAriaLabel) {
|
|
160
|
-
ATTRIBUTES["data-translate-aria-label"] = this.ariaLabel;
|
|
161
|
-
}
|
|
162
|
-
return ATTRIBUTES;
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
translation() {
|
|
166
|
-
return this.i18n[this.$root.$i18n.language];
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
textLocalWithBeforeAndAfter() {
|
|
170
|
-
return `${ this.textBefore }${ this.textLocal }${ this.textAfter }`;
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
methods: {
|
|
174
|
-
isPlaceholderTranslate(text) {
|
|
175
|
-
return !(!isString(text) ||
|
|
176
|
-
text[0] !== "_" ||
|
|
177
|
-
text[text.length - 1] !== "_");
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
replaceText({ text = "", object }) {
|
|
181
|
-
if (!isPlainObject(object)) {
|
|
182
|
-
return text;
|
|
183
|
-
}
|
|
184
|
-
let textClone = text;
|
|
185
|
-
let searchIndexStart = 0;
|
|
186
|
-
while (true) {
|
|
187
|
-
const firstIndex = textClone.indexOf("{{", searchIndexStart);
|
|
188
|
-
const lastIndex = textClone.indexOf("}}", searchIndexStart);
|
|
189
|
-
|
|
190
|
-
if (firstIndex === -1 || lastIndex === -1) {
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const PATH = textClone.slice(firstIndex + 2, lastIndex).trim();
|
|
195
|
-
const valueFromObject = get(object, PATH);
|
|
196
|
-
|
|
197
|
-
textClone = this.spliceString({
|
|
198
|
-
text: textClone,
|
|
199
|
-
replaceText: valueFromObject,
|
|
200
|
-
firstIndex,
|
|
201
|
-
lastindex: lastIndex + 2,
|
|
202
|
-
});
|
|
203
|
-
searchIndexStart = firstIndex + `${ valueFromObject }`.length;
|
|
204
|
-
}
|
|
205
|
-
return textClone;
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
spliceString({
|
|
209
|
-
text = "",
|
|
210
|
-
replaceText = "",
|
|
211
|
-
firstIndex,
|
|
212
|
-
lastindex,
|
|
213
|
-
}) {
|
|
214
|
-
return `${ text.slice(0, firstIndex) }${ replaceText }${ text.slice(lastindex, text.length) }`;
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
getTranslatedText({ placeholder }) {
|
|
219
|
-
if (this.extra) {
|
|
220
|
-
return this.replaceText({
|
|
221
|
-
text: this.translation[placeholder],
|
|
222
|
-
object: this.extra,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return this.translation[placeholder];
|
|
226
|
-
},
|
|
56
|
+
setup(props) {
|
|
57
|
+
const {
|
|
58
|
+
translation,
|
|
59
|
+
} = ATranslationAPI();
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
htmlLocal,
|
|
63
|
+
isTranslateHtml,
|
|
64
|
+
} = HtmlAPI(props, {
|
|
65
|
+
translation,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
isTranslateText,
|
|
70
|
+
textLocal,
|
|
71
|
+
textLocalWithBeforeAndAfter,
|
|
72
|
+
} = TextAPI(props, {
|
|
73
|
+
translation,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
isTranslateTitle,
|
|
78
|
+
titleLocal,
|
|
79
|
+
} = TitleAPI(props, {
|
|
80
|
+
translation,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
isTranslatePlaceholder,
|
|
85
|
+
placeholderLocal,
|
|
86
|
+
} = PlaceholderAPI(props, {
|
|
87
|
+
translation,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const {
|
|
91
|
+
ariaLabelLocal,
|
|
92
|
+
isTranslateAriaLabel,
|
|
93
|
+
} = AriaLabelAPI(props, {
|
|
94
|
+
translation,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
attributesLocal,
|
|
99
|
+
} = AttributesAPI(props, {
|
|
100
|
+
ariaLabelLocal,
|
|
101
|
+
htmlLocal,
|
|
102
|
+
isTranslateAriaLabel,
|
|
103
|
+
isTranslateHtml,
|
|
104
|
+
isTranslatePlaceholder,
|
|
105
|
+
isTranslateText,
|
|
106
|
+
isTranslateTitle,
|
|
107
|
+
placeholderLocal,
|
|
108
|
+
titleLocal,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
attributesLocal,
|
|
113
|
+
htmlLocal,
|
|
114
|
+
textLocal,
|
|
115
|
+
textLocalWithBeforeAndAfter,
|
|
116
|
+
};
|
|
227
117
|
},
|
|
228
118
|
render() {
|
|
229
119
|
if (this.htmlLocal) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
ref,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const language = ref("de");
|
|
8
|
+
const i18n = ref({});
|
|
9
|
+
|
|
10
|
+
export default function ATranslationAPI() {
|
|
11
|
+
const translation = computed(() => {
|
|
12
|
+
return i18n.value[language.value];
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
i18n,
|
|
17
|
+
language,
|
|
18
|
+
setI18n,
|
|
19
|
+
setLanguage,
|
|
20
|
+
translation,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setI18n(i18nLocal = {}) {
|
|
25
|
+
i18n.value = i18nLocal;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function setLanguage(languageLocal = "") {
|
|
29
|
+
language.value = languageLocal;
|
|
30
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import UtilsAPI from "./UtilsAPI";
|
|
7
|
+
|
|
8
|
+
export default function AriaLabelAPI(props, {
|
|
9
|
+
translation = computed(() => ({})),
|
|
10
|
+
}) {
|
|
11
|
+
const ariaLabel = toRef(props, "ariaLabel");
|
|
12
|
+
const extra = toRef(props, "extra");
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
isPlaceholderTranslate,
|
|
16
|
+
getTranslatedText,
|
|
17
|
+
} = UtilsAPI();
|
|
18
|
+
|
|
19
|
+
const isTranslateAriaLabel = computed(() => {
|
|
20
|
+
return !(!ariaLabel.value || !isPlaceholderTranslate(ariaLabel.value));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const ariaLabelLocal = computed(() => {
|
|
24
|
+
if (isTranslateAriaLabel.value) {
|
|
25
|
+
return getTranslatedText({
|
|
26
|
+
placeholder: ariaLabel.value,
|
|
27
|
+
translationObj: translation.value,
|
|
28
|
+
extra: extra.value,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return ariaLabel.value;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
ariaLabelLocal,
|
|
36
|
+
isTranslateAriaLabel,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
export default function AttributesAPI(props, {
|
|
7
|
+
ariaLabelLocal = computed(() => ""),
|
|
8
|
+
htmlLocal = computed(() => ""),
|
|
9
|
+
isTranslateAriaLabel = computed(() => false),
|
|
10
|
+
isTranslateHtml = computed(() => false),
|
|
11
|
+
isTranslatePlaceholder = computed(() => false),
|
|
12
|
+
isTranslateText = computed(() => false),
|
|
13
|
+
isTranslateTitle = computed(() => false),
|
|
14
|
+
placeholderLocal = computed(() => ""),
|
|
15
|
+
titleLocal = computed(() => ""),
|
|
16
|
+
}) {
|
|
17
|
+
const ariaLabel = toRef(props, "ariaLabel");
|
|
18
|
+
const html = toRef(props, "html");
|
|
19
|
+
const placeholder = toRef(props, "placeholder");
|
|
20
|
+
const text = toRef(props, "text");
|
|
21
|
+
const title = toRef(props, "title");
|
|
22
|
+
|
|
23
|
+
const attributesLocal = computed(() => {
|
|
24
|
+
const ATTRIBUTES = {};
|
|
25
|
+
if (isTranslateText.value) {
|
|
26
|
+
ATTRIBUTES["data-translate-text"] = text.value;
|
|
27
|
+
}
|
|
28
|
+
if (isTranslateHtml.value) {
|
|
29
|
+
ATTRIBUTES["data-translate-html"] = html.value;
|
|
30
|
+
}
|
|
31
|
+
if (html.value) {
|
|
32
|
+
ATTRIBUTES.innerHTML = htmlLocal.value;
|
|
33
|
+
}
|
|
34
|
+
if (title.value) {
|
|
35
|
+
ATTRIBUTES.title = titleLocal.value;
|
|
36
|
+
}
|
|
37
|
+
if (isTranslateTitle.value) {
|
|
38
|
+
ATTRIBUTES["data-translate-title"] = title.value;
|
|
39
|
+
}
|
|
40
|
+
if (placeholder.value) {
|
|
41
|
+
ATTRIBUTES.placeholder = placeholderLocal.value;
|
|
42
|
+
}
|
|
43
|
+
if (isTranslatePlaceholder.value) {
|
|
44
|
+
ATTRIBUTES["data-translate-placeholder"] = placeholder.value;
|
|
45
|
+
}
|
|
46
|
+
if (ariaLabel.value) {
|
|
47
|
+
ATTRIBUTES["aria-label"] = ariaLabelLocal.value;
|
|
48
|
+
}
|
|
49
|
+
if (isTranslateAriaLabel.value) {
|
|
50
|
+
ATTRIBUTES["data-translate-aria-label"] = ariaLabel.value;
|
|
51
|
+
}
|
|
52
|
+
return ATTRIBUTES;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
attributesLocal,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import UtilsAPI from "./UtilsAPI";
|
|
7
|
+
|
|
8
|
+
export default function HtmlAPI(props, {
|
|
9
|
+
translation = computed(() => ({})),
|
|
10
|
+
}) {
|
|
11
|
+
const extra = toRef(props, "extra");
|
|
12
|
+
const html = toRef(props, "html");
|
|
13
|
+
const textAfter = toRef(props, "textAfter");
|
|
14
|
+
const textBefore = toRef(props, "textBefore");
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
isPlaceholderTranslate,
|
|
18
|
+
getTranslatedText,
|
|
19
|
+
} = UtilsAPI();
|
|
20
|
+
|
|
21
|
+
const isTranslateHtml = computed(() => {
|
|
22
|
+
return !(!html.value || !isPlaceholderTranslate(html.value));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const textBeforeHtml = computed(() => {
|
|
26
|
+
return textBefore.value ?
|
|
27
|
+
`<span>${ textBefore.value }</span>` :
|
|
28
|
+
"";
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const textAfterHtml = computed(() => {
|
|
32
|
+
return textAfter.value ?
|
|
33
|
+
`<span>${ textAfter.value }</span>` :
|
|
34
|
+
"";
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const htmlLocal = computed(() => {
|
|
38
|
+
if (!html.value) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
let htmlString = html.value;
|
|
42
|
+
|
|
43
|
+
if (isTranslateHtml.value) {
|
|
44
|
+
htmlString = getTranslatedText({
|
|
45
|
+
placeholder: html.value,
|
|
46
|
+
translationObj: translation.value,
|
|
47
|
+
extra: extra.value
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return `${ textBeforeHtml.value }${ htmlString }${ textAfterHtml.value }`;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
htmlLocal,
|
|
55
|
+
isTranslateHtml,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import UtilsAPI from "./UtilsAPI";
|
|
7
|
+
|
|
8
|
+
export default function PlaceholderAPI(props, {
|
|
9
|
+
translation = computed(() => ({})),
|
|
10
|
+
}) {
|
|
11
|
+
const extra = toRef(props, "extra");
|
|
12
|
+
const placeholder = toRef(props, "placeholder");
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
isPlaceholderTranslate,
|
|
16
|
+
getTranslatedText,
|
|
17
|
+
} = UtilsAPI();
|
|
18
|
+
|
|
19
|
+
const isTranslatePlaceholder = computed(() => {
|
|
20
|
+
return !(!placeholder.value || !isPlaceholderTranslate(placeholder.value));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const placeholderLocal = computed(() => {
|
|
24
|
+
if (isTranslatePlaceholder.value) {
|
|
25
|
+
return getTranslatedText({
|
|
26
|
+
placeholder: placeholder.value,
|
|
27
|
+
translationObj: translation.value,
|
|
28
|
+
extra: extra.value,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return placeholder.value;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
isTranslatePlaceholder,
|
|
36
|
+
placeholderLocal,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import UtilsAPI from "./UtilsAPI";
|
|
7
|
+
|
|
8
|
+
export default function TextAPI(props, {
|
|
9
|
+
translation = computed(() => ({})),
|
|
10
|
+
}) {
|
|
11
|
+
const extra = toRef(props, "extra");
|
|
12
|
+
const text = toRef(props, "text");
|
|
13
|
+
const textAfter = toRef(props, "textAfter");
|
|
14
|
+
const textBefore = toRef(props, "textBefore");
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
isPlaceholderTranslate,
|
|
18
|
+
getTranslatedText,
|
|
19
|
+
} = UtilsAPI();
|
|
20
|
+
|
|
21
|
+
const isTranslateText = computed(() => {
|
|
22
|
+
return !(!text.value || !isPlaceholderTranslate(text.value));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const textLocal = computed(() => {
|
|
26
|
+
if (isTranslateText.value) {
|
|
27
|
+
return getTranslatedText({
|
|
28
|
+
placeholder: text.value,
|
|
29
|
+
translationObj: translation.value,
|
|
30
|
+
extra: extra.value
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return text.value;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const textLocalWithBeforeAndAfter = computed(() => {
|
|
37
|
+
return `${ textBefore.value }${ textLocal.value }${ textAfter.value }`;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
isTranslateText,
|
|
42
|
+
textLocal,
|
|
43
|
+
textLocalWithBeforeAndAfter,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
toRef,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import UtilsAPI from "./UtilsAPI";
|
|
7
|
+
|
|
8
|
+
export default function TitleAPI(props, {
|
|
9
|
+
translation = computed(() => ({})),
|
|
10
|
+
}) {
|
|
11
|
+
const extra = toRef(props, "extra");
|
|
12
|
+
const title = toRef(props, "title");
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
isPlaceholderTranslate,
|
|
16
|
+
getTranslatedText,
|
|
17
|
+
} = UtilsAPI();
|
|
18
|
+
|
|
19
|
+
const isTranslateTitle = computed(() => {
|
|
20
|
+
return !(!title.value || !isPlaceholderTranslate(title.value));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const titleLocal = computed(() => {
|
|
24
|
+
if (isTranslateTitle.value) {
|
|
25
|
+
return getTranslatedText({
|
|
26
|
+
placeholder: title.value,
|
|
27
|
+
translationObj: translation.value,
|
|
28
|
+
extra: extra.value,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return title.value;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
isTranslateTitle,
|
|
36
|
+
titleLocal,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
get,
|
|
3
|
+
isPlainObject,
|
|
4
|
+
isString,
|
|
5
|
+
} from "lodash-es";
|
|
6
|
+
|
|
7
|
+
export default function UtilsAPI() {
|
|
8
|
+
const isPlaceholderTranslate = text => {
|
|
9
|
+
return !(!isString(text) ||
|
|
10
|
+
text[0] !== "_" ||
|
|
11
|
+
text[text.length - 1] !== "_");
|
|
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) }`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const replaceText = ({ text = "", object }) => {
|
|
24
|
+
if (!isPlainObject(object)) {
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
let textClone = text;
|
|
28
|
+
let searchIndexStart = 0;
|
|
29
|
+
while (true) {
|
|
30
|
+
const firstIndex = textClone.indexOf("{{", searchIndexStart);
|
|
31
|
+
const lastIndex = textClone.indexOf("}}", searchIndexStart);
|
|
32
|
+
|
|
33
|
+
if (firstIndex === -1 || lastIndex === -1) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const PATH = textClone.slice(firstIndex + 2, lastIndex).trim();
|
|
38
|
+
const valueFromObject = get(object, PATH);
|
|
39
|
+
|
|
40
|
+
textClone = spliceString({
|
|
41
|
+
text: textClone,
|
|
42
|
+
replaceText: valueFromObject,
|
|
43
|
+
firstIndex,
|
|
44
|
+
lastindex: lastIndex + 2,
|
|
45
|
+
});
|
|
46
|
+
searchIndexStart = firstIndex + `${ valueFromObject }`.length;
|
|
47
|
+
}
|
|
48
|
+
return textClone;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const getTranslatedText = ({ placeholder, translationObj, extra }) => {
|
|
52
|
+
if (extra) {
|
|
53
|
+
return replaceText({
|
|
54
|
+
text: translationObj[placeholder],
|
|
55
|
+
object: extra,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return translationObj[placeholder];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
getTranslatedText,
|
|
63
|
+
isPlaceholderTranslate,
|
|
64
|
+
replaceText,
|
|
65
|
+
spliceString,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -2,15 +2,20 @@ import {
|
|
|
2
2
|
ref, watch,
|
|
3
3
|
} from "vue";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const baseTitle = ref("");
|
|
6
6
|
|
|
7
7
|
export default function APageTabTitleAPI({
|
|
8
8
|
title = ref(""),
|
|
9
9
|
}) {
|
|
10
10
|
const setPageTabTitle = () => {
|
|
11
|
-
let pageTitle =
|
|
11
|
+
let pageTitle = "";
|
|
12
12
|
if (title.value) {
|
|
13
|
-
pageTitle =
|
|
13
|
+
pageTitle = title.value;
|
|
14
|
+
if (baseTitle.value) {
|
|
15
|
+
pageTitle += ` - ${ baseTitle.value }`;
|
|
16
|
+
}
|
|
17
|
+
} else if (baseTitle.value) {
|
|
18
|
+
pageTitle = baseTitle.value;
|
|
14
19
|
}
|
|
15
20
|
document.title = pageTitle;
|
|
16
21
|
};
|
|
@@ -22,6 +27,6 @@ export default function APageTabTitleAPI({
|
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
export function setBaseTitle(
|
|
26
|
-
|
|
30
|
+
export function setBaseTitle(baseTitleArg = "") {
|
|
31
|
+
baseTitle.value = baseTitleArg;
|
|
27
32
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
setI18n,
|
|
3
|
+
setLanguage,
|
|
4
|
+
} from "../ATranslation/compositionAPI/ATranslationAPI";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
6
7
|
install: (app, options, language) => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
setI18n(options);
|
|
9
|
+
setLanguage(language);
|
|
9
10
|
},
|
|
10
11
|
};
|