| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   createContext, | 
					
						
							|  |  |  |   useContext, | 
					
						
							|  |  |  | } from 'use-context-selector' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import type { Locale } from '@/i18n' | 
					
						
							| 
									
										
										
										
											2025-04-30 14:58:49 +08:00
										 |  |  | import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n/language' | 
					
						
							| 
									
										
										
										
											2025-04-09 12:10:17 +08:00
										 |  |  | import { noop } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type II18NContext = { | 
					
						
							|  |  |  |   locale: Locale | 
					
						
							| 
									
										
										
										
											2023-08-23 13:54:40 +08:00
										 |  |  |   i18n: Record<string, any> | 
					
						
							| 
									
										
										
										
											2024-04-29 17:55:52 +08:00
										 |  |  |   setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const I18NContext = createContext<II18NContext>({ | 
					
						
							| 
									
										
										
										
											2024-02-23 14:31:06 +08:00
										 |  |  |   locale: 'en-US', | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   i18n: {}, | 
					
						
							| 
									
										
										
										
											2025-04-09 12:10:17 +08:00
										 |  |  |   setLocaleOnClient: noop, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | export const useI18N = () => useContext(I18NContext) | 
					
						
							|  |  |  | export const useGetLanguage = () => { | 
					
						
							|  |  |  |   const { locale } = useI18N() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return getLanguage(locale) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-04-30 14:58:49 +08:00
										 |  |  | export const useGetDocLanguage = () => { | 
					
						
							|  |  |  |   const { locale } = useI18N() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return getDocLanguage(locale) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export const useGetPricingPageLanguage = () => { | 
					
						
							|  |  |  |   const { locale } = useI18N() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return getPricingPageLanguage(locale) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export default I18NContext |