More things

This commit is contained in:
2026-10-01 02:29:21 +02:00
parent e1df4d3ae1
commit 13b659662e
54 changed files with 4409 additions and 911 deletions

View File

@@ -35,6 +35,22 @@ export function languageName(code: string): string {
return LANGUAGES.find((l) => l.code === code)?.name ?? code.toUpperCase()
}
/**
* Which language version to open an article in when the address asks for
* none: the reader's own language when the article speaks it, else English
* as the wiki's common tongue, else null — nothing to pick, so whatever
* version already stands for the article answers.
*/
export function preferredLanguage(
available: readonly (string | undefined)[],
reader: string
): string | null {
const codes = new Set(available.map((c) => (c ?? '').trim().toLowerCase()))
const wanted = reader.trim().toLowerCase()
if (codes.has(wanted)) return wanted
return codes.has(DEFAULT_LANGUAGE) ? DEFAULT_LANGUAGE : null
}
/** The first language no version of an article has been written in yet. */
export function nextFreeLanguage(taken: readonly string[]): string {
const takenCodes = taken.map((c) => c.trim().toLowerCase())