Skip to content

Commit ef25682

Browse files
feat: allow lang configuration (#288)
Co-authored-by: Luca Casonato <hello@lcas.dev>
1 parent ad8aa1c commit ef25682

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/server/render.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface RenderOptions<Data> {
2626
renderFn: RenderFunction;
2727
data?: Data;
2828
error?: unknown;
29+
lang?: string;
2930
}
3031

3132
export type InnerRenderFunction = () => string;
@@ -36,12 +37,13 @@ export class RenderContext {
3637
#styles: string[] = [];
3738
#url: URL;
3839
#route: string;
39-
#lang = "en";
40+
#lang: string;
4041

41-
constructor(id: string, url: URL, route: string) {
42+
constructor(id: string, url: URL, route: string, lang: string) {
4243
this.#id = id;
4344
this.#url = url;
4445
this.#route = route;
46+
this.#lang = lang;
4547
}
4648

4749
/** A unique ID for this logical JIT render. */
@@ -151,6 +153,7 @@ export async function render<Data>(
151153
crypto.randomUUID(),
152154
opts.url,
153155
opts.route.pattern,
156+
opts.lang ?? "en",
154157
);
155158

156159
if (csp) {

src/server/render_test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { template } from "./render.tsx";
2+
import { assertStringIncludes } from "../../tests/deps.ts";
3+
Deno.test("check lang", () => {
4+
const lang = "fr";
5+
const body = template({
6+
bodyHtml: "",
7+
headComponents: [],
8+
imports: [],
9+
preloads: [],
10+
styles: [],
11+
lang: lang,
12+
});
13+
assertStringIncludes(body, `<html lang="${lang}">`);
14+
});

0 commit comments

Comments
 (0)