Multi Language

1. Add content

                        
// ----------------------------------------------------
// File: src/utils/languages/ar.json  
// ----------------------------------------------------  

{
  "Modern": "عصري",
  "Contacts":"جهات الاتصال",
  "Chats":"الدردشات"
}



// ----------------------------------------------------
// File: src/utils/languages/en.json  
// ----------------------------------------------------  

{
  "Modern": "Modern",
  "Contacts":"Contacts",
  "Chats":"Chats"
}



// ----------------------------------------------------
// File: src/utils/languages/ch.json  
// ----------------------------------------------------  

{
  "Modern": "現代的",
  "Contacts":"聯繫人",
  "Chats":"聊天記錄"
}



// ----------------------------------------------------
// File: src/utils/languages/fr.json  
// ---------------------------------------------------- 

{
  "Modern": "Moderne",
  "Contacts":"Les contacts",
  "Chats":"Chattes"
}

                        
                    

2. Usage


// --------------------------------------------------------------------
// File: src/app/(DashboardLayout)/layout/vertical/header/Language.tsx  
// --------------------------------------------------------------------

"use client";
import React, { useContext, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { CustomizerContext } from "@/app/context/CustomizerContext";
import Image from "next/image";
import {
  DropdownMenu,
  DropdownMenuTrigger,
  DropdownMenuContent,
  DropdownMenuItem,
} from "@/components/ui/dropdown-menu";

import engflag from "/public/images/flag/icon-flag-en.svg";
import cnflag from "/public/images/flag/icon-flag-cn.svg";
import frflag from "/public/images/flag/icon-flag-fr.svg";
import saflag from "/public/images/flag/icon-flag-sa.svg";

const Languages = [
  {
    flagname: "English (UK)",
    icon: engflag,
    value: "en",
  },
  {
    flagname: "中国人 (Chinese)",
    icon: cnflag,
    value: "ch",
  },
  {
    flagname: "français (French)",
    icon: frflag,
    value: "fr",
  },
  {
    flagname: "عربي (Arabic)",
    icon: saflag,
    value: "ar",
  },
];

export const Language = () => {
  const { i18n } = useTranslation();
  const { isLanguage, setIsLanguage } = useContext(CustomizerContext);

  const currentLang =
    Languages.find((_lang) => _lang.value === isLanguage) || Languages[1];

  useEffect(() => {
    i18n.changeLanguage(isLanguage);
  }, [isLanguage]);

  return (
    <div className="relative px-4">
      <DropdownMenu>
        <DropdownMenuTrigger asChild>
          <span className="relative after:absolute after:w-10 after:-top-1/2 after:h-10 after:rounded-full hover:after:bg-lightprimary rounded-full flex justify-center items-center cursor-pointer">
            <Image
              src={currentLang.icon}
              alt="language"
              className="rounded-full h-5 w-5 shrink-0 object-cover cursor-pointer"
            />
          </span>
        </DropdownMenuTrigger>

        <DropdownMenuContent className="w-56 rounded-sm p-1 z-50">
          {Languages.map((item, index) => (
            <DropdownMenuItem
              key={index}
              onSelect={() => setIsLanguage(item.value)}
              className="flex gap-3 items-center py-2 px-4 cursor-pointer hover:bg-muted"
            >
              <Image
                src={item.icon}
                alt={item.flagname}
                className="rounded-full object-cover h-5 w-5"
              />
              <span className="text-sm text-muted-foreground group-hover:text-primary font-medium leading-[25px]">
                {item.flagname}
              </span>
            </DropdownMenuItem>
          ))}
        </DropdownMenuContent>
      </DropdownMenu>
    </div>
  );
};