hiteshchoudhary / apihub

Your own API Hub to learn and master API interaction. Ideal for frontend, mobile dev and backend developers.
https://freeapi.app
Other
3.62k stars 836 forks source link

FEATURE: Adding Internationalization (i18n) #174

Open ram-prasad23 opened 3 months ago

ram-prasad23 commented 3 months ago

Describe the Feature

Feature Request: Internationalization (i18n) Support

Summary

Add support for Internationalization (i18n) to the backend to handle requests in multiple languages. When a request comes with a query parameter lg=ta (Tamil) or lg=en (English), the response should be in the requested language. If the query parameter is not present or the requested language is not supported, the response should default to English.

Description

The goal is to implement i18n support in the Node.js backend to enhance user experience by providing responses in their preferred language. This feature will detect the language from the query parameter lg in the request URL and send the response in the corresponding language. If the requested language is not supported or the lg parameter is not provided, the response will default to English.

Implementation Steps

  1. Add Dependencies:

    • Use a library like i18n or i18next to handle translation files and middleware setup.
    • Ensure to update package.json with the new dependencies.
  2. Set Up Middleware:

    • Create middleware to detect the lg parameter from the request URL.
    • Load the appropriate language file based on the lg parameter or default to English.
  3. Create Translation Files:

    • Set up translation JSON files for supported languages (e.g., en.json for English, ta.json for Tamil).
    • Place translation files in a directory structure that the i18n library can easily access.
  4. Update Responses:

    • Modify existing endpoints to use the i18n library to return translated responses.
    • Ensure that dynamic content in responses also gets translated.

Use Case

Example

Response (Tamil)


{
  "status":200,
  "message": "வணக்கம், இது உங்கள் கோரிக்கைக்கு பதிலாக இருக்கும்."
}

### Additional Information

_No response_

### Suggested Tools

i18n

### Additional Context or Information

_No response_