More things
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user