Skip to content

Commit 59b026a

Browse files
committed
frontend: tsdocs: Add TSDoc comments to ThemeProviderNexti18n.tsx
1 parent 48d6219 commit 59b026a

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

frontend/src/i18n/ThemeProviderNexti18n.tsx

+38-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import React, { ReactNode, useEffect, useState } from 'react';
44
import { useTranslation } from 'react-i18next';
55
import { Loader } from '../components/common';
66

7+
/**
8+
* Returns the Material UI locale object for the given language code.
9+
*
10+
* @remarks
11+
* This method retrieves the locale configuration for a specific language supported by
12+
* Material UI. It checks the provided language code against a predefined set of available locales,
13+
* and returns the corresponding locale object. If the language code is not found, it defaults to
14+
* English (`enUS`).
15+
*
16+
* @param locale - The language code for which the locale object is required (e.g., 'en', 'pt', 'es').
17+
*
18+
* @returns The Material UI locale object corresponding to the provided language code.
19+
* Defaults to `enUS` if the locale is not found in the predefined list.
20+
*/
21+
722
function getLocale(locale: string): typeof enUS {
823
const LOCALES = {
924
en: enUS,
@@ -18,8 +33,29 @@ function getLocale(locale: string): typeof enUS {
1833
return locale in LOCALES ? LOCALES[locale as LocalesType] : LOCALES['en'];
1934
}
2035

21-
/** Like a ThemeProvider but uses reacti18next for the language selection
22-
* Because Material UI is localized as well.
36+
/**
37+
* A custom theme provider component that integrates Material UI's theme with `react-i18next` for language selection.
38+
* It ensures that both the theme and language are synchronized, providing seamless localization across the application.
39+
*
40+
* @remarks
41+
* This component functions like a standard Material UI `ThemeProvider`, but it also listens for language changes using `react-i18next`.
42+
* When the language is changed, the corresponding Material UI locale is applied to update the theme accordingly.
43+
* This is essential for supporting multiple languages and ensuring the UI behaves correctly with Right-To-Left (RTL) languages.
44+
*
45+
* The component will show a loading state (`<Loader />`) until the i18n resources are ready for rendering.
46+
*
47+
* @param {object} props - The properties for the component.
48+
* @param {Theme} props.theme - The Material UI theme object to be applied to the app.
49+
* @param {ReactNode} props.children - The child components wrapped by this theme provider.
50+
*
51+
* @returns {ReactNode} The children components wrapped with the updated Material UI theme and language configurations.
52+
*
53+
* @example
54+
* ```tsx
55+
* <ThemeProviderNexti18n theme={theme}>
56+
* <YourComponent />
57+
* </ThemeProviderNexti18n>
58+
* ```
2359
*/
2460
const ThemeProviderNexti18n: React.FunctionComponent<{
2561
theme: Theme;

0 commit comments

Comments
 (0)