forked from zguiy/utils
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			431 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			431 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import zh from './zh'
 | 
						|
import en from './en'
 | 
						|
import type { Language } from '@/types/tools'
 | 
						|
 | 
						|
export const locales = {
 | 
						|
  zh,
 | 
						|
  en
 | 
						|
}
 | 
						|
 | 
						|
export const getTranslation = (lang: Language = 'zh') => locales[lang]
 | 
						|
 | 
						|
export const t = (key: string, lang: Language = 'zh') => {
 | 
						|
  const keys = key.split('.')
 | 
						|
  let value: any = locales[lang]
 | 
						|
  
 | 
						|
  for (const k of keys) {
 | 
						|
    value = value?.[k]
 | 
						|
  }
 | 
						|
  
 | 
						|
  return value || key
 | 
						|
}
 | 
						|
 | 
						|
export default locales 
 |