transutils.py 768 B

1234567891011121314151617181920212223
  1. """Translation related utilities. When imported, injects _ to builtins"""
  2. # Copyright (c) Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import gettext
  5. import os
  6. import warnings
  7. def _trans_gettext_deprecation_helper(*args, **kwargs):
  8. """The trans gettext deprecation helper."""
  9. warn_msg = "The alias `_()` will be deprecated. Use `_i18n()` instead."
  10. warnings.warn(warn_msg, FutureWarning, stacklevel=2)
  11. return trans.gettext(*args, **kwargs)
  12. # Set up message catalog access
  13. base_dir = os.path.realpath(os.path.join(__file__, "..", ".."))
  14. trans = gettext.translation(
  15. "notebook", localedir=os.path.join(base_dir, "notebook/i18n"), fallback=True
  16. )
  17. _ = _trans_gettext_deprecation_helper
  18. _i18n = trans.gettext