summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/LallansIssue.astro27
-rw-r--r--src/components/LallansIssueContributions.astro26
-rw-r--r--src/i18n/translate.ts17
-rw-r--r--src/i18n/translations/pages/furthsettins.ts8
-rw-r--r--src/i18n/translations/pages/home.ts8
-rw-r--r--src/i18n/translations/site.ts20
-rw-r--r--src/layouts/Layout.astro4
-rw-r--r--src/pages/[locale]/furthsettins/index.astro10
-rw-r--r--src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro12
-rw-r--r--src/pages/[locale]/furthsettins/lallans/index.astro8
-rw-r--r--src/pages/[locale]/index.astro8
-rw-r--r--src/types/TranslationsDictionary.d.ts10
12 files changed, 91 insertions, 67 deletions
diff --git a/src/components/LallansIssue.astro b/src/components/LallansIssue.astro
index 915c17d..d60e2fe 100644
--- a/src/components/LallansIssue.astro
+++ b/src/components/LallansIssue.astro
@@ -1,11 +1,11 @@
---
-import translate from "../i18n/translate";
+import translate from '../i18n/translate';
import tSite from '../i18n/translations/site';
-import type LallansIssue from "../types/LallansIssue";
-import type Locale from "../types/Locale";
-import LallansIssueContributions from "./LallansIssueContributions.astro";
-import LallansIssueContributors from "./LallansIssueContributors.astro";
-import PayPalButtons from "./PayPalButtons.astro";
+import type LallansIssue from '../types/LallansIssue';
+import type Locale from '../types/Locale';
+import LallansIssueContributions from './LallansIssueContributions.astro';
+import LallansIssueContributors from './LallansIssueContributors.astro';
+import PayPalButtons from './PayPalButtons.astro';
interface Props {
issue: LallansIssue;
@@ -18,8 +18,8 @@ const t = translate(locale);
<div class="lallans-issue__header-block">
<header>
- <h1>{ t(tSite, 'lallans') } { issue.issueNumber }</h1>
- <p class="italic">{ issue.description[locale] }</p>
+ <h1>{t(tSite, { key: 'lallans' })} {issue.issueNumber}</h1>
+ <p class="italic">{issue.description[locale]}</p>
</header>
<div class="lallans-issue__header-block-end">
@@ -28,11 +28,10 @@ const t = translate(locale);
</div>
</div>
-{ 'contributions' in issue ? (
- <LallansIssueContributions contributions={issue.contributions} locale={locale} />
+{
+ 'contributions' in issue ? (
+ <LallansIssueContributions contributions={issue.contributions} locale={locale} />
) : (
- 'contributors' in issue && (
- <LallansIssueContributors contributors={issue.contributors} />
- )
+ 'contributors' in issue && <LallansIssueContributors contributors={issue.contributors} />
)
-} \ No newline at end of file
+}
diff --git a/src/components/LallansIssueContributions.astro b/src/components/LallansIssueContributions.astro
index 2888ca6..cfd3392 100644
--- a/src/components/LallansIssueContributions.astro
+++ b/src/components/LallansIssueContributions.astro
@@ -1,5 +1,5 @@
---
-import translate from "../i18n/translate";
+import translate from '../i18n/translate';
import tSite from '../i18n/translations/site';
import type { Contribution } from '../types/LallansIssue';
import type Locale from '../types/Locale';
@@ -16,14 +16,18 @@ const t = translate(locale);
<section>
<h2>Contributions</h2>
<ul class="lallans-issue__contributions">
- { contributions.map(contribution => (
- <li>
- <span class="italic">{ contribution.title }</span>
- { 'author' in contribution && (
- <span> { t(tSite, 'by') } { contribution.author }</span>
- )
- }
- </li>
- ))}
+ {
+ contributions.map((contribution) => (
+ <li>
+ <span class="italic">{contribution.title}</span>
+ {'author' in contribution && (
+ <span>
+ {' '}
+ {t(tSite, { key: 'by' })} {contribution.author}
+ </span>
+ )}
+ </li>
+ ))
+ }
</ul>
-</section> \ No newline at end of file
+</section>
diff --git a/src/i18n/translate.ts b/src/i18n/translate.ts
index b407e3b..b911547 100644
--- a/src/i18n/translate.ts
+++ b/src/i18n/translate.ts
@@ -1,9 +1,20 @@
import type Locale from '../types/Locale';
-import type { TranslationsDictionary } from '../types/TranslationsDictionary';
+import type { TranslationsDictionary, Translation } from '../types/TranslationsDictionary';
import { defaultLocale } from './locales';
+type TranslationsDictionaryWith<Key extends string, Params> = TranslationsDictionary<{
+ [key in Key]: { [locale in typeof defaultLocale]: Translation<Params> } & {
+ [locale in Locale]?: Translation<Params>;
+ };
+}>;
+
export default function (locale: Locale) {
- return function <T extends string>(dict: TranslationsDictionary<T>, key: T) {
- return dict[key][locale] ?? dict[key][defaultLocale];
+ return function <
+ Key extends string,
+ Params,
+ Dict extends TranslationsDictionaryWith<Key, Params>,
+ >(dict: Dict, params: { key: Key } & { [Param in keyof Params]: string }) {
+ const translation = dict[params.key][locale] ?? dict[params.key][defaultLocale];
+ return translation(params);
};
}
diff --git a/src/i18n/translations/pages/furthsettins.ts b/src/i18n/translations/pages/furthsettins.ts
index 41da32b..4b87311 100644
--- a/src/i18n/translations/pages/furthsettins.ts
+++ b/src/i18n/translations/pages/furthsettins.ts
@@ -2,10 +2,10 @@ import type { TranslationsDictionary } from '../../../types/TranslationsDictiona
const furthsettinsTranslations = {
title: {
- sco: 'Furthsettins',
- 'en-GB': 'Publications',
+ sco: () => 'Furthsettins',
+ 'en-GB': () => 'Publications',
},
};
-type Keys = keyof typeof furthsettinsTranslations;
-export default furthsettinsTranslations as TranslationsDictionary<Keys>;
+type Raw = typeof furthsettinsTranslations;
+export default furthsettinsTranslations as TranslationsDictionary<Raw>;
diff --git a/src/i18n/translations/pages/home.ts b/src/i18n/translations/pages/home.ts
index 0dff80d..dda30b8 100644
--- a/src/i18n/translations/pages/home.ts
+++ b/src/i18n/translations/pages/home.ts
@@ -2,10 +2,10 @@ import type { TranslationsDictionary } from '../../../types/TranslationsDictiona
const homeTranslations = {
title: {
- sco: 'Hame',
- 'en-GB': 'Home',
+ sco: () => 'Hame',
+ 'en-GB': () => 'Home',
},
};
-type Keys = keyof typeof homeTranslations;
-export default homeTranslations as TranslationsDictionary<Keys>;
+type Raw = typeof homeTranslations;
+export default homeTranslations as TranslationsDictionary<Raw>;
diff --git a/src/i18n/translations/site.ts b/src/i18n/translations/site.ts
index 89e9ed5..b414499 100644
--- a/src/i18n/translations/site.ts
+++ b/src/i18n/translations/site.ts
@@ -2,22 +2,22 @@ import type { TranslationsDictionary } from '../../types/TranslationsDictionary'
const siteTranslations = {
title: {
- sco: 'Scots Leid Associe',
- 'en-GB': 'Scots Language Society',
+ sco: () => 'Scots Leid Associe',
+ 'en-GB': () => 'Scots Language Society',
},
description: {
- sco: 'The wabsteid o the Scots Leid Associe',
- 'en-GB': 'The website of the Scots Language Society',
+ sco: () => 'The wabsteid o the Scots Leid Associe',
+ 'en-GB': () => 'The website of the Scots Language Society',
},
lallans: {
- sco: 'Lallans',
- 'en-GB': 'Lallans',
+ sco: () => 'Lallans',
+ 'en-GB': () => 'Lallans',
},
by: {
- sco: 'bi',
- 'en-GB': 'by',
+ sco: () => 'bi',
+ 'en-GB': () => 'by',
},
};
-type Keys = keyof typeof siteTranslations;
-export default siteTranslations as TranslationsDictionary<Keys>;
+type Raw = typeof siteTranslations;
+export default siteTranslations as TranslationsDictionary<Raw>;
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro
index 360acfb..ca567f6 100644
--- a/src/layouts/Layout.astro
+++ b/src/layouts/Layout.astro
@@ -17,13 +17,13 @@ const t = translate(locale);
<html lang="sco">
<head>
<meta charset="UTF-8" />
- <meta name="description" content={ t(site, 'description') } />
+ <meta name="description" content={t(site, { key: 'description' })} />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="/normalize.css" />
<link rel="stylesheet" href="/main.css" />
<meta name="generator" content={Astro.generator} />
- <title>{ title } | { t(site, 'title') }</title>
+ <title>{title} | {t(site, { key: 'title' })}</title>
</head>
<body>
<slot />
diff --git a/src/pages/[locale]/furthsettins/index.astro b/src/pages/[locale]/furthsettins/index.astro
index f59616a..45e583c 100644
--- a/src/pages/[locale]/furthsettins/index.astro
+++ b/src/pages/[locale]/furthsettins/index.astro
@@ -6,21 +6,23 @@ import tFurthsettins from '../../../i18n/translations/pages/furthsettins';
import tSite from '../../../i18n/translations/site';
import type Locale from '../../../types/Locale';
-export async function getStaticPaths() { return localeStaticPaths; }
+export async function getStaticPaths() {
+ return localeStaticPaths;
+}
const locale = Astro.params.locale as Locale;
const t = translate(locale);
---
-<Page locale={locale} title={ t(tFurthsettins, 'title') }>
+<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}>
<h1>Furthsettins</h1>
<ul class="publications-gallery">
<li>
<a href="furthsettins/lallans" class="link">
<img src="/images/furthsettins/lallans.jpg" class="publications-gallery__image" />
- <p class="publications-gallery__title">{ t(tSite, 'lallans') }</p>
+ <p class="publications-gallery__title">{t(tSite, { key: 'lallans' })}</p>
</a>
</li>
</ul>
-</Page> \ No newline at end of file
+</Page>
diff --git a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro
index dc3cecc..876eab1 100644
--- a/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro
+++ b/src/pages/[locale]/furthsettins/lallans/[issueNumber]/index.astro
@@ -10,11 +10,9 @@ import LallansIssue from '../../../../../components/LallansIssue.astro';
export async function getStaticPaths() {
const lallansIssueNumbers = Object.keys(getLallansIssue) as `${LallansIssueNumber}`[];
- return lallansIssueNumbers.flatMap(n => (
- localeStaticPaths.map(p => (
- { ...p, params: { ...p.params, issueNumber: n } }
- ))
- ));
+ return lallansIssueNumbers.flatMap((n) =>
+ localeStaticPaths.map((p) => ({ ...p, params: { ...p.params, issueNumber: n } }))
+ );
}
const locale = Astro.params.locale as Locale;
@@ -23,6 +21,6 @@ const issueNumber = new Number(Astro.params.issueNumber).valueOf() as LallansIss
const issue = await getLallansIssue[issueNumber]();
---
-<Page locale={locale} title={ t(tFurthsettins, 'title') }>
+<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}>
<LallansIssue issue={issue} locale={locale} />
-</Page> \ No newline at end of file
+</Page>
diff --git a/src/pages/[locale]/furthsettins/lallans/index.astro b/src/pages/[locale]/furthsettins/lallans/index.astro
index 0c10b99..b565497 100644
--- a/src/pages/[locale]/furthsettins/lallans/index.astro
+++ b/src/pages/[locale]/furthsettins/lallans/index.astro
@@ -6,14 +6,16 @@ import tFurthsettins from '../../../../i18n/translations/pages/furthsettins';
import type Locale from '../../../../types/Locale';
import LallansIssuesGallery from '../../../../components/LallansIssuesGallery.astro';
-export async function getStaticPaths() { return localeStaticPaths; }
+export async function getStaticPaths() {
+ return localeStaticPaths;
+}
const locale = Astro.params.locale as Locale;
const t = translate(locale);
---
-<Page locale={locale} title={ t(tFurthsettins, 'title') }>
+<Page locale={locale} title={t(tFurthsettins, { key: 'title' })}>
<h1>Lallans</h1>
<LallansIssuesGallery />
-</Page> \ No newline at end of file
+</Page>
diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro
index 5f9ab7a..8ae3a7b 100644
--- a/src/pages/[locale]/index.astro
+++ b/src/pages/[locale]/index.astro
@@ -6,15 +6,17 @@ import site from '../../i18n/translations/site';
import home from '../../i18n/translations/pages/home';
import type Locale from '../../types/Locale';
-export async function getStaticPaths() { return localeStaticPaths; }
+export async function getStaticPaths() {
+ return localeStaticPaths;
+}
const locale = Astro.params.locale as Locale;
const t = translate(locale);
---
-<Page locale={locale} title={ t(home, 'title') }>
+<Page locale={locale} title={t(home, { key: 'title' })}>
<section>
- <h1 class="title">{ t(site, 'title') }</h1>
+ <h1 class="title">{t(site, { key: 'title' })}</h1>
<h1>Tap-level heidin</h1>
<h2>Seicont-level heidin</h2>
<h3>Third-level heidin</h3>
diff --git a/src/types/TranslationsDictionary.d.ts b/src/types/TranslationsDictionary.d.ts
index 5a8a251..d62947c 100644
--- a/src/types/TranslationsDictionary.d.ts
+++ b/src/types/TranslationsDictionary.d.ts
@@ -1,6 +1,12 @@
import type { defaultLocale } from '../i18n/locales';
import type Locale from './Locale';
-type TranslationsDictionary<Keys> = {
- [key in Keys]: { [key in Locale]?: string } & { [key in typeof defaultLocale]: string };
+export type Translation<Params> = (params: { [key in keyof Params]: string }) => string;
+
+export type TranslationsDictionary<Raw> = {
+ [key in keyof Raw]: {
+ [locale in Locale]?: Translation<Parameters<Raw[key][typeof defaultLocale]>[0]>;
+ } & {
+ [locale in typeof defaultLocale]: Translation<Parameters<Raw[key][typeof defaultLocale]>[0]>;
+ };
};