Add i18n module and fix missing CopyrightedCharacters
This commit is contained in:
parent
7ca6f52cc2
commit
4f83ae8802
11 changed files with 270 additions and 196 deletions
|
|
@ -1,58 +1,15 @@
|
|||
---
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type Lang } from "../content/config";
|
||||
import UserComponent from "./UserComponent.astro";
|
||||
import { t } from "../i18n";
|
||||
|
||||
type Props = {
|
||||
authors: CollectionEntry<"users"> | CollectionEntry<"users">[];
|
||||
lang: Lang;
|
||||
};
|
||||
|
||||
const { authors, lang } = Astro.props;
|
||||
const authorsArray = [authors].flat();
|
||||
const { lang } = Astro.props;
|
||||
const authors = Astro.slots.has("default")
|
||||
? (await Astro.slots.render("default")).replaceAll(/\<\/(a|span)\>\</g, "</$1><br><")
|
||||
: "";
|
||||
---
|
||||
|
||||
{
|
||||
authorsArray.length > 0 ? (
|
||||
<p class="font-light">
|
||||
{lang === "eng" &&
|
||||
(authorsArray.length > 2 ? (
|
||||
<span>
|
||||
by{" "}
|
||||
{authorsArray.slice(0, authorsArray.length - 1).map((author) => (
|
||||
<Fragment>
|
||||
<UserComponent lang="eng" user={author} />,
|
||||
</Fragment>
|
||||
))}
|
||||
and <UserComponent lang="eng" user={authorsArray[authorsArray.length - 1]} />
|
||||
</span>
|
||||
) : authorsArray.length > 1 ? (
|
||||
<span>
|
||||
by <UserComponent lang="eng" user={authorsArray[0]} /> and{" "}
|
||||
<UserComponent lang="eng" user={authorsArray[1]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
by <UserComponent lang="eng" user={authorsArray[0]} />
|
||||
</span>
|
||||
))}
|
||||
{lang === "tok" &&
|
||||
(authorsArray.length > 1 ? (
|
||||
<span>
|
||||
lipu ni li tan jan ni:{" "}
|
||||
{authorsArray.slice(0, authorsArray.length - 1).map((author) => (
|
||||
<Fragment>
|
||||
<UserComponent lang="tok" user={author} />
|
||||
{" en "}
|
||||
</Fragment>
|
||||
))}
|
||||
<UserComponent lang="tok" user={authorsArray[authorsArray.length - 1]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
lipu ni li tan <UserComponent lang="tok" user={authorsArray[0]} />
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
) : null
|
||||
}
|
||||
{authors ? <p id="authors" set:html={t(lang, "story/authors", authors.split("<br>"))} /> : null}
|
||||
|
|
|
|||
|
|
@ -1,67 +1,34 @@
|
|||
---
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type Lang } from "../content/config";
|
||||
import { t } from "../i18n";
|
||||
import UserComponent from "./UserComponent.astro";
|
||||
import CopyrightedCharactersItem from "./CopyrightedCharactersItem.astro";
|
||||
|
||||
type Props = {
|
||||
copyrightedCharacters?: Record<string, CollectionEntry<"users">>;
|
||||
copyrightedCharacters?: Array<[CollectionEntry<"users">, string[]]>;
|
||||
lang: Lang;
|
||||
};
|
||||
|
||||
const { copyrightedCharacters, lang } = Astro.props;
|
||||
if (copyrightedCharacters && "" in copyrightedCharacters && Object.keys(copyrightedCharacters).length > 1) {
|
||||
throw new Error("copyrightedCharacter cannot use empty key (catch-all) with other keys");
|
||||
}
|
||||
const charactersPerUser =
|
||||
copyrightedCharacters &&
|
||||
Object.keys(copyrightedCharacters).reduce(
|
||||
(acc, character) => {
|
||||
const key = copyrightedCharacters[character].id;
|
||||
if (!(key in acc)) {
|
||||
acc[key] = [];
|
||||
}
|
||||
acc[key].push(character);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<
|
||||
CollectionEntry<"users">["id"],
|
||||
(typeof copyrightedCharacters extends Record<infer K, any> ? K : never)[]
|
||||
>,
|
||||
);
|
||||
---
|
||||
|
||||
{
|
||||
charactersPerUser ? (
|
||||
copyrightedCharacters ? (
|
||||
<section id="copyrighted-characters">
|
||||
{lang === "eng" ? (
|
||||
<ul>
|
||||
{Object.values(charactersPerUser).map((characterList) => (
|
||||
<li>
|
||||
{characterList[0] === "" ? (
|
||||
<span>
|
||||
All characters are © <UserComponent lang={lang} user={copyrightedCharacters[""]} />
|
||||
</span>
|
||||
) : characterList.length > 2 ? (
|
||||
<span>
|
||||
{characterList.slice(0, characterList.length - 1).join(", ")}, and{" "}
|
||||
{characterList[characterList.length - 1]} are ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
) : characterList.length > 1 ? (
|
||||
<span>
|
||||
{characterList[0]} and {characterList[1]} are ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{characterList[0]} is ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
<ul>
|
||||
{copyrightedCharacters.map(([owner, characterList]) => (
|
||||
<CopyrightedCharactersItem
|
||||
stringFunction={
|
||||
characterList[0] === ""
|
||||
? (user) => t(lang, "characters/all_characters_are_copyrighted_by", user)
|
||||
: (user) => t(lang, "characters/characters_are_copyrighted_by", user, characterList)
|
||||
}
|
||||
>
|
||||
<UserComponent lang={lang} user={owner} />
|
||||
</CopyrightedCharactersItem>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null
|
||||
}
|
||||
|
|
|
|||
10
src/components/CopyrightedCharactersItem.astro
Normal file
10
src/components/CopyrightedCharactersItem.astro
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
type Props = {
|
||||
stringFunction: (_: string) => string;
|
||||
};
|
||||
|
||||
const { stringFunction } = Astro.props;
|
||||
const owner = Astro.slots.has("default") ? await Astro.slots.render("default") : "";
|
||||
---
|
||||
|
||||
{owner ? <li set:html={stringFunction(owner)} /> : null}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type CollectionEntry, getEntry } from "astro:content";
|
||||
import { t } from "../i18n";
|
||||
import { type Lang } from "../content/config";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
type Props = {
|
||||
lang: Lang;
|
||||
|
|
@ -12,7 +12,7 @@ let { user, lang } = Astro.props;
|
|||
if (user.data.isAnonymous) {
|
||||
user = await getEntry("users", "anonymous");
|
||||
}
|
||||
const username = user.data.nameLang[lang] || user.data.name;
|
||||
const username = t(lang, user.data.nameLang as any) || user.data.name;
|
||||
let link: string | null = null;
|
||||
if (user.data.preferredLink) {
|
||||
if (user.data.preferredLink in user.data.links) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue