Display source language for pages

This commit is contained in:
DrMint 2024-05-11 17:26:51 +02:00
parent 2fe38c38e1
commit cb3ba888dd
3 changed files with 33 additions and 30 deletions

13
TODO.md
View File

@ -6,27 +6,28 @@
- Create a tool to upload scans images and apply them to collectible - Create a tool to upload scans images and apply them to collectible
- Automatically generate different sizes of images - Automatically generate different sizes of images
- Handle relationship in RichText Content - Handle relationship in RichText Content
- Add proper localization for formatFilesize, formatInches, formatMillimeters, formatPounds, and formatGrams
## Mid term ## Mid term
- [Medias] Add Parent pages
- [Scans] Adapt size of obi based on cover/dustjacket
- [Scans] Order of cover/dustjacket/obi should be based on the book's page order.
- [RichTextContent] Add autolink block support - [RichTextContent] Add autolink block support
- Save cookies for longer than just the session - Save cookies for longer than just the session
- [Scripts] Can't run the scripts using node (ts-node?)
- Support for nameless section - Support for nameless section
- [Timeline] Error if collectible not published? - [Timeline] Error if collectible not published?
- [Timeline] Handle no JS for footers - [Timeline] display source language
- [Timeline] Add details button in footer with credits + last updated / created - [Timeline] Add details button in footer with credits + last updated / created
- When the tags overflow, the tag group name should be align start (see http://localhost:12499/en/pages/magnitude-negative-chapter-1) - When the tags overflow, the tag group name should be align start (see http://localhost:12499/en/pages/magnitude-negative-chapter-1)
- [SDK] create a initPayload() that return a payload sdk (and stop hard wirring to ENV or node-cache) - [SDK] create a initPayload() that return a payload sdk (and stop hard wirring to ENV or node-cache)
- [Videos] see why no video on Firefox and no poster on Chrome https://v3.accords-library.com/en/videos/661b672825d380e548dbb8c8 - [Videos] see why no video on Firefox and no poster on Chrome https://v3.accords-library.com/en/videos/661b672825d380e548dbb8c8
- [Videos] Display platform info + channel page - [Videos] Display platform info + channel page
- [Timeline] Handle no JS for footers
## Long term ## Long term
- [Scripts] Can't run the scripts using node (ts-node?)
- [Scans] Adapt size of obi based on cover/dustjacket
- [Scans] Order of cover/dustjacket/obi should be based on the book's page order.
- [Medias] Add Parent pages
- Add proper localization for formatFilesize, formatInches, formatMillimeters, formatPounds, and formatGrams
- [Timeline] Some filtering options (by source/languages) - [Timeline] Some filtering options (by source/languages)
- The Chronicles - The Chronicles
- The Changelog - The Changelog

View File

@ -6,12 +6,13 @@ import { formatLocale } from "src/utils/format";
import { getI18n } from "src/i18n/i18n"; import { getI18n } from "src/i18n/i18n";
interface Props { interface Props {
currentLang: string; currentLanguage: string;
currentSourceLanguage: string;
getPartialUrl: (locale: string) => string; getPartialUrl: (locale: string) => string;
availableLanguages: string[]; availableLanguages: string[];
} }
const { currentLang, getPartialUrl, availableLanguages } = Astro.props; const { currentLanguage, currentSourceLanguage, getPartialUrl, availableLanguages } = Astro.props;
const { t } = await getI18n(Astro.locals.currentLocale); const { t } = await getI18n(Astro.locals.currentLocale);
--- ---
@ -19,13 +20,16 @@ const { t } = await getI18n(Astro.locals.currentLocale);
<div id="lang-selector" class="when-js when-no-print"> <div id="lang-selector" class="when-js when-no-print">
<Tooltip trigger="click"> <Tooltip trigger="click">
<Button icon="material-symbols:translate" title={currentLang.toUpperCase()} /> <Button
icon="material-symbols:translate"
title={`${currentLanguage !== currentSourceLanguage ? `${currentSourceLanguage.toUpperCase()} → ` : ""}${currentLanguage.toUpperCase()}`}
/>
<div id="tooltip-content" slot="tooltip-content"> <div id="tooltip-content" slot="tooltip-content">
{ {
availableLanguages.map((id) => ( availableLanguages.map((id) => (
<MasoActor href={getPartialUrl(id)}> <MasoActor href={getPartialUrl(id)}>
<p class:list={{ current: id === currentLang, "pressable-link": true }}> <p class:list={{ current: id === currentLanguage, "pressable-link": true }}>
{formatLocale(id)} {formatLocale(id)}
</p> </p>
</MasoActor> </MasoActor>

View File

@ -22,12 +22,13 @@ interface Props {
const reqUrl = new URL(Astro.request.url); const reqUrl = new URL(Astro.request.url);
const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!; const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!;
const slug = Astro.props.slug ?? reqUrl.searchParams.get("slug")!; const slug = Astro.props.slug ?? reqUrl.searchParams.get("slug")!;
const page = Astro.props.page ?? (await payload.getPage(slug)); const { translations, thumbnail, tagGroups } = Astro.props.page ?? (await payload.getPage(slug));
const { getLocalizedUrl } = await getI18n(Astro.locals.currentLocale); const { getLocalizedUrl } = await getI18n(Astro.locals.currentLocale);
const { getLocalizedMatch } = await getI18n(lang); const { getLocalizedMatch } = await getI18n(lang);
const translation = getLocalizedMatch(page.translations); const { pretitle, title, subtitle, summary, content, credits, toc, language, sourceLanguage } =
getLocalizedMatch(translations);
--- ---
{/* ------------------------------------------- HTML ------------------------------------------- */} {/* ------------------------------------------- HTML ------------------------------------------- */}
@ -35,22 +36,18 @@ const translation = getLocalizedMatch(page.translations);
<MasoTarget> <MasoTarget>
<AsideLayout> <AsideLayout>
<Fragment slot="header"> <Fragment slot="header">
<AppLayoutTitle <AppLayoutTitle title={title} pretitle={pretitle} subtitle={subtitle} />
title={translation.title}
pretitle={translation.pretitle}
subtitle={translation.subtitle}
/>
</Fragment> </Fragment>
<Fragment slot="header-aside"> <Fragment slot="header-aside">
{ {
page.thumbnail && ( thumbnail && (
<a href={getLocalizedUrl(`/images/${page.thumbnail.id}`)}> <a href={getLocalizedUrl(`/images/${thumbnail.id}`)}>
<img <img
id="thumbnail" id="thumbnail"
src={page.thumbnail.url} src={thumbnail.url}
width={page.thumbnail.width} width={thumbnail.width}
height={page.thumbnail.height} height={thumbnail.height}
/> />
</a> </a>
) )
@ -58,16 +55,17 @@ const translation = getLocalizedMatch(page.translations);
</Fragment> </Fragment>
<Fragment slot="meta"> <Fragment slot="meta">
{translation.summary && <AppLayoutDescription description={translation.summary} />} {summary && <AppLayoutDescription description={summary} />}
{page.tagGroups.length > 0 && <TagGroups tagGroups={page.tagGroups} />} {tagGroups.length > 0 && <TagGroups tagGroups={tagGroups} />}
</Fragment> </Fragment>
<Fragment slot="aside"> <Fragment slot="aside">
{ {
page.translations.length > 1 && ( translations.length > 1 && (
<LanguageOverride <LanguageOverride
currentLang={lang} currentLanguage={language}
availableLanguages={page.translations.map(({ language }) => language)} currentSourceLanguage={sourceLanguage}
availableLanguages={translations.map(({ language }) => language)}
getPartialUrl={(lang) => getPartialUrl={(lang) =>
getLocalizedUrl(`/api/pages/partial?lang=${lang}&slug=${slug}`) getLocalizedUrl(`/api/pages/partial?lang=${lang}&slug=${slug}`)
} }
@ -75,14 +73,14 @@ const translation = getLocalizedMatch(page.translations);
) )
} }
{translation.credits.length > 0 && <Credits credits={translation.credits} />} {credits.length > 0 && <Credits credits={credits} />}
{translation.toc.length > 0 && <TableOfContent toc={translation.toc} />} {toc.length > 0 && <TableOfContent toc={toc} />}
</Fragment> </Fragment>
<hr /> <hr />
<div id="text"> <div id="text">
<RichText content={translation.content} /> <RichText content={content} />
</div> </div>
</AsideLayout> </AsideLayout>
</MasoTarget> </MasoTarget>