JhohannesK / TipoHiZ

A typing website made for everyone
https://tipohiz.vercel.app/
GNU General Public License v3.0
16 stars 33 forks source link

Implement Language Toggle Feature for English and French #136

Closed Mefisto04 closed 23 hours ago

Mefisto04 commented 23 hours ago

Pull Request Description

Overview

This pull request introduces a language toggle feature that allows users to switch between English and French within the application. The changes enable dynamic loading of corresponding language files for the text area, enhancing the user experience for bilingual users.

Code Changes

  1. HomePage Component

    • Introduced a state variable language to track the current language, initialized to English.
    • Added a toggleLanguage function to switch between English and French when the language text is clicked.
    • Passed the language state as a prop to the TextArea component.
    const [language, setLanguage] = useState<'english' | 'french'>('english');
    
    const toggleLanguage = () => {
      setLanguage((prev) => (prev === 'english' ? 'french' : 'english'));
    };
  2. TextArea Component

    • Modified the useEffect hook to dynamically import the correct JSON language file based on the language prop received from HomePage.
    React.useEffect(() => {
      import(`../modules/TextFiles/${language === 'english' ? 'English' : 'French'}/${type}.json`).then((word) => {
         setWordList(word.default);
      });
    }, [type, language]);

User Interface Changes

vercel[bot] commented 23 hours ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tipohiz ❌ Failed (Inspect) Oct 5, 2024 10:38am