Implement approved specification #32 and tickets #33-#37. Keep host authentication server-verified and pin session interaction language. Compile scoped base selectors for browser compatibility and retain full gutters during CSS pruning.
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import type { TranslationParams } from "../../i18n";
|
|
|
|
/** Keep IDs and parameters in state so open results follow later locale changes. */
|
|
export type AdminMessage = string | {
|
|
message: string;
|
|
params?: Readonly<Record<string, string | number | { message: string }>>;
|
|
};
|
|
|
|
export function adminMessage(message: string, params?: Exclude<AdminMessage, string>["params"]): AdminMessage {
|
|
return { message, params };
|
|
}
|
|
|
|
/** Local API diagnostics retain their code; translate only the known message body. */
|
|
export function renderAdminDiagnostic(t: (message: string) => string, diagnostic: string): string {
|
|
const match = /^([a-z][a-z_]+): (.+)$/.exec(diagnostic);
|
|
return match ? `${match[1]}: ${t(match[2])}` : t(diagnostic);
|
|
}
|
|
|
|
export function renderAdminMessage(
|
|
t: (message: string, params?: TranslationParams) => string,
|
|
value: AdminMessage,
|
|
): string {
|
|
if (typeof value === "string") return t(value);
|
|
const params = value.params && Object.fromEntries(Object.entries(value.params).map(([key, param]) =>
|
|
[key, typeof param === "object" ? t(param.message) : param],
|
|
));
|
|
return t(value.message, params);
|
|
}
|