forked from i18next/i18next-http-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.fresh.js
More file actions
39 lines (36 loc) · 1.01 KB
/
middleware.fresh.js
File metadata and controls
39 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { expect } from 'jsr:@std/expect'
import i18next from 'https://deno.land/x/i18next/index.js'
import i18nextMiddleware from '../../index.js'
const { test } = Deno
import { App } from "jsr:@fresh/core";
i18next
.use(i18nextMiddleware.LanguageDetector)
.init({
preload: ["en", "fr"],
fallbackLng: "en",
resources: {
en: {
translation: { hi: "hello" }
},
fr: {
translation: { hi: "bonjour" }
}
}
});
test('middleware fresh', async () => {
const handler = new App()
.use(i18nextMiddleware.freshPlugin(i18next))
.get("/", (ctx) => {
return new Response(ctx.state.t('hi'))
})
.handler();
const headers = new Headers()
headers.append('Accept-Language', 'fr')
const res = await handler(
new Request('http://localhost',
{ headers }
));
const resHeaders = Object.fromEntries(res.headers.entries())
expect(resHeaders).toEqual(expect.objectContaining({ 'content-language': 'fr'}))
expect(await res.text()).toEqual("bonjour")
})