added testlang to help translators
This commit is contained in:
		
							parent
							
								
									dcc3bbaa60
								
							
						
					
					
						commit
						2e20c6cd91
					
				| @ -14,7 +14,8 @@ | |||||||
| 		"lint": "eslint src/**/*.{js,vue} --fix", | 		"lint": "eslint src/**/*.{js,vue} --fix", | ||||||
| 		"lint-tests": "eslint src/**/*.js --fix", | 		"lint-tests": "eslint src/**/*.js --fix", | ||||||
| 		"test": "jest", | 		"test": "jest", | ||||||
| 		"test-watch": "jest --watch" | 		"test-watch": "jest --watch", | ||||||
|  | 		"testlang": "node ./tests/testlang.js" | ||||||
| 	}, | 	}, | ||||||
| 	"dependencies": { | 	"dependencies": { | ||||||
| 		"@vue/composition-api": "1.0.6", | 		"@vue/composition-api": "1.0.6", | ||||||
|  | |||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										52
									
								
								tests/testlang.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								tests/testlang.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | |||||||
|  | async function loadLang(lang_id) { | ||||||
|  | 	let language_module | ||||||
|  | 	const result = [] | ||||||
|  | 	try { | ||||||
|  | 		language_module = await import(`../src/lang/${lang_id}.mjs`) | ||||||
|  | 		language_module = language_module.default | ||||||
|  | 	} catch (e) { | ||||||
|  | 		language_module = {} | ||||||
|  | 	} | ||||||
|  | 	function parseObject(obj, root = '') { | ||||||
|  | 		for (const [key, value] of Object.entries(obj)) { | ||||||
|  | 			if (typeof value === 'string') { | ||||||
|  | 				result.push(root + key) | ||||||
|  | 			} else { | ||||||
|  | 				parseObject(value, root + key + '.') | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	parseObject(language_module) | ||||||
|  | 	return result | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function testLang(lang_id) { | ||||||
|  | 	const baseLangFile = await loadLang('en') | ||||||
|  | 	const comparedLangFile = await loadLang(lang_id) | ||||||
|  | 
 | ||||||
|  | 	if (comparedLangFile.length === 0) { | ||||||
|  | 		console.log(`Language file ${lang_id} doesn't exist!`) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	console.log('\nMissing Keys:') | ||||||
|  | 	baseLangFile.forEach(key => { | ||||||
|  | 		if (!comparedLangFile.includes(key)) console.log(key) | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	console.log('\nExtra Keys:') | ||||||
|  | 	comparedLangFile.forEach(key => { | ||||||
|  | 		if (!baseLangFile.includes(key)) console.log(key) | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ;(async () => { | ||||||
|  | 	const args = process.argv.slice(2) | ||||||
|  | 	if (args.length !== 1) { | ||||||
|  | 		console.log('Usage:\nyarn testlang [COUNTRY_ID]\n') | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	console.log(`Testing language file ${args[0]}`) | ||||||
|  | 	await testLang(args[0]) | ||||||
|  | 	console.log('') | ||||||
|  | })() | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user