Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. # This script's purpose is to retrieve the translations from POEditor (https://poeditor.com).
  3. # It is mainly used in the release process.
  4. # (c) Jérôme Deuchnord - MIT License
  5. import os
  6. import requests
  7. POEDITOR_URL = 'https://api.poeditor.com/v2'
  8. API_TOKEN = os.environ['POEDITOR_API_ACCESS']
  9. PROJECT_ID = os.environ['POEDITOR_PROJECT_ID']
  10. languages = requests.post('%s/languages/list' % POEDITOR_URL,
  11. data={'api_token': API_TOKEN,
  12. 'id': PROJECT_ID})
  13. json = languages.json()
  14. if languages.status_code != 200:
  15. raise AssertionError(json['response']['message'])
  16. for language in json['result']['languages']:
  17. if language['percentage'] < 100:
  18. # Ignore unfinished translations
  19. continue
  20. print('Importing finished translation for %s... ' % language['name'], end='')
  21. translations = requests.post('%s/projects/export' % POEDITOR_URL,
  22. data={'api_token': API_TOKEN,
  23. 'id': PROJECT_ID,
  24. 'language': language['code'],
  25. 'type': 'po'})
  26. if translations.status_code != 200:
  27. print('Failed!')
  28. raise AssertionError(translations.json()['response']['message'])
  29. translations = requests.get(translations.json()['result']['url'])
  30. if translations.status_code != 200:
  31. print('Failed!')
  32. raise AssertionError('URL given by the API returned a %d status code' % translations.status_code)
  33. os.makedirs('kosmorrolib/locales/%s/LC_MESSAGES' % language['code'], exist_ok=True)
  34. with open('kosmorrolib/locales/%s/LC_MESSAGES/messages.po' % language['code'], 'w') as file:
  35. file.write(translations.text)
  36. print('OK')