Our great sponsors
-
i18next-fs-backend
i18next-fs-backend is a backend layer for i18next using in Node.js and for Deno to load translations from the filesystem.
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
Alternatively, use i18next-locize-backend instead of the i18next-fs-backend. If you're running your code in a serverless environment, make sure you read this advice first!
We will show some examples that uses i18next as i18n framework. If you're curious to know why we suggest i18next, have a look at this page.
Just use this cli to synchronize the translations with your code. To see how this could look like check out Step 1 in this tutorial.
This time we will use a different i18next module, i18next-http-middleware. It can be used for all Deno web frameworks, like abc or ServestJS, but also for Node.js web frameworks, like express or Fastify.
This time we will use a different i18next module, i18next-http-middleware. It can be used for all Deno web frameworks, like abc or ServestJS, but also for Node.js web frameworks, like express or Fastify.
// deno run --allow-net --allow-read index.js import { Application } from 'https://deno.land/x/abc/mod.ts' import { config } from "https://deno.land/x/dotenv/mod.ts" import { i18n, middleware } from './i18n.js' import { renderFile } from 'https://deno.land/x/dejs/mod.ts' const port = config.PORT || 8080 const app = new Application() app.renderer = { render(name, data) { return renderFile(`./views/${name}.html`, data) } } const handle = middleware.handle(i18n) app.use((next) => (c) => { handle(c) return next(c) } ) app.get('/', (c) => c.render('index', { t: c.request.t, i18n: c.request.i18n })) app.get('/raw', (c) => c.request.t('home.title')) app.start({ port }) console.log(i18n.t('server.started', { port })) console.log(i18n.t('server.started', { port, lng: 'de' })) console.log(i18n.t('server.started', { port, lng: 'it' }))
Related posts
- Is there an easy way to deploy Deno to production like for example Node to AWS Elastic Beanstalk? Or something in the works? I want to use deno in production on AWS Amazon.
- How does server side internationalization (i18n) look like?
- Building a GitHub activity feed with Node.js and Socket.io
- NestJS tip: how to change HTTP server timeouts
- 7 Frameworks, One SAML Jackson - Your Open Source Single Sign-On Solution