translation.py 916 B

12345678910111213141516171819202122232425262728293031323334353637
  1. class translation:
  2. def __init__(self, content: str, success: bool = True) -> None:
  3. self.__success = success
  4. self.__content = content
  5. def __str__(self) -> str:
  6. return self.__content
  7. @property
  8. def text(self) -> str:
  9. return self.__content
  10. @property
  11. def valid(self) -> bool:
  12. return self.__success
  13. def format(self, params: dict) -> str:
  14. parts = self.__content.split("#{")
  15. results = parts.pop(0)
  16. for count in parts:
  17. elements = count.split("}")
  18. if len(elements) == 1:
  19. results.append(count)
  20. continue
  21. name = elements.pop(0).strip()
  22. rest = str("}").join(elements)
  23. if not name in params:
  24. results = results + rest
  25. continue
  26. results = results + str(params[name]) + rest
  27. return results