Bravo Mart

View Categories

Language Translation Setup

< 1 min read

Easily add, remove, or manage translations using simple JSON files.

📂 1. Folder Structure #

All translation files must live inside the /public/locales directory.

Adding a New Language

Example:

public/

 └── locales/

      ├── en.json   // English

      ├── ar.json   // Arabic

      ├── es.json   // Spanish

      └── bn.json   // Bengali

Each file should contain key-value pairs of translations:

📄
public/locales/en.json
{
  "welcome": "Welcome",
  "logout": "Logout"
}

⚙️ 2. Available Locales Configuration #

The list of supported locales is defined

src/lib/language.ts

📄
src/lib/language.ts
export const availableLocales = ["en", "ar", "es"] as const;

export function getLanguageName(locale: string): string {
  switch (locale) {
    case "en":
      return "English";
    case "ar":
      return "Arabic";
    case "es":
      return "Spanish";
    default:
      return locale.toUpperCase();
  }
}

🔄 4. Fallback Behavior #

If a key is missing in the selected language, the system will fall back to English (en) by default.
Make sure at least en.json always exists and is complete.

Leave a Reply