i18n: localize posts
This commit is contained in:
1 parent
64107e51a0
commit
c4236fa124
9 files changed
+110
-31
No files matched your search
@@ -49,6 +49,7 @@
|
|||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import { fediseer, type Data } from '$lib/fediseer/fediseer'
|
import { fediseer, type Data } from '$lib/fediseer/fediseer'
|
||||||
import Fediseer from '$lib/fediseer/Fediseer.svelte'
|
import Fediseer from '$lib/fediseer/Fediseer.svelte'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@
|
|||||||
href="/post/{getInstance()}/{post.post.id}"
|
href="/post/{getInstance()}/{post.post.id}"
|
||||||
class="!text-inherit h-8 px-3"
|
class="!text-inherit h-8 px-3"
|
||||||
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
|
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
|
||||||
title="Comments"
|
title={$t('post.actions.comments')}
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" src={ChatBubbleOvalLeft} mini size="14" />
|
<Icon slot="prefix" src={ChatBubbleOvalLeft} mini size="14" />
|
||||||
<FormattedNumber number={post.counts.comments} />
|
<FormattedNumber number={post.counts.comments} />
|
||||||
@@ -123,7 +124,12 @@
|
|||||||
<DebugObject object={post} bind:open={debug} />
|
<DebugObject object={post} bind:open={debug} />
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
<Button on:click={() => (debug = true)} size="square-md" color="ghost">
|
<Button
|
||||||
|
on:click={() => (debug = true)}
|
||||||
|
title="Debug"
|
||||||
|
size="square-md"
|
||||||
|
color="ghost"
|
||||||
|
>
|
||||||
<Icon src={BugAnt} mini size="16" slot="prefix" />
|
<Icon src={BugAnt} mini size="16" slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -143,7 +149,7 @@
|
|||||||
color="ghost"
|
color="ghost"
|
||||||
loading={saving}
|
loading={saving}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
title={post.saved ? 'Unsave' : 'Save'}
|
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
src={post.saved ? BookmarkSlash : Bookmark}
|
src={post.saved ? BookmarkSlash : Bookmark}
|
||||||
@@ -159,12 +165,17 @@
|
|||||||
containerClass="overflow-auto max-h-[400px]"
|
containerClass="overflow-auto max-h-[400px]"
|
||||||
class="h-8"
|
class="h-8"
|
||||||
targetClass="h-full"
|
targetClass="h-full"
|
||||||
title="Post actions"
|
title={$t('post.actions.more.label')}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
slot="target"
|
||||||
|
title={$t('post.actions.more.label')}
|
||||||
|
color="ghost"
|
||||||
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Button slot="target" title="Post actions" color="ghost" size="square-md">
|
|
||||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} mini />
|
<Icon slot="prefix" src={EllipsisHorizontal} width={16} mini />
|
||||||
</Button>
|
</Button>
|
||||||
<MenuDivider>Creator</MenuDivider>
|
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
link
|
link
|
||||||
href="/u/{post.creator.name}@{new URL(post.creator.actor_id).hostname}"
|
href="/u/{post.creator.name}@{new URL(post.creator.actor_id).hostname}"
|
||||||
@@ -189,7 +200,6 @@
|
|||||||
const data = await fediseer.getInstanceInfo(
|
const data = await fediseer.getInstanceInfo(
|
||||||
new URL(post.community.actor_id).hostname
|
new URL(post.community.actor_id).hostname
|
||||||
)
|
)
|
||||||
console.log(data)
|
|
||||||
fediseerData = data
|
fediseerData = data
|
||||||
fediseerOpen = true
|
fediseerOpen = true
|
||||||
fediseerLoading = false
|
fediseerLoading = false
|
||||||
@@ -207,11 +217,11 @@
|
|||||||
<span>{new URL(post.community.actor_id).hostname}</span>
|
<span>{new URL(post.community.actor_id).hostname}</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
||||||
<MenuDivider>Actions</MenuDivider>
|
<MenuDivider>{$t('post.actions.more.actions')}</MenuDivider>
|
||||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
||||||
<MenuButton on:click={() => (editing = true)}>
|
<MenuButton on:click={() => (editing = true)}>
|
||||||
<Icon src={PencilSquare} width={16} mini slot="prefix" />
|
<Icon src={PencilSquare} width={16} mini slot="prefix" />
|
||||||
Edit
|
{$t('post.actions.more.edit')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.jwt}
|
{#if $profile?.jwt}
|
||||||
@@ -222,7 +232,9 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} width={16} mini />
|
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} width={16} mini />
|
||||||
Mark as {post.read ? 'Unread' : 'Read'}
|
{post.read
|
||||||
|
? $t('post.actions.more.markUnread')
|
||||||
|
: $t('post.actions.more.markRead')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
@@ -233,7 +245,7 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={Share} width={16} mini slot="prefix" />
|
<Icon src={Share} width={16} mini slot="prefix" />
|
||||||
Share
|
{$t('post.actions.more.share')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.jwt}
|
{#if $profile?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
@@ -260,7 +272,7 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={ArrowTopRightOnSquare} width={16} mini slot="prefix" />
|
<Icon src={ArrowTopRightOnSquare} width={16} mini slot="prefix" />
|
||||||
Crosspost
|
{$t('post.actions.more.crosspost')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
@@ -275,13 +287,15 @@
|
|||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
>
|
>
|
||||||
<Icon src={Trash} width={16} mini slot="prefix" />
|
<Icon src={Trash} width={16} mini slot="prefix" />
|
||||||
{post.post.deleted ? 'Restore' : 'Delete'}
|
{post.post.deleted
|
||||||
|
? $t('post.actions.more.restore')
|
||||||
|
: $t('post.actions.more.delete')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
||||||
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
||||||
<Icon src={Flag} width={16} mini slot="prefix" />
|
<Icon src={Flag} width={16} mini slot="prefix" />
|
||||||
Report
|
{$t('moderation.report')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { t } from '$lib/translations'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import {
|
import {
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
class={$$slots.default ? '' : 'flex-1'}
|
class={$$slots.default ? '' : 'flex-1'}
|
||||||
>
|
>
|
||||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
||||||
Back
|
{$t('common.back')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
}}
|
}}
|
||||||
class={$$slots.default ? '' : 'flex-1'}
|
class={$$slots.default ? '' : 'flex-1'}
|
||||||
>
|
>
|
||||||
Next
|
{$t('common.next')}
|
||||||
<Icon src={ChevronRight} size="18" mini slot="suffix" />
|
<Icon src={ChevronRight} size="18" mini slot="suffix" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { locale } from '$lib/translations'
|
||||||
|
|
||||||
export let number: number
|
export let number: number
|
||||||
export let locale: string = 'en'
|
let localeToUse: string = $locale
|
||||||
export let options: Intl.NumberFormatOptions = {
|
export let options: Intl.NumberFormatOptions = {
|
||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { localeToUse as locale }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<span class={$$props.class ?? ''}>
|
<span class={$$props.class ?? ''}>
|
||||||
{Intl.NumberFormat(locale, options).format(number)}
|
{Intl.NumberFormat(localeToUse, options).format(number)}
|
||||||
</span>
|
</span>
|
||||||
+30
-1
@@ -93,7 +93,10 @@
|
|||||||
"submit": "Submit"
|
"submit": "Submit"
|
||||||
},
|
},
|
||||||
"routes": {
|
"routes": {
|
||||||
"frontpage": "Frontpage",
|
"frontpage": {
|
||||||
|
"title": "Frontpage",
|
||||||
|
"footer": "{{users:number}} active {{users; 1:user; default:users;}}"
|
||||||
|
},
|
||||||
"modlog": "Modlog",
|
"modlog": "Modlog",
|
||||||
"instances": "Instances",
|
"instances": "Instances",
|
||||||
"legal": "Legal"
|
"legal": "Legal"
|
||||||
@@ -109,5 +112,31 @@
|
|||||||
"users": "Users",
|
"users": "Users",
|
||||||
"posts": "Posts",
|
"posts": "Posts",
|
||||||
"communities": "Communities"
|
"communities": "Communities"
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"actions": {
|
||||||
|
"comments": "Comments",
|
||||||
|
"save": "Save",
|
||||||
|
"unsave": "Unsave",
|
||||||
|
"more": {
|
||||||
|
"label": "More Actions",
|
||||||
|
"edit": "Edit",
|
||||||
|
"creator": "Creator",
|
||||||
|
"actions": "Actions",
|
||||||
|
"markRead": "Mark as Read",
|
||||||
|
"markUnread": "Mark as Unread",
|
||||||
|
"share": "Share",
|
||||||
|
"crosspost": "Crosspost",
|
||||||
|
"delete": "Delete",
|
||||||
|
"restore": "Restore"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"moderation": {
|
||||||
|
"report": "Report"
|
||||||
|
},
|
||||||
|
"common": {
|
||||||
|
"back": "Back",
|
||||||
|
"next": "Next"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-3
@@ -77,6 +77,7 @@ interface Settings {
|
|||||||
deduplicateEmbed: boolean
|
deduplicateEmbed: boolean
|
||||||
compactFeatured: boolean
|
compactFeatured: boolean
|
||||||
}
|
}
|
||||||
|
language: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultSettings: Settings = {
|
export const defaultSettings: Settings = {
|
||||||
@@ -128,12 +129,13 @@ export const defaultSettings: Settings = {
|
|||||||
},
|
},
|
||||||
dock: {
|
dock: {
|
||||||
noGap: toBool(env.PUBLIC_DOCK_PANEL) ?? null,
|
noGap: toBool(env.PUBLIC_DOCK_PANEL) ?? null,
|
||||||
top: toBool(env.PUBLIC_DOCK_TOP) ?? null
|
top: toBool(env.PUBLIC_DOCK_TOP) ?? null,
|
||||||
},
|
},
|
||||||
posts: {
|
posts: {
|
||||||
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
|
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
|
||||||
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true
|
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
||||||
}
|
},
|
||||||
|
language: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userSettings = writable(defaultSettings)
|
export const userSettings = writable(defaultSettings)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const config: Config = {
|
|||||||
loader: async () => (await import('./i18n/en.json')).default,
|
loader: async () => (await import('./i18n/en.json')).default,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
fallbackLocale: 'en',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const { t, locale, locales, loading, loadTranslations } = new i18n(
|
export const { t, locale, locales, loading, loadTranslations } = new i18n(
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { loadTranslations } from '$lib/translations.js'
|
import { loadTranslations } from '$lib/translations.js'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export let ssr = (env.PUBLIC_SSR_ENABLED?.toLowerCase() ?? 'false') == 'true'
|
export let ssr = (env.PUBLIC_SSR_ENABLED?.toLowerCase() ?? 'false') == 'true'
|
||||||
|
|
||||||
export const load = async ({ url }) => {
|
export const load = async ({}) => {
|
||||||
await loadTranslations('en')
|
const initLocale = get(userSettings)?.language ?? navigator?.language ?? 'en'
|
||||||
|
|
||||||
|
console.log(`Loading locale ${initLocale}`)
|
||||||
|
|
||||||
|
await loadTranslations(initLocale)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||||
<header>
|
<header>
|
||||||
<Header>{$t('routes.frontpage')}</Header>
|
<Header>{$t('routes.frontpage.title')}</Header>
|
||||||
</header>
|
</header>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Location changeDefault selected={data.listingType} />
|
<Location changeDefault selected={data.listingType} />
|
||||||
@@ -45,11 +45,9 @@
|
|||||||
>
|
>
|
||||||
<span class="flex flex-row items-center gap-1">
|
<span class="flex flex-row items-center gap-1">
|
||||||
<Icon src={ChartBar} size="16" mini />
|
<Icon src={ChartBar} size="16" mini />
|
||||||
<FormattedNumber
|
{$t('routes.frontpage.footer', {
|
||||||
number={$site?.site_view.counts.users_active_day ?? 0}
|
users: $site?.site_view.counts.users_active_day ?? '??',
|
||||||
class="text-black dark:text-white font-medium"
|
})}
|
||||||
/>
|
|
||||||
<span class="font-normal">active users</span>
|
|
||||||
</span>
|
</span>
|
||||||
</Pageination>
|
</Pageination>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,14 @@
|
|||||||
import Setting from './Setting.svelte'
|
import Setting from './Setting.svelte'
|
||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
import { Disclosure, Material, Switch, TextInput, toast } from 'mono-svelte'
|
import {
|
||||||
|
Disclosure,
|
||||||
|
Material,
|
||||||
|
Note,
|
||||||
|
Switch,
|
||||||
|
TextInput,
|
||||||
|
toast,
|
||||||
|
} from 'mono-svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import {
|
import {
|
||||||
@@ -25,6 +32,7 @@
|
|||||||
import { removeItem } from '$lib/util.js'
|
import { removeItem } from '$lib/util.js'
|
||||||
import Section from './Section.svelte'
|
import Section from './Section.svelte'
|
||||||
import ToggleSetting from './ToggleSetting.svelte'
|
import ToggleSetting from './ToggleSetting.svelte'
|
||||||
|
import { locales } from '$lib/translations'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -90,6 +98,22 @@
|
|||||||
Go to themes <Icon src={ArrowRight} size="16" mini slot="suffix" />
|
Go to themes <Icon src={ArrowRight} size="16" mini slot="suffix" />
|
||||||
</Button>
|
</Button>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting>
|
||||||
|
<span slot="title">Language</span>
|
||||||
|
<p slot="description">
|
||||||
|
The language used for Photon's UI.
|
||||||
|
<Note>
|
||||||
|
All languages other than US English are community translated, and may
|
||||||
|
be incomplete!
|
||||||
|
</Note>
|
||||||
|
</p>
|
||||||
|
<Select bind:value={$userSettings.language}>
|
||||||
|
<option value={null}>Auto-Detect</option>
|
||||||
|
{#each $locales as locale}
|
||||||
|
<option value={locale}>{locale}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</Setting>
|
||||||
<Setting>
|
<Setting>
|
||||||
<span slot="title">Post style</span>
|
<span slot="title">Post style</span>
|
||||||
<ViewSelect showLabel={false} />
|
<ViewSelect showLabel={false} />
|
||||||
|
|||||||
Reference in new issue
Block a user