translations.py 581 B

1234567891011121314151617181920212223242526
  1. import json
  2. import csv
  3. csv_file = 'bot/phrases.csv'
  4. json_file = 'bot/translations.json'
  5. def json_from_csv():
  6. phrases = {}
  7. with open(csv_file, 'r', encoding='utf-8') as file:
  8. reader = csv.reader(file)
  9. for row in reader:
  10. phrases[row[0]] = {'en': row[1], 'ru': row[2]}
  11. with open(json_file, 'w', encoding='utf-8') as file:
  12. json.dump(phrases, file, indent=4, ensure_ascii=False)
  13. def load_tr():
  14. with open(json_file, 'r', encoding='utf-8') as file:
  15. return json.load(file)
  16. if __name__ == '__main__':
  17. json_from_csv()