i18n?
#356
Replies: 3 comments
|
yes multiple langugare would be nice! |
0 replies
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!"
}
} |
0 replies
|
If it helps, I've started working on a plugin for my own stuff. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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
All reactions