| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							| 
									
										
										
										
											2023-10-18 16:00:56 +08:00
										 |  |  | import React, { useEffect } from 'react' | 
					
						
							|  |  |  | import { changeLanguage } from '@/i18n/i18next-config' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import I18NContext from '@/context/i18n' | 
					
						
							|  |  |  | import type { Locale } from '@/i18n' | 
					
						
							| 
									
										
										
										
											2024-02-23 14:31:06 +08:00
										 |  |  | import { setLocaleOnClient } from '@/i18n' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type II18nProps = { | 
					
						
							|  |  |  |   locale: Locale | 
					
						
							|  |  |  |   children: React.ReactNode | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const I18n: FC<II18nProps> = ({ | 
					
						
							| 
									
										
										
										
											2023-10-18 16:00:56 +08:00
										 |  |  |   locale, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   children, | 
					
						
							|  |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2023-10-18 16:00:56 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     changeLanguage(locale) | 
					
						
							|  |  |  |   }, [locale]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <I18NContext.Provider value={{ | 
					
						
							|  |  |  |       locale, | 
					
						
							| 
									
										
										
										
											2024-01-11 11:08:32 +08:00
										 |  |  |       i18n: {}, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       setLocaleOnClient, | 
					
						
							|  |  |  |     }}> | 
					
						
							|  |  |  |       {children} | 
					
						
							|  |  |  |     </I18NContext.Provider> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(I18n) |