Skip to content

Commit

Permalink
Merge pull request #404 from auroral-ui/397-friends-description-shoul…
Browse files Browse the repository at this point in the history
…d-hide-if-not-using-default-labels

397 fix: custom link label trying to localize
  • Loading branch information
bennyxguo authored Nov 1, 2023
2 parents eb8c641 + 10c4a5b commit 712c486
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/components/Link/LinkCategoryList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<template v-if="links">
<template v-for="category in Object.keys(links)" :key="category">
<MainTitle
:title="convertToLocale(category)"
:title="localizeLink(category)"
:count="links[category].length"
margins="mb-2"
:uppercase="false"
/>
<span class="text-ob-dim mb-8 text-lg">
{{ t(`${convertToLocale(category)}-desc`) }}
{{ t(`${localizeLink(category + '-desc')}`) }}
</span>
<ul :class="linkWrapperClasses(category)">
<template v-for="[i, link] of links[category].entries()" :key="i">
Expand All @@ -17,7 +17,7 @@
:link="link.link"
:avatar="link.avatar"
:description="link.description"
:type="convertToLocale(link.label)"
:type="localizeLink(link.label)"
:vip="link.label === 'links-badge-vip'"
:category-mode="true"
/>
Expand All @@ -32,7 +32,7 @@ import { Link } from '@/models/Article.class'
import { PropType, defineComponent } from 'vue'
import LinkCard from './LinkCard.vue'
import { MainTitle } from '../Title'
import { convertToLocale } from '@/utils'
import { localizeLink } from '@/utils/localization'
import { useI18n } from 'vue-i18n'
export default defineComponent({
Expand All @@ -55,7 +55,7 @@ export default defineComponent({
'xl:grid-cols-4': category === 'links-badge-vip'
}
},
convertToLocale,
localizeLink,
t
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Link/LinkList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:link="link.link"
:avatar="link.avatar"
:description="link.description"
:type="convertToLocale(link.label)"
:type="localizeLink(link.label)"
:vip="link.label === 'links-badge-vip'"
/>
</template>
Expand All @@ -24,7 +24,7 @@
<script lang="ts">
import { Link } from '@/models/Article.class'
import { PropType, defineComponent } from 'vue'
import { convertToLocale } from '@/utils'
import { localizeLink } from '@/utils/localization'
import { SubTitle } from '../Title'
export default defineComponent({
Expand All @@ -38,7 +38,7 @@ export default defineComponent({
}
},
setup() {
return { convertToLocale }
return { localizeLink }
}
})
</script>
15 changes: 0 additions & 15 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,6 @@ export function getDaysTillNow(from: string) {
return Math.floor(timeDiff / (1000 * 3600 * 24))
}

export function convertToLocale(label: string) {
const locales = [
'links-badge-tech',
'links-badge-designer',
'links-badge-vip',
'links-badge-personal'
]

if (locales.includes(label)) {
return `settings.${label}`
}

return label
}

export function cleanPath(path: string) {
if (path !== '/' && path.at(-1) === '/') {
return path.slice(0, -1)
Expand Down
14 changes: 14 additions & 0 deletions src/utils/localization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const SUPPORTED_LINK_LOCALES = [
'links-badge-tech',
'links-badge-designer',
'links-badge-vip',
'links-badge-personal'
]

export function localizeLink(label: string) {
if (SUPPORTED_LINK_LOCALES.includes(label.replace('-desc', ''))) {
return `settings.${label}`
}

return label.match('-desc') ? '' : label
}

0 comments on commit 712c486

Please sign in to comment.