__init__.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import gettext
  2. import os
  3. import six
  4. # Setup i18N
  5. #
  6. # Calling `gettext.install()` injects `_()` in the builtins namespace and
  7. # thus it becomes available globally (i.e. in the same process). Any python
  8. # code that needs to use _() should make sure that it firsts imports this
  9. # library.
  10. #
  11. # Note: we need to do this at the beginning of this module in order to
  12. # ensure that the injection happens before anything else gets imported.
  13. #
  14. # For more info please check the following links:
  15. # - https://docs.python.org/2/library/gettext.html#gettext.install
  16. # - https://pymotw.com/2//gettext/index.html#application-vs-module-localization
  17. # - https://www.wefearchange.org/2012/06/the-right-way-to-internationalize-your.html
  18. #
  19. _LOCALE_DIR = os.path.join(os.getenv("GISBASE"), 'locale')
  20. if six.PY2:
  21. gettext.install('grasslibs', _LOCALE_DIR, unicode=True)
  22. gettext.install('grassmods', _LOCALE_DIR, unicode=True)
  23. gettext.install('grasswxpy', _LOCALE_DIR, unicode=True)
  24. else:
  25. gettext.install('grasslibs', _LOCALE_DIR)
  26. gettext.install('grassmods', _LOCALE_DIR)
  27. gettext.install('grasswxpy', _LOCALE_DIR)
  28. __all__ = ["script", "temporal"]
  29. if os.path.exists(os.path.join(os.path.dirname(__file__), "lib", "__init__.py")):
  30. __all__.append("lib")