Skip to content

Commit

Permalink
i18n: localize post badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyphyn committed Jun 3, 2024
1 parent 0f0e34d commit f9935ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
35 changes: 24 additions & 11 deletions src/lib/components/lemmy/post/PostMeta.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { userSettings } from '$lib/settings'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from '$lib/translations'
export let community: Community | undefined = undefined
export let subscribed: SubscribedType | undefined = undefined
Expand Down Expand Up @@ -113,36 +114,48 @@
style="grid-area: badges;"
>
{#if badges.nsfw}
<Badge color="red-subtle">NSFW</Badge>
<Badge color="red-subtle">{$t('post.badges.nsfw')}</Badge>
{/if}
{#if badges.saved}
<Badge label="Saved" color="yellow-subtle" allowIconOnly>
<Badge
label={$t('post.badges.saved')}
color="yellow-subtle"
allowIconOnly
>
<Icon src={Bookmark} mini size="12" slot="icon" />
Saved
{$t('post.badges.saved')}
</Badge>
{/if}
{#if badges.locked}
<Badge label="Locked" color="yellow-subtle" allowIconOnly>
<Badge
label={$t('post.badges.locked')}
color="yellow-subtle"
allowIconOnly
>
<Icon src={LockClosed} mini size="14" slot="icon" />
<span class="max-md:hidden">Locked</span>
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
</Badge>
{/if}
{#if badges.removed}
<Badge label="Removed" color="red-subtle" allowIconOnly>
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
<Icon src={Trash} mini size="14" slot="icon" />
<span class="max-md:hidden">Removed</span>
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
</Badge>
{/if}
{#if badges.deleted}
<Badge label="Deleted" color="red-subtle" allowIconOnly>
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
<Icon src={Trash} mini size="14" slot="icon" />
<span class="max-md:hidden">Deleted</span>
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
</Badge>
{/if}
{#if badges.featured}
<Badge label="Featured" color="green-subtle" allowIconOnly>
<Badge
label={$t('post.badges.featured')}
color="green-subtle"
allowIconOnly
>
<Icon src={Megaphone} mini size="14" slot="icon" />
<span class="max-md:hidden">Featured</span>
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
</Badge>
{/if}
<slot name="badges" />
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/util/RelativeDate.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { locale } from '$lib/translations'
export let date: Date
export let relativeTo: Date | undefined = undefined
export let options: Intl.RelativeTimeFormatOptions = {
Expand Down Expand Up @@ -36,7 +38,7 @@
if (diffInMillis >= thresholds[i].threshold) {
const value = Math.round(diffInMillis / thresholds[i].threshold)
let language = 'en'
let language = $locale
if (typeof navigator != 'undefined') {
language = navigator.language
}
Expand Down
10 changes: 9 additions & 1 deletion src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
"delete": "Delete",
"restore": "Restore"
}
},
"badges": {
"nsfw": "NSFW",
"locked": "Locked",
"featured": "Featured",
"removed": "Removed",
"deleted": "Deleted",
"saved": "Saved"
}
},
"moderation": {
Expand All @@ -139,4 +147,4 @@
"back": "Back",
"next": "Next"
}
}
}
8 changes: 8 additions & 0 deletions src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
"delete": "Supprimer",
"restore": "Restaurer"
}
},
"badges": {
"nsfw": "NSFW",
"locked": "Verrouillé",
"featured": "En vedette",
"removed": "Supprimé",
"deleted": "Supprimé",
"saved": "Enregistré"
}
},
"moderation": {
Expand Down

0 comments on commit f9935ce

Please sign in to comment.