fix-gettext.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. commit 6df9d7282117d14575cba802978b635e0661ce0d
  2. merge: c7e3ec07a5a75dde4da2c0954eae709906150ee7 56e45ed36ba8ee900952583c2c47040314676f6a
  3. author: orlovgb
  4. date: 2019-08-28T21:12:31+03:00
  5. revision: 5552086
  6. fix py3 gettext to use resorces from __res
  7. Скопипастил с https://a.yandex-team.ru/arc/trunk/arcadia/contrib/tools/python/Lib/gettext.py
  8. Дописал, чтобы в resfs_src и resfs_read уходила байтовая строка
  9. REVIEW: 930161
  10. --- contrib/tools/python3/Lib/gettext.py (c7e3ec07a5a75dde4da2c0954eae709906150ee7)
  11. +++ contrib/tools/python3/Lib/gettext.py (6df9d7282117d14575cba802978b635e0661ce0d)
  12. @@ -49,7 +49,12 @@ import locale
  13. import os
  14. import re
  15. import sys
  16. +import io
  17. +try:
  18. + import __res
  19. +except ImportError:
  20. + __res = None
  21. __all__ = ['NullTranslations', 'GNUTranslations', 'Catalog',
  22. 'bindtextdomain', 'find', 'translation', 'install',
  23. @@ -492,7 +497,7 @@ def find(domain, localedir=None, languages=None, all=False):
  24. if lang == 'C':
  25. break
  26. mofile = os.path.join(localedir, lang, 'LC_MESSAGES', '%s.mo' % domain)
  27. - if os.path.exists(mofile):
  28. + if __res and __res.resfs_src(mofile.encode('utf-8'), resfs_file=True) or os.path.exists(mofile):
  29. if all:
  30. result.append(mofile)
  31. else:
  32. @@ -522,8 +527,12 @@ def translation(domain, localedir=None, languages=None,
  33. key = (class_, os.path.abspath(mofile))
  34. t = _translations.get(key)
  35. if t is None:
  36. - with open(mofile, 'rb') as fp:
  37. - t = _translations.setdefault(key, class_(fp))
  38. + mores = __res and __res.resfs_read(mofile.encode('utf-8'))
  39. + if mores:
  40. + t = _translations.setdefault(key, class_(io.BytesIO(mores)))
  41. + else:
  42. + with open(mofile, 'rb') as fp:
  43. + t = _translations.setdefault(key, class_(fp))
  44. # Copy the translation object to allow setting fallbacks and
  45. # output charset. All other instance data is shared with the
  46. # cached object.