i18n_check.py 1020 B

123456789101112131415161718192021222324252627282930
  1. """Handle a hash digest of the translatable strings."""
  2. # Copyright (c) 2021 Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from hashlib import sha256
  5. from pathlib import Path
  6. from tempfile import TemporaryDirectory
  7. import polib
  8. from jupyterlab_translate.api import extract_language_pack
  9. HERE = Path(__file__).parent
  10. if __name__ == "__main__":
  11. with TemporaryDirectory() as tmp_dir:
  12. extract_language_pack(HERE.parent, tmp_dir, "jupyterlab", False)
  13. pot = polib.pofile(
  14. str(Path(tmp_dir) / "jupyterlab" / "locale" / "jupyterlab.pot"),
  15. wrapwidth=100000,
  16. )
  17. hash = sha256()
  18. # Use only the context and the id as the position may changed without impact
  19. # Sort the entry because the order in the POT file may changed (likely because code position changed)
  20. for entry in sorted(map(lambda e: f"{e.msgctxt!s} {e.msgid!s}", pot)):
  21. hash.update(entry.encode("utf-8"))
  22. proof = hash.hexdigest()
  23. print(proof)