Format list of supported projects with Intl

This commit is contained in:
Nikita Karamov 2024-02-12 19:09:33 +01:00
parent 166d4fcc44
commit a37470bf9c
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD
2 changed files with 20 additions and 4 deletions

View file

@ -72,6 +72,18 @@ export function applyTranslations(language: string) {
} }
} }
if (Intl.ListFormat) {
const formatter = new Intl.ListFormat(language, {
style: "short",
type: "conjunction",
});
for (const node of document.querySelectorAll("[data-enumerate]")) {
const dataset = (node as HTMLElement).dataset;
node.innerHTML = formatter.format(dataset.enumerate!.split(","));
}
}
document.documentElement.lang = language; document.documentElement.lang = language;
document.documentElement.dir = document.documentElement.dir =
languages[language as keyof typeof languages].dir; languages[language as keyof typeof languages].dir;

View file

@ -107,12 +107,16 @@ import package_ from "../../package.json";
<p><b data-translate="supportedProjects">Supported projects:</b></p> <p><b data-translate="supportedProjects">Supported projects:</b></p>
<ul> <ul>
<li> <li>
Mastodon (<span data-translate="incl">incl.</span> Hometown, Fedibird, Mastodon (<span data-translate="incl">incl.</span>&#x0020;<span
GlitchCafé) data-enumerate="Hometown,Fedibird,GlitchCafé"
>Hometown, Fedibird, GlitchCafé</span
>)
</li> </li>
<li> <li>
Misskey (<span data-translate="incl">incl.</span> Firefish/Calckey, Misskey (<span data-translate="incl">incl.</span>&#x0020;<span
FoundKey, Meisskey) data-enumerate="Firefish,Calckey,FoundKey,Meisskey"
>Firefish, Calckey, FoundKey, Meisskey</span
>)
</li> </li>
<li>Friendica</li> <li>Friendica</li>
<li>Hubzilla</li> <li>Hubzilla</li>