002-phrasebook.py 568 B

1234567891011121314151617181920212223242526272829
  1. import pathlib
  2. current = pathlib.Path(__file__).parent
  3. root = current.parent
  4. package = root / pathlib.Path("source")
  5. import sys
  6. sys.path.append(str(package))
  7. import cx_libtranslate
  8. phrases = {
  9. "sample": "Przyklad",
  10. "For example.": "Na przyklad."
  11. }
  12. objects = {
  13. "a": {
  14. "b": {
  15. "c": "result"
  16. }
  17. }
  18. }
  19. phrasebook = cx_libtranslate.phrasebook(phrases, objects)
  20. print(phrasebook.translate("sample"))
  21. print(phrasebook.translate("For example."))
  22. print(phrasebook.translate("This not exists."))
  23. print(phrasebook.translate("a.b.c"))