str_trans_eng.py 631 B

1234567891011121314151617181920212223
  1. # 替换字符串
  2. turkey_replace_dict = {
  3. 'ç': 'c', 'Ç': 'C',
  4. 'ğ': 'g', 'Ğ': 'G',
  5. 'ı': 'i', 'İ': 'I',
  6. 'ö': 'o', 'Ö': 'O',
  7. 'ş': 's', 'Ş': 'S',
  8. 'ü': 'u', 'Ü': 'U'
  9. }
  10. turkey_to_english_trans = str.maketrans(turkey_replace_dict)
  11. def replace_str_english(text: str, country_name: str) -> str or None:
  12. if text:
  13. if country_name == 'turkey':
  14. return text.translate(turkey_to_english_trans)
  15. return None
  16. if __name__ == '__main__':
  17. text = 'SÖZAL KİMYA SANAYİ VE TİCARET ANONİM ŞİRKETİ'
  18. english_text = replace_str_english(text, 'turkey')
  19. print(english_text)