Replies: 3 comments
-
yes multiple langugare would be nice! |
Beta Was this translation helpful? Give feedback.
-
Here is an example:
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import i18next from "https://deno.land/x/i18next/index.js";
import Backend from "https://deno.land/x/i18next_fs_backend/index.js";
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
i18next
.use(Backend)
.init({
// debug: true,
backend: { loadPath: "locales/{{lng}}/locales.json" },
fallbackLng: "en",
preload: ["en", "de", "it"],
});
export async function handler(
req: Request,
ctx: MiddlewareHandlerContext<any>,
) {
ctx.state.i18n = i18next.getFixedT(ctx.state.lng || systemLocale);
const res = await ctx.next();
return res;
}
import { Handlers, PageProps } from "$fresh/server.ts";
export const handler: Handlers = {
GET(req: any, ctx: any) {
console.log(ctx.state.i18n("home.title"));
return ctx.render({ template: ctx.twindTheme });
},
}; which assumes at least files for ["en", "de", "it"] and that e.g. your {
"home": {
"title": "Hallo Welt!"
}
} |
Beta Was this translation helpful? Give feedback.
-
If it helps, I've started working on a plugin for my own stuff. |
Beta Was this translation helpful? Give feedback.
-
It would be nice if fresh supported i18next or any other localization framework.
I was checking out this https://github.com/i18next/i18next-http-middleware but it doesn't seem to integrate well with fresh
Beta Was this translation helpful? Give feedback.
All reactions