@@ -4,6 +4,21 @@ import React, { ReactNode, useEffect, useState } from 'react';
4
4
import { useTranslation } from 'react-i18next' ;
5
5
import { Loader } from '../components/common' ;
6
6
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
+
7
22
function getLocale ( locale : string ) : typeof enUS {
8
23
const LOCALES = {
9
24
en : enUS ,
@@ -18,8 +33,29 @@ function getLocale(locale: string): typeof enUS {
18
33
return locale in LOCALES ? LOCALES [ locale as LocalesType ] : LOCALES [ 'en' ] ;
19
34
}
20
35
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
+ * ```
23
59
*/
24
60
const ThemeProviderNexti18n : React . FunctionComponent < {
25
61
theme : Theme ;
0 commit comments