-
Notifications
You must be signed in to change notification settings - Fork 2
/
I18nTip.vue
78 lines (73 loc) · 2 KB
/
I18nTip.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
<script setup lang="ts">
import type {
I18nData,
I18nPluginLocaleData,
LinkRenderer,
} from "../../shared/types";
import { computed } from "vue";
import { isAbsoluteUrl } from "vuepress-shared/client";
import { useI18nData } from "../composables";
type I18nPluginTipType = "untranslated" | "outdated";
const linkRenderer: LinkRenderer = (text, url) =>
`<a href="${url}"${isAbsoluteUrl(url) ? ` target="_blank"` : ""}>${text}</a>`;
const getContent = (
type: I18nPluginTipType,
locale: I18nPluginLocaleData,
i18nData: I18nData,
) => {
switch (type) {
case "untranslated":
return locale.untranslated.content(
linkRenderer,
i18nData.translationGuide,
);
case "outdated":
if (
!i18nData.updatedTime ||
!i18nData.sourceUpdatedTime ||
!i18nData.sourceLink
) {
return null;
} else {
return locale.outdated.content(
linkRenderer,
i18nData.sourceUpdatedTime,
i18nData.updatedTime,
i18nData.sourceLink,
);
}
default:
return null;
}
};
const i18nData = useI18nData();
const { containerClass, titleClass } = i18nData.value.options;
const locale = computed(() => i18nData.value.locale);
const showTips = computed(
() => i18nData.value.isUntranslated || i18nData.value.isOutdated,
);
const tipType = computed(() =>
i18nData.value.isUntranslated ? "untranslated" : "outdated",
);
const containerType = computed(() =>
tipType.value === "untranslated" ? "tip" : "warning",
);
const containerTitle = computed(() => locale.value[tipType.value].title);
const containerContent = computed(() =>
showTips.value
? getContent(tipType.value, locale.value, i18nData.value)
: null,
);
</script>
<template>
<div
v-if="showTips && containerContent"
:class="[...containerClass, containerType]"
>
<p :class="titleClass">
{{ containerTitle }}
</p>
<!--eslint-disable-next-line vue/no-v-html -->
<p v-html="containerContent"></p>
</div>
</template>