fix: util translation helper
This commit is contained in:
		
							parent
							
								
									80fa6b9f94
								
							
						
					
					
						commit
						a8f6f5f776
					
				
					 4 changed files with 27 additions and 23 deletions
				
			
		
							
								
								
									
										18
									
								
								backend/src/util/translationHelper.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								backend/src/util/translationHelper.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | |||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import yaml from 'js-yaml'; | ||||
| 
 | ||||
| export function loadTranslations<T>(language: string): T { | ||||
|     try { | ||||
|         const filePath = path.join(process.cwd(), '_i18n', `${language}.yml`); | ||||
|         const yamlFile = fs.readFileSync(filePath, 'utf8'); | ||||
|         return yaml.load(yamlFile) as T; | ||||
|     } catch (error) { | ||||
|         console.error( | ||||
|             `Cannot load translation for ${language}, fallen back to dutch` | ||||
|         ); | ||||
|         console.error(error); | ||||
|         const fallbackPath = path.join(process.cwd(), '_i18n', 'nl.yml'); | ||||
|         return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as T; | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl