test_translations.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding=utf-8
  2. """Safe Translations Test.
  3. .. note:: This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. """
  8. from .utilities import get_qgis_app
  9. __author__ = 'ismailsunni@yahoo.co.id'
  10. __date__ = '12/10/2011'
  11. __copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
  12. 'Disaster Reduction')
  13. import unittest
  14. import os
  15. from PyQt5.QtCore import QCoreApplication, QTranslator
  16. QGIS_APP = get_qgis_app()
  17. class SafeTranslationsTest(unittest.TestCase):
  18. """Test translations work."""
  19. def setUp(self):
  20. """Runs before each test."""
  21. if 'LANG' in iter(os.environ.keys()):
  22. os.environ.__delitem__('LANG')
  23. def tearDown(self):
  24. """Runs after each test."""
  25. if 'LANG' in iter(os.environ.keys()):
  26. os.environ.__delitem__('LANG')
  27. def test_qgis_translations(self):
  28. """Test that translations work."""
  29. parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir)
  30. dir_path = os.path.abspath(parent_path)
  31. file_path = os.path.join(
  32. dir_path, 'i18n', 'af.qm')
  33. translator = QTranslator()
  34. translator.load(file_path)
  35. QCoreApplication.installTranslator(translator)
  36. expected_message = 'Goeie more'
  37. real_message = QCoreApplication.translate("@default", 'Good morning')
  38. self.assertEqual(real_message, expected_message)
  39. if __name__ == "__main__":
  40. suite = unittest.makeSuite(SafeTranslationsTest)
  41. runner = unittest.TextTestRunner(verbosity=2)
  42. runner.run(suite)