Github Readme To Pages Website
Have you ever wanted to create your own professional portfolio website without spending hours writing HTML, CSS, and JavaScript...
Tech Tutorials and Resources Read articleNovember 26, 2026
Creating a multilingual website can make content accessible to visitors from different parts of the world. However, implementing internationalization manually often requires maintaining language files, configuring translations, and writing additional JavaScript to switch between languages.
Fortunately, JavaScript libraries such as translate.js simplify this process by providing automatic webpage translation without requiring developers to rewrite their existing HTML content.
In this tutorial, we will explore translate.js, an open-source JavaScript library developed by xnx3. It provides automatic HTML translation with a minimal JavaScript setup and offers numerous customization options for controlling translation behavior.
We will also explore how I integrated this library into my personal blog website, Madhurima Mindscape, using a floating language button, a searchable language dropdown, and localStorage to remember visitors' language preferences.
You can also try the live implementation right here on this website! Simply click the floating language button to open the language panel, then expand the language dropdown to browse or search for your preferred language. This lets you experience how translate.js works in practice and see how easily it can translate the webpage content.
GitHub Repository: xnx3/translate
Official Documentation: translate.js Documentation
"A multilingual website should make content accessible without making the translation implementation unnecessarily complicated."
translate.js is an open-source JavaScript library designed to provide automatic multilingual translation for websites.
Its main objective is to simplify website internationalization by allowing developers to translate webpage content with a minimal amount of JavaScript code.
According to its GitHub repository, the library provides several useful capabilities:
One of its biggest advantages is that developers can get started with only a few JavaScript instructions instead of building an entire translation system from scratch.
The library also provides an extensive collection of extension instructions for more precise control over translation behavior.
💡 My tip: If you want to introduce multilingual support into an existing static HTML website, explore translate.js before building a complete translation system manually.
Traditional internationalization implementations often require developers to maintain separate translations for different languages and manually connect those translations with webpage elements.
translate.js offers an alternative approach by automatically identifying and translating webpage text through its translation service.
Some important advantages include:
The library also supports different translation service configurations. For example, client.edge can be selected without configuring your own translation server.
💡 My tip: Choose the translation service according to your application's requirements. For production websites, also evaluate service availability, reliability, privacy, and usage limits.
Before implementing translation, we need to load the translate.js library into our webpage.
Add the following script to your HTML page. It can be placed near the end of the body section.
<script src="https://res.zvo.cn/translate/translate.js"></script>
Alternatively, you can download the library from its GitHub repository and host the file within your own project.
Specify the original language used by your website. In my personal blog, the original content is written in English.
translate.language.setLocal('english');
This tells the library which language should be treated as the local language of the webpage.
Next, configure the translation service. In my implementation, I used the client.edge translation service.
translate.service.use('client.edge');
Finally, initialize the translation process:
translate.execute();
The basic configuration can therefore be written as follows:
<script src="https://res.zvo.cn/translate/translate.js"></script>
<script>
translate.language.setLocal('english');
translate.service.use('client.edge');
translate.execute();
</script>
These instructions provide the foundation for translating webpage content. Additional configuration can be added before calling translate.execute().
Official reference: translate.js GitHub Repository
One of the most useful aspects of translate.js is its extensive collection of fine-tuning instructions.
These instructions allow developers to control different parts of the translation process, customize the language selector, define translation rules, monitor dynamic content, and integrate custom translation functionality.
Instead of relying only on the default translation behavior, we can configure the library according to the requirements of our website.
These are selected instructions from the library's extension capabilities. Their exact arguments and configuration requirements should be checked in the official documentation before implementation.
For the complete list of customization options, visit: Official translate.js Documentation .
💡 My tip: You do not need to configure every available instruction. Start with basic translation and introduce additional controls only when your website requires them.
After exploring the library, I decided to use translate.js in my personal blog website, Madhurima Mindscape.
My goal was to provide visitors with an easy way to translate blog content without changing the existing page layout or introducing a complicated language configuration system.
Instead of displaying a traditional language selection dropdown permanently on the page, I implemented a floating language button positioned at the bottom-right corner.
When visitors click this button, a language selection panel appears. The panel contains a custom searchable dropdown where visitors can search for languages using their English names or native language names.
The implementation includes:
The implementation is divided into three main parts: HTML, CSS, and JavaScript.
First, I added a floating language button and a separate container for the translation selector.
<!-- Language Toggle Button -->
<button id="language-toggle"
class="language-toggle ignore"
type="button">
<i class="fa-solid fa-language language-icon"></i>
<span class="language-text">Lang</span>
</button>
<div id="translate-container"
class="translate-container">
</div>
The language-toggle button is responsible for opening and closing the language selection panel.
The translate-container element is where the custom language selector is dynamically generated using JavaScript.
I also added the ignore class to the floating button so that it remains unaffected by automatic translation.
I created a separate stylesheet named translate.css to keep the language selector styling independent from the rest of the website.
The main styling focuses on the floating button and the language selection panel.
Important CSS features include:
Here is a simplified example of the main CSS styling:
/* Floating Language Button */
.language-toggle {
position: fixed;
right: 25px;
bottom: 25px;
width: 55px;
height: 55px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: none;
border-radius: 50%;
background: var(--h2-color);
color: var(--post-action-color);
cursor: pointer;
z-index: 9999;
box-shadow: 0 3px 12px rgba(0,0,0,.18);
transition: .25s ease;
}
/* Language Selection Panel */
.translate-container {
display: none;
position: fixed;
right: 24px;
bottom: 80px;
width: 280px;
max-width: calc(100vw - 32px);
padding: 12px;
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,.15);
z-index: 9998;
}
/* Show Panel */
.translate-container.active {
display: block;
}
/* Searchable Language Options */
.language-dropdown-options {
max-height: 240px;
overflow-y: auto;
overflow-x: hidden;
}
/* Mobile Responsiveness */
@media (max-width: 480px) {
.language-toggle {
right: 16px;
bottom: 24px;
}
.translate-container {
right: 16px;
bottom: 90px;
width: 240px;
}
.language-dropdown-options {
max-height: 200px;
}
}
The complete stylesheet also includes additional styling for the dropdown trigger, search input, individual language options, selected states, scrollbar, and accessibility.
You can explore the complete CSS implementation here:
Next, I configured translate.js to use English as the original webpage language and selected the client.edge translation service.
// Set original webpage language
translate.language.setLocal('english');
// Select translation service
translate.service.use('client.edge');
// Set language selector container
translate.selectLanguageTag.documentId =
'translate-container';
translate.selectLanguageTag.show = true;
// Ignore language selector during translation
translate.ignore.id.push('translate-container');
// Monitor dynamically rendered content
translate.listener.start();
I also used the library's custom UI functionality through translate.selectLanguageTag.customUI to build my own searchable language dropdown instead of relying on the default selector.
The custom dropdown is generated dynamically from the language list provided by translate.js. I created the language options using JavaScript and added their English and native language names.
To make language selection easier, the dropdown also includes a search input that filters the available options as visitors type.
Another important feature I implemented was remembering the visitor's selected language across page visits.
For this, I used the browser's localStorage API.
const LANGUAGE_STORAGE_KEY = 'preferredLanguage';
// Retrieve saved language
function getSavedLanguage() {
return localStorage.getItem(LANGUAGE_STORAGE_KEY);
}
// Save selected language
function savePreferredLanguage(languageId) {
localStorage.setItem(
LANGUAGE_STORAGE_KEY,
languageId
);
}
Whenever a visitor selects a language, its language ID is saved in localStorage. When the page is opened again, JavaScript retrieves that saved preference and restores the selected language through the translation library.
I also added error handling around localStorage operations so that the translation interface can continue working if browser storage is unavailable.
The custom dropdown uses a hidden native select element to communicate with translate.js.
When a visitor selects a language, JavaScript:
The important integration instruction is:
select.addEventListener('change', function(event) {
translate.selectLanguageTag.selectOnChange(event);
});
This allows the custom interface to use translate.js for the actual language switching functionality.
Finally, I connected the floating language button to the translation container.
const button =
document.getElementById('language-toggle');
const container =
document.getElementById('translate-container');
if (button && container) {
button.addEventListener('click', function() {
container.classList.toggle('active');
});
}
Clicking the button toggles the visibility of the language selection panel. Visitors can then open the searchable dropdown and select their preferred language.
I also implemented outside-click handling to close the dropdown when visitors interact elsewhere on the page.
The complete JavaScript implementation contains additional logic for language sorting, searching, saved preference restoration, dropdown accessibility, and translation initialization.
You can explore the complete JavaScript source here:
💡 My tip: Keeping the translation library configuration, custom dropdown logic, and CSS styling organized makes the implementation easier to maintain and customize.
In my personal blog, I separated the language selector into dedicated CSS and JavaScript files instead of placing everything directly inside the main HTML document.
The relevant project structure looks like this:
Madhurima-Mindscape/
│
├── css/
│ └── translate.css
│
├── js/
│ └── translate.js
│
└── blog.html
The HTML document contains the floating button and translation container. The CSS file manages the appearance and responsive layout, while the JavaScript file handles translation configuration and user interactions.
Complete source files:
This separation also makes it easier to reuse the language selector across different pages of the website.
A language selector should be convenient to use on both desktop and mobile devices.
For this reason, I included responsive CSS rules to adjust the floating button and language selection panel on smaller screens.
The mobile implementation includes:
I also used a search input so that visitors do not need to scroll through the entire language list to find a particular language.
The selected language is highlighted, making it easier to identify the currently active translation.
💡 My tip: When implementing a language selector with many options, a searchable dropdown provides a much better experience than a long, unfiltered list.
Although translate.js makes website translation easier, there are a few things developers should consider before using it.
It is also important to remember that automatic translation is different from professionally localized content. Important legal, technical, or business information may require human review.
translate.js provides considerably more functionality than basic webpage translation. Its customization instructions make it possible to adapt the library to different website requirements.
If you want to explore more advanced features, I recommend going through the official documentation and GitHub repository.
Useful Resources:
Exploring the original library alongside a practical implementation is a useful way to understand how its different features can be applied to real websites.
Building multilingual functionality does not always require a complicated internationalization system. JavaScript libraries such as translate.js provide a convenient way to introduce automatic translation into existing websites.
In this tutorial, we explored the basic setup of translate.js, its translation service configuration, language selection functionality, and several advanced customization instructions.
We also explored my practical implementation in Madhurima Mindscape, where I created a floating language button with a searchable dropdown, responsive styling, and localStorage-based language preference persistence.
What I particularly like about this implementation is that it keeps the language selector separate from the main website layout while providing visitors with an accessible way to switch between languages.
If you are developing a personal blog, portfolio, documentation website, or another HTML-based project, translate.js is worth exploring for its flexible translation and customization capabilities.
"Good web development is not just about adding functionality. It is also about making that functionality accessible and convenient for everyone."
Want to explore the complete implementation? Check out the translate.js library and my personal blog's source code.
Leave a comment 💬
Choose a message to share your thoughts about this article.
Your email app will open with your comment ready to send.