Skip to content

Commit

Permalink
[Penify]: Documentation for commit - 7ddb08f (#264)
Browse files Browse the repository at this point in the history
Co-authored-by: penify-dev[bot] <146478655+penify-dev[bot]@users.noreply.github.com>
  • Loading branch information
penify-dev[bot] authored Sep 1, 2024
1 parent 7ddb08f commit 3364e0b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Components/LanguageSwitcher.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
import React from "react";
import { useTranslation } from "react-i18next";

/**
* A functional component that provides a language switcher for the application.
* It allows users to change the application's language by clicking on buttons.
*
* @component
* @example
* return (
* <LanguageSwitcher />
* );
*
* @returns {JSX.Element} A div containing buttons for switching languages.
* Each button, when clicked, changes the language of the application to the specified language.
*
* @throws {Error} Throws an error if the language change fails due to an invalid language code.
*/
const LanguageSwitcher = () => {
const { i18n } = useTranslation();
/**
* Changes the current language of the application.
*
* This function utilizes the i18n library to switch the language
* based on the provided language code. It is important to ensure
* that the language code passed is supported by the i18n configuration.
*
* @param {string} lng - The language code to switch to (e.g., 'en', 'fr', 'es').
* @throws {Error} Throws an error if the provided language code is not supported.
*
* @example
* // Change the language to French
* changeLanguage('fr');
*/
const changeLanguage = (lng) => {
i18n.changeLanguage(lng);
};
Expand Down

0 comments on commit 3364e0b

Please sign in to comment.