Offering various language options on a website determined by the URL

I've been contemplating how to add multi-language support to my personal website, which I developed using ExpressJS and NodeJS with EJS as the template engine. Currently, the website is only available in English, but I want to add a German version as well. My idea is to use URL variables for this purpose, such as

example.com/en/home - to display the home page in English

example.com/de/home - to display the home page in German

I also plan to include a section with two buttons representing the German and British flags to allow users to switch between languages.

What have I considered so far?

One solution I thought of was creating separate folders within my views directory, each dedicated to a specific language and containing the same content in different languages. However, serving the appropriate content based on the selected language would involve duplicating HTTP documents and routes, which goes against the principle of 'don't repeat yourself'.

Can anyone provide advice on a more efficient way to implement multi-language support? Any help would be greatly appreciated!

Answer №1

To ensure efficiency, I recommend using a single template for your views to avoid excessive duplication.

Consider utilizing the node package i18n-node for internationalization, as it seamlessly integrates with expressJs.

If you're curious about how this works, check out Michael DeRazon's excellent explanation on his website: Michael DeRazon, i18n for Node + Express

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Disable a Button with JavaScript in a Vue.js Application Without Using jQuery

I'm currently in the process of transitioning old jQuery code to JavaScript for a Vue.js application. function DisableSubmit() { submitButton.prop('disabled', true); submitButton.attr('data-enabled-value', submitButton.val ...

I attempted to log the elements of my submit button form, but unfortunately nothing is appearing in the browser console

I am attempting to capture the data from my submit button form, but for some reason, nothing is showing up in the console of my browser. $("#signupform").submit(function(event){ // Stopped default PHP processing event.preve ...

Analyzing the execution flow of functions

I've been hacking away at my code, but now I'm ready to bring some structure into it by incorporating unit tests and following a TDD approach. However, I'm facing challenges when trying to create a unit test that validates a method. Any tips ...

Event triggered when a Socket.IO connection is disconnected

Everything seems to be working well with my code when a new user joins, but I'm encountering issues when a user leaves as it doesn't display anything. Can someone point out the error in my code? Below is my server-side code: const express = requ ...

What is the best way to manage a significant volume of "business" data or objects within my JavaScript project?

I specialize in working with AngularJs and have a factory that provides services related to buildings. I am managing a large number of buildings (around 50-60) with multiple properties and sub-properties associated with each one (approximately 15-20, some ...

Refine JSON data by selecting only distinct key/value pairs

My JSON object has the following structure: var theSchools = { Bradley University: "bru", Knox College: "knox", Southern Illinois University Edwardsville: "siue",… } I am trying to find a way to retrieve the school name (key) based on the schoo ...

Are JSON Web Tokens (JWT) too lengthy to transmit via client URL? Exploring Node.js and Express for authentication purposes

I need to authenticate a user's email address using JWT instead of OAuth. This is necessary because users will be signing up with their work email and need to verify it. To do this, I have added an "isVerified" field to my User model. When a user sign ...

Specify the directory where the npm package should be installed

I've been exploring npm to handle the javascript for my project. During my search on stackoverflow, I came across this documentation: https://docs.npmjs.com/using-npm-packages-in-your-projects However, I must admit that it was quite confusing for me ...

You are required to select one of the two radio buttons in order to proceed with the validation process

To prevent the user from proceeding to the next page, validation is necessary. They are required to select one of the radio buttons, etc. <div class=""> <div class="radiho" style="display: block"> <input type="checkbox" name="sp ...

How to accentuate search results using Angular filters and conceal non-matching text?

Recently, I came across an interesting example of using Angular filter to highlight search results. It works well in highlighting the word 'suit', but I noticed that all non-matching text remains visible. If you'd like to see the example I ...

Is the populate method of Mongoose causing a disruption in the promise chain?

My mongoose Schema is structured as follows: var Functionary = new Schema({ person: { type: mongoose.Schema.Types.ObjectId, ref: 'Person' }, dateOfAssignment: Date, dateOfDischarge: Date, isActive: Boolean }); var PositionSche ...

Outdated errors encountered during the installation of packages in Gatsby

Encountering errors while installing packages with a Gatsby theme. I have already attempted npm install --legacy-peer-deps without success. Even after running gatsby develop , the errors persist: Here is the list of errors I am encountering: npm ERR! cod ...

Chrome's inability to efficiently handle chunked responses in comparison to Firefox and Safari

I am currently working on a unique test node server that sends chunked responses every two seconds with the specified headers: response.setHeader('Content-Type', 'text/plain') response.setHeader('Transfer-Encoding', 'chu ...

Header and footer remain unaligned

Bookstore.html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <style> ul { list-style-type: none; padding: 20px; overflow: hidden; background-color: black; width:1230px; p ...

Incorporate the .pem data into the .env file

In my next.js application, I am facing a challenge with JWT public/private key authentication. My hosting provider does not allow me to upload secret files, so I am attempting to access the .pem file from a multi-line string stored in an .env variable. Th ...

Guide to displaying options in the Vue material select box even when the default value is blank

I have implemented the material design framework vuematerial with vue.js. In traditional HTML, a selection box looks like this: <select> <option value="">You should initially see this</option> <option value="1">One</o ...

Adjusting the grid for various mobile screen sizes

I am currently working on designing a user interface (UI) for mobile screens that includes a header, grid, and buttons. I want the UI to look consistent across all mobile devices. Here are screenshots from various mobile screens: Samsung S5 Pixel 2 XL I ...

What could be causing certain link titles to appear outside of my <a> tags?

Check out this jsbin link to see the issue I am facing. I noticed that some of my link titles are appearing outside the anchor tags. Initially, I thought it was because some titles were enclosed in double quotes. I tried creating a function to fix this, b ...

Encountering a 400 bad request error when attempting to utilize AJAX within a WordPress environment

I am encountering a 400 error while attempting to retrieve the response from WordPress AJAX. Despite multiple attempts, I have been unable to pinpoint the root cause of the issue. The jQuery version being used is 3.6 and the filter.js file appears to be fu ...

Remove the option to select specific minutes from the time input on an HTML

My HTML code includes a time input that looks like this: <input id="appt-time" type="time" name="appt-time" value="13:30" /> I want to figure out how I can remove the minutes from the input or ensure that the ...