Hi Friends,

Even as I launch this today ( my 80th Birthday ), I realize that there is yet so much to say and do. There is just no time to look back, no time to wonder,"Will anyone read these pages?"

With regards,
Hemen Parekh
27 June 2013

Now as I approach my 90th birthday ( 27 June 2023 ) , I invite you to visit my Digital Avatar ( www.hemenparekh.ai ) – and continue chatting with me , even when I am no more here physically

Friday, 23 May 2025

Language Selection

 Kishan

 

 

I hope following is useful

 

Hcp

 

 

===========================

 

 

I asked Manus :

 

Hey Manus bhai : Good Morning :

 

Take a look at the landing pages of www.HemenParekh.ai and www.My-Teacher.in . You will notice that it offers to user , a selection of any one out of 26 languages. A user can access the site, ONLY after she has chosen any one language . This selection, renders the entire site in that chosen language.

 

Can you guess what technology / software API , my developer colleague Kishan might have used for this functionality ? And , if I want him to implement the same effect on www.IndiaAGI.ai , can he do so with some simple / fast / FREE , technology ? “

 

 

Manus replied :

 

“  I've completed my analysis of the language selection functionality on www.HemenParekh.ai and www.My-Teacher.in, and have prepared recommendations for implementing similar functionality on www.IndiaAGI.ai.

 

Based on my examination, both sites use a similar approach where users must select one of 26 languages before accessing the site's content. This ensures the entire user experience is delivered in the user's preferred language from the start.

 

The implementation appears to be primarily JavaScript-based, likely using either:

 

1.     custom JavaScript implementation with language-specific JSON files containing translated content

2.     A lightweight i18n library such as Polyglot.js or i18next

3.      

4.     Client-side rendering where language preference is stored in localStorage or cookies

5.      

For www.IndiaAGI.ai, I recommend either Polyglot.js or a custom implementation with JSON files as the most suitable free and simple options:

 

Polyglot.js (developed by Airbnb) is extremely lightweight (35.5 kB, 10.5 kB gzipped), has a simple API with minimal learning curve, and handles basic pluralization. It's perfect for projects with straightforward translation needs.

 

custom implementation gives you complete control, has no external dependencies, and results in minimal bundle size.

 

This approach involves creating JSON files for each language, implementing a simple language switcher, storing preferences in localStorage, and applying translations to DOM elements.

 

I've prepared a detailed analysis document with implementation examples and code snippets that your developer colleague Kishan can use as a reference.

 

The solution is fast, simple, and completely free to implement.

 

 

# Analysis of Language Selection Functionality for www.IndiaAGI.ai

 

## Overview of Existing Implementations

 

After analyzing the landing pages of www.HemenParekh.ai and www.My-Teacher.in, I observed that both sites implement a similar language selection mechanism. Users are presented with a selection of 26 languages on the landing page, and they must choose one before accessing the site's content. This approach ensures that the entire user experience is delivered in the user's preferred language from the start.

 

### Key Observations:

 

1.     Both sites present a clean, visually appealing language selection interface with languages grouped by region (Indian languages and global languages).

 

2.     The language options include both the language name in English and in its native script.

 

 

3.     The implementation appears to be primarily JavaScript-based, with the language selection triggering a state change that affects the entire site's content.

 

4.     The console analysis did not reveal any specific third-party translation libraries, suggesting either a custom implementation or a lightweight solution.

 

 

 

## Likely Technologies Used

 

Based on my analysis, the language selection functionality on these websites is likely implemented using one of the following approaches:

 

1.     **Custom JavaScript implementation**

 

with language-specific JSON or JavaScript files containing translated content for each supported language. This approach is straightforward and doesn't require external dependencies.

 

2.     **Lightweight i18n library**

 

such as Polyglot.js or a simplified version of i18next, which manages translations through JSON files and provides methods for language switching.

 

3.     **Client-side rendering**

 

where the selected language preference is stored (in localStorage or cookies) and used to load the appropriate language pack when rendering the site content.

 

## Recommended Free and Simple Implementation Options

 

For implementing similar functionality on www.IndiaAGI.ai, I recommend the following free and simple options:

 

### 1. i18next

 

i18next is one of the most popular and comprehensive internationalization libraries for JavaScript. It's highly extensible, well-maintained, and has excellent documentation.

 

**Advantages:**

 

- Complete internationalization solution with 3.5 million weekly downloads

- Supports all major frameworks (React, Vue, Angular)

- Handles complex pluralization, number formatting, and date formatting

- Active community and regular updates

- Extensive plugin ecosystem

 

 

**Implementation Complexity:** Moderate

 

**Bundle Size:** 56.3 kB (14.8 kB gzipped)

 

### 2. Polyglot.js

 

Developed by Airbnb, Polyglot.js is a minimalist i18n library focused specifically on string translation and pluralization.

 

**Advantages:**

 

- Extremely lightweight (35.5 kB, 10.5 kB gzipped)

- Simple API with minimal learning curve

- Handles basic pluralization

- Perfect for smaller projects with straightforward translation needs

 

**Implementation Complexity:** Low

 

**Bundle Size:** 35.5 kB (10.5 kB gzipped)

 

 

### 3. Custom Implementation with JSON Files

 

For maximum simplicity and control, a custom implementation using plain JavaScript and JSON translation files can be very effective.

 

**Advantages:**

 

- No external dependencies

- Complete control over implementation

- Minimal bundle size

- Simplest approach for basic translation needs

 

**Implementation Complexity:** Low to Moderate

 

**Bundle Size:** Minimal (depends on implementation)

 

## Recommendation for www.IndiaAGI.ai

 

Based on the requirement for a simple, fast, and free solution, I recommend either **Polyglot.js** or a **custom implementation with JSON files** for www.IndiaAGI.ai.

 

### Why Polyglot.js:

 

Polyglot.js strikes an excellent balance between simplicity and functionality. It's lightweight enough to not impact page load times significantly, yet provides the essential features needed for a multilingual site. The implementation is straightforward:

 

1. Include the library in your project

2. Create JSON files for each supported language

3. Initialize Polyglot with the appropriate language data

4. Use the translation functions in your code

 

### Why Custom Implementation:

 

If even greater simplicity and smaller bundle size are priorities, a custom implementation can be very effective:

 

1. Create a JSON file for each language containing key-value pairs of translations

2. Implement a simple language switcher that loads the appropriate JSON file

3. Store the language preference in localStorage or cookies

4. Apply translations to DOM elements based on the loaded language data

 

## Implementation Example (Custom Approach)

 

Here's a simplified example of how a custom implementation might work:

 

```javascript

// Language selection functionality

document.addEventListener('DOMContentLoaded', function() {

  // Check if user has previously selected a language

  const savedLanguage = localStorage.getItem('selectedLanguage') || 'en';

 

  // If no language is selected yet, show language selection modal

  if (!savedLanguage || savedLanguage === 'none') {

    showLanguageSelector();

  } else {

    loadLanguage(savedLanguage);

  }

 

  // Set up language selection buttons

  document.querySelectorAll('.language-select-btn').forEach(button => {

    button.addEventListener('click', function() {

      const lang = this.getAttribute('data-lang');

      localStorage.setItem('selectedLanguage', lang);

      loadLanguage(lang);

      hideLanguageSelector();

    });

  });

});

 

// Load language data and apply translations

function loadLanguage(lang) {

  fetch(`/languages/${lang}.json`)

    .then(response => response.json())

    .then(translations => {

      // Store translations globally

      window.translations = translations;

     

      // Apply translations to all elements with data-i18n attribute

      document.querySelectorAll('[data-i18n]').forEach(element => {

        const key = element.getAttribute('data-i18n');

        if (translations[key]) {

          element.textContent = translations[key];

        }

      });

     

      // Set html lang attribute

      document.documentElement.lang = lang;

    });

}

 

function showLanguageSelector() {

  document.getElementById('language-selector').style.display = 'block';

}

 

function hideLanguageSelector() {

  document.getElementById('language-selector').style.display = 'none';

}

```

 

## Conclusion

 

Implementing a language selection functionality similar to www.HemenParekh.ai and www.My-Teacher.in for www.IndiaAGI.ai is entirely feasible using free and simple technologies.

 

The most straightforward approach would be either Polyglot.js or a custom implementation with JSON files, both of which provide a lightweight solution that won't impact site performance.

 

For the fastest implementation with minimal complexity, I recommend starting with the custom approach outlined above, which can be implemented in a matter of hours and easily extended as needed.

 

If more advanced features like pluralization or date formatting become necessary in the future, migrating to Polyglot.js or i18next would be a natural progression.

 

## References

 

1. i18next: https://www.i18next.com/

2. Polyglot.js: https://airbnb.io/polyglot.js/

3. JavaScript translation and localization guide: https://lokalise.com/blog/comparing-libraries-translating-js-apps/

4. The Best JavaScript I18n Libraries: https://phrase.com/blog/posts/the-best-javascript-i18n-libraries/

No comments:

Post a Comment