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
|
|
@ -3,6 +3,7 @@ import { getCollection, getEntry, type CollectionEntry, getEntries } from "astro
|
|||
import { marked, type RendererApi } from "marked";
|
||||
import { decode as tinyDecode } from "tiny-decode";
|
||||
import { type Lang, type Website } from "../../../content/config";
|
||||
import { t } from "../../../i18n";
|
||||
|
||||
type DescriptionFormat = "bbcode" | "markdown";
|
||||
|
||||
|
|
@ -196,9 +197,9 @@ function getLinkForUser(user: CollectionEntry<"users">, website: ExportWebsite):
|
|||
|
||||
function getNameForUser(user: CollectionEntry<"users">, anonymousUser: CollectionEntry<"users">, lang: Lang): string {
|
||||
if (user.data.isAnonymous) {
|
||||
return anonymousUser.data.nameLang[lang] || anonymousUser.data.name;
|
||||
return t(lang, anonymousUser.data.nameLang as any) || anonymousUser.data.name;
|
||||
}
|
||||
return user.data.nameLang[lang] || user.data.name;
|
||||
return t(lang, user.data.nameLang as any) || user.data.name;
|
||||
}
|
||||
|
||||
type Props = {
|
||||
|
|
@ -253,7 +254,7 @@ export const GET: APIRoute<Props, Params> = async ({ props: { story }, site }) =
|
|||
[
|
||||
story.data.description,
|
||||
`*Word count: ${story.data.wordCount}. ${story.data.contentWarning.trim()}*`,
|
||||
"Writing: " + (await getEntries([story.data.authors].flat())).map((author) => u(author)).join(" , "),
|
||||
"Writing: " + (await getEntries([story.data.authors].flat())).map((author) => u(author)).join(" "),
|
||||
story.data.requester && "Request for: " + u(await getEntry(story.data.requester)),
|
||||
story.data.commissioner && "Commissioned by: " + u(await getEntry(story.data.commissioner)),
|
||||
...(await Promise.all(
|
||||
|
|
@ -301,35 +302,11 @@ export const GET: APIRoute<Props, Params> = async ({ props: { story }, site }) =
|
|||
const commissioner = story.data.commissioner && (await getEntry(story.data.commissioner));
|
||||
const requester = story.data.requester && (await getEntry(story.data.requester));
|
||||
|
||||
let storyHeader = `${story.data.title}\n`;
|
||||
if (lang === "eng") {
|
||||
let authorsString = `by ${authorsNames[0]}`;
|
||||
if (authorsNames.length > 2) {
|
||||
authorsString += `, ${authorsNames.slice(1, authorsNames.length - 1).join(", ")}, and ${authorsNames[authorsNames.length - 1]}`;
|
||||
} else if (authorsNames.length == 2) {
|
||||
authorsString += ` and ${authorsNames[1]}`;
|
||||
}
|
||||
storyHeader +=
|
||||
`${authorsString}\n` +
|
||||
(commissioner ? `Commissioned by ${getNameForUser(commissioner, anonymousUser, lang)}\n` : "") +
|
||||
(requester ? `Requested by ${getNameForUser(requester, anonymousUser, lang)}\n` : "");
|
||||
} else if (lang === "tok") {
|
||||
let authorsString = "lipu ni li tan ";
|
||||
if (authorsNames.length > 1) {
|
||||
authorsString += `jan ni: ${authorsNames.join(" en ")}`;
|
||||
} else {
|
||||
authorsString += authorsNames[0];
|
||||
}
|
||||
if (commissioner) {
|
||||
throw new Error(`No "commissioner" handler for language "tok"`);
|
||||
}
|
||||
if (requester) {
|
||||
throw new Error(`No "requester" handler for language "tok"`);
|
||||
}
|
||||
storyHeader += `${authorsString}\n`;
|
||||
} else {
|
||||
throw new Error(`Unknown language "${lang}"`);
|
||||
}
|
||||
const storyHeader =
|
||||
`${story.data.title}\n` +
|
||||
`${t(lang, "story/authors", authorsNames)}\n` +
|
||||
(commissioner ? `${t(lang, "story/commissioned_by", getNameForUser(commissioner, anonymousUser, lang))}\n` : "") +
|
||||
(requester ? `${t(lang, "story/requested_by", getNameForUser(requester, anonymousUser, lang))}\n` : "");
|
||||
|
||||
const storyText = `${storyHeader}\n===\n\n${story.body.replaceAll("\\*", "*").replaceAll("\\=", "=")}`
|
||||
.replaceAll(/\n\n\n+/g, "\n\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue