From 3364e0bbe3f06920f4780fa64bb203ca4be2a742 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 01:41:12 +0100 Subject: [PATCH] [Penify]: Documentation for commit - 7ddb08f (#264) Co-authored-by: penify-dev[bot] <146478655+penify-dev[bot]@users.noreply.github.com> --- src/Components/LanguageSwitcher.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Components/LanguageSwitcher.js b/src/Components/LanguageSwitcher.js index 61ccd60..72c9195 100644 --- a/src/Components/LanguageSwitcher.js +++ b/src/Components/LanguageSwitcher.js @@ -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 ( + * + * ); + * + * @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); };