diff --git a/web/src/i18n.ts b/web/src/i18n.ts index f528aaf87e..090f5cbb41 100644 --- a/web/src/i18n.ts +++ b/web/src/i18n.ts @@ -5,6 +5,7 @@ import type {MessageDescriptor} from "@formatjs/intl"; import {DEFAULT_INTL_CONFIG, IntlErrorCode, createIntl, createIntlCache} from "@formatjs/intl"; import type {FormatXMLElementFn, PrimitiveType} from "intl-messageformat"; import _ from "lodash"; +import assert from "minimalistic-assert"; import {page_params} from "./base_page_params"; @@ -53,13 +54,9 @@ export function $t_html( export let language_list: (typeof page_params & {page_type: "home"})["language_list"]; export function get_language_name(language_code: string): string { - const language_list_map: Record = {}; - - // One-to-one mapping from code to name for all languages - for (const language of language_list) { - language_list_map[language.code] = language.name; - } - return language_list_map[language_code]; + const language = language_list.find((language) => language.code === language_code); + assert(language !== undefined); + return language.name; } export function initialize(language_params: {language_list: typeof language_list}): void {