i18n: Fix TypeScript noUncheckedIndexedAccess errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-30 10:07:59 -07:00
parent eedde08f24
commit 6a429603ad
1 changed files with 4 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import type {MessageDescriptor} from "@formatjs/intl";
import {DEFAULT_INTL_CONFIG, IntlErrorCode, createIntl, createIntlCache} from "@formatjs/intl"; import {DEFAULT_INTL_CONFIG, IntlErrorCode, createIntl, createIntlCache} from "@formatjs/intl";
import type {FormatXMLElementFn, PrimitiveType} from "intl-messageformat"; import type {FormatXMLElementFn, PrimitiveType} from "intl-messageformat";
import _ from "lodash"; import _ from "lodash";
import assert from "minimalistic-assert";
import {page_params} from "./base_page_params"; 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 let language_list: (typeof page_params & {page_type: "home"})["language_list"];
export function get_language_name(language_code: string): string { export function get_language_name(language_code: string): string {
const language_list_map: Record<string, string> = {}; const language = language_list.find((language) => language.code === language_code);
assert(language !== undefined);
// One-to-one mapping from code to name for all languages return language.name;
for (const language of language_list) {
language_list_map[language.code] = language.name;
}
return language_list_map[language_code];
} }
export function initialize(language_params: {language_list: typeof language_list}): void { export function initialize(language_params: {language_list: typeof language_list}): void {