|
4 | 4 | export function useViewOnGitProvider( |
5 | 5 | provider: MaybeRefOrGetter<ProviderId | (string & {}) | null | undefined>, |
6 | 6 | ) { |
7 | | - const { t } = useI18n() |
| 7 | + const { t, te } = useI18n() |
8 | 8 | return computed(() => { |
9 | 9 | const uProvider = toValue(provider) |
10 | | - // using this switch instead of `view_on.${provider}` to prevent missing future translations |
11 | | - switch (uProvider) { |
12 | | - case 'github': |
13 | | - return t('common.view_on.github') |
14 | | - case 'gitlab': |
15 | | - return t('common.view_on.gitlab') |
16 | | - case 'bitbucket': |
17 | | - return t('common.view_on.bitbucket') |
18 | | - case 'codeberg': |
19 | | - return t('common.view_on.codeberg') |
20 | | - case 'forgejo': |
21 | | - return t('common.view_on.forgejo') |
22 | | - case 'gitea': |
23 | | - return t('common.view_on.gitea') |
24 | | - case 'gitee': |
25 | | - return t('common.view_on.gitee') |
26 | | - case 'radicle': |
27 | | - return t('common.view_on.radicle') |
28 | | - case 'sourcehut': |
29 | | - return t('common.view_on.sourcehut') |
30 | | - case 'tangled': |
31 | | - return t('common.view_on.tangled') |
| 10 | + if (!uProvider) { |
| 11 | + return t('common.view_on.git_repo') |
32 | 12 | } |
| 13 | + const key = `common.view_on.${uProvider}` |
| 14 | + if (te(key)) { |
| 15 | + return t(key) |
| 16 | + } |
| 17 | + // oxlint-disable-next-line no-console |
| 18 | + console.warn(`"common.view_on.${uProvider}" translation doesn't exist`) |
33 | 19 | return t('common.view_on.git_repo') |
34 | 20 | }) |
35 | 21 | } |
| 22 | + |
| 23 | +/* for i18n report, translations that are currently present: |
| 24 | +t('common.view_on.github') |
| 25 | +t('common.view_on.gitlab') |
| 26 | +t('common.view_on.bitbucket') |
| 27 | +t('common.view_on.codeberg') |
| 28 | +t('common.view_on.forgejo') |
| 29 | +t('common.view_on.gitea') |
| 30 | +t('common.view_on.gitee') |
| 31 | +t('common.view_on.radicle') |
| 32 | +t('common.view_on.sourcehut') |
| 33 | +t('common.view_on.tangled') |
| 34 | + */ |
0 commit comments