39 lines
		
	
	
	
		
			947 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			947 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import argparse
 | |
| import json
 | |
| import sys
 | |
| from pathlib import Path
 | |
| from typing import Dict
 | |
| 
 | |
| MAIN_TL = Path("../translations/_main.json")
 | |
| 
 | |
| def check_translation(target: Path) -> bool:
 | |
|     with open(MAIN_TL) as f:
 | |
|         main_tl: Dict[str, str] = json.load(f)
 | |
|     with open(target) as f:
 | |
|         test_tl: Dict[str, str] = json.load(f)
 | |
|     
 | |
|     fail = False
 | |
| 
 | |
|     for k in test_tl.keys():
 | |
|         if k not in main_tl:
 | |
|             print("please remove: ", k)
 | |
|             fail = True
 | |
| 
 | |
|     # check for duplicate values
 | |
|     value_set = {}
 | |
|     for k, v in test_tl.items():
 | |
|         if v in value_set:
 | |
|             print(f"duplicate: `{v}` ({value_set[v]}, {k})")
 | |
|             fail = True
 | |
|         value_set[v] = k
 | |
| 
 | |
|     return fail
 | |
| 
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     parser = argparse.ArgumentParser()
 | |
|     parser.add_argument("tl_file", type=Path, help="Translation file")
 | |
|     args = parser.parse_args()
 | |
| 
 | |
|     if check_translation(args.tl_file):
 | |
|         sys.exit(1)
 |