25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
1.2 KiB

  1. import re
  2. import sys
  3. errors_encounter = 0
  4. pattern = re.compile(r"_\(([\"']{,3})(?P<message>((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P<py_context>((?!\5).)*)\5)*(\s*,\s*(.)*?\s*(,\s*([\"'])(?P<js_context>((?!\11).)*)\11)*)*\)")
  5. start_pattern = re.compile(r"_{1,2}\([\"']{1,3}")
  6. # skip first argument
  7. files = sys.argv[1:]
  8. files_to_scan = [_file for _file in files if _file.endswith(('.py', '.js'))]
  9. for _file in files_to_scan:
  10. with open(_file, 'r') as f:
  11. print(f'Checking: {_file}')
  12. file_lines = f.readlines()
  13. for line_number, line in enumerate(file_lines, 1):
  14. start_matches = start_pattern.search(line)
  15. if start_matches:
  16. match = pattern.search(line)
  17. if not match and line.endswith(',\n'):
  18. # concat remaining text to validate multiline pattern
  19. line = "".join(file_lines[line_number - 1:])
  20. line = line[start_matches.start() + 1:]
  21. match = pattern.match(line)
  22. if not match:
  23. errors_encounter += 1
  24. print(f'\nTranslation syntax error at line number: {line_number + 1}\n{line.strip()[:100]}')
  25. if errors_encounter > 0:
  26. print('\nYou can visit "https://frappeframework.com/docs/user/en/translations" to resolve this error.')
  27. sys.exit(1)
  28. else:
  29. print('\nGood To Go!')