feat: allow lang configuration (#288)

Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
Benjamin Geets
2022-06-26 13:37:18 +02:00
committed by GitHub
co-authored by Luca Casonato
parent ad8aa1cbca
commit ef25682725
2 changed files with 19 additions and 2 deletions
+5 -2
View File
@@ -26,6 +26,7 @@ export interface RenderOptions<Data> {
renderFn: RenderFunction;
data?: Data;
error?: unknown;
lang?: string;
}
export type InnerRenderFunction = () => string;
@@ -36,12 +37,13 @@ export class RenderContext {
#styles: string[] = [];
#url: URL;
#route: string;
#lang = "en";
#lang: string;
constructor(id: string, url: URL, route: string) {
constructor(id: string, url: URL, route: string, lang: string) {
this.#id = id;
this.#url = url;
this.#route = route;
this.#lang = lang;
}
/** A unique ID for this logical JIT render. */
@@ -151,6 +153,7 @@ export async function render<Data>(
crypto.randomUUID(),
opts.url,
opts.route.pattern,
opts.lang ?? "en",
);
if (csp) {
+14
View File
@@ -0,0 +1,14 @@
import { template } from "./render.tsx";
import { assertStringIncludes } from "../../tests/deps.ts";
Deno.test("check lang", () => {
const lang = "fr";
const body = template({
bodyHtml: "",
headComponents: [],
imports: [],
preloads: [],
styles: [],
lang: lang,
});
assertStringIncludes(body, `<html lang="${lang}">`);
});