feat: i18n

This commit is contained in:
marshmallow 2024-05-04 06:28:15 +10:00
parent 2049551387
commit e3ba2c4ba5
4 changed files with 51 additions and 25 deletions

View file

@ -1,5 +1,8 @@
--- ---
import { getLangFromUrl, useTranslations } from '../i18n/utils';
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
--- ---
<section id="goals"> <section id="goals">
@ -7,47 +10,33 @@
<div> <div>
<ol> <ol>
<li> <li>
<h3>Independent</h3> <h3>{t("goals.independent.title")}</h3>
<p> <p>
We will fork and maintain Nix, NixPkgs, and NixOS. Additional support {t("goals.independent")}
for projects such as Nix Darwin and Home Manager will be considered.
</p> </p>
</li> </li>
<li> <li>
<h3>Governance</h3> <h3>{t("goals.gov.title")}</h3>
<p> <p>
A democratic model of governance with elected positions will be used to {t("goals.gov")}
manage the project. A steering committee will provide direction with
additional committees handling specific logistical tasks. Features or
individual projects will be owned by Special Interest Groups. SIGs will
collaborate within Working Groups to achieve their goals. Each committee
and group will have its goals, requirements, and management process
clearly defined.
</p> </p>
</li> </li>
<li> <li>
<h3>Stabilization</h3> <h3>{t("goals.stabilization.title")}</h3>
<p> <p>
User-friendly features such as the Nix v3 CLI will be enabled by {t("goals.stabilization")}
default. Nix Flakes are used too heavily to remove or change and will
instead be stabilized as a v0 in its current state with any future work
being handled by a Special Interest Group.
</p> </p>
</li> </li>
<li> <li>
<h3>Infrastructure</h3> <h3>{t("goals.infa.title")}</h3>
<p> <p>
We will build and maintain the tools and infrastructure necessary to {t("goals.infa")}
keep the ecosystem healthy, including Continuous Integration and Binary
Caching.
</p> </p>
</li> </li>
<li> <li>
<h3>Education</h3> <h3>{t("goals.education.title")}</h3>
<p> <p>
Unified documentation, tutorials, guides, and examples will provide a {t("goals.education")}
better onboarding experience for newcomers and a faster iteration cycle
for experts.
</p> </p>
</li> </li>
</ol> </ol>

20
src/i18n/ui.ts Normal file
View file

@ -0,0 +1,20 @@
export const languages = {
en: 'English'
};
export const defaultLang = 'en';
export const ui = {
en: {
'goals.independent.title': 'Independent',
'goals.independent': 'We will fork and maintain Nix, NixPkgs, and NixOS. Additional support for projects such as Nix Darwin and Home Manager will be considered.',
'goals.gov.title': 'Governance',
'goals.gov': 'A democratic model of governance with elected positions will be used to manage the project. A steering committee will provide direction with additional committees handling specific logistical tasks. Features or individual projects will be owned by Special Interest Groups. SIGs will collaborate within Working Groups to achieve their goals. Each committee and group will have its goals, requirements, and management process clearly defined.',
'goals.stabilization.title': 'Stabilization',
'goals.stabilization': 'User-friendly features such as the Nix v3 CLI will be enabled by default. Nix Flakes are used too heavily to remove or change and will instead be stabilized as a v0 in its current state with any future work being handled by a Special Interest Group.',
'goals.infa.title': 'Infastructure',
'goals.infa': 'We will build and maintain the tools and infrastructure necessary to keep the ecosystem healthy, including Continuous Integration and Binary Caching.',
'goals.education.title': 'Education',
'goals.education': 'Unified documentation, tutorials, guides, and examples will provide a better onboarding experience for newcomers and a faster iteration cycle for experts.',
},
} as const;

13
src/i18n/utils.ts Normal file
View file

@ -0,0 +1,13 @@
import { ui, defaultLang } from './ui';
export function getLangFromUrl(url: URL) {
const [, lang] = url.pathname.split('/');
if (lang in ui) return lang as keyof typeof ui;
return defaultLang;
}
export function useTranslations(lang: keyof typeof ui) {
return function t(key: keyof typeof ui[typeof defaultLang]) {
return ui[lang][key] || ui[defaultLang][key];
}
}

View file

@ -1,13 +1,17 @@
--- ---
import { getLangFromUrl } from '../i18n/utils';
interface Props { interface Props {
title: string; title: string;
} }
const { title } = Astro.props; const { title } = Astro.props;
const lang = getLangFromUrl(Astro.url);
--- ---
<!doctype html> <!doctype html>
<html lang="en"> <html lang={lang}>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="description" content="An alternative to the Nix ecosystem." /> <meta name="description" content="An alternative to the Nix ecosystem." />