Drop Windows EXE support for gettext
This commit is contained in:
parent
89442a0e26
commit
995f5036ca
12
setup.py
12
setup.py
@ -7,8 +7,6 @@ import os.path
|
|||||||
import warnings
|
import warnings
|
||||||
import sys
|
import sys
|
||||||
import glob
|
import glob
|
||||||
import io
|
|
||||||
import zipfile
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
@ -27,15 +25,6 @@ except ImportError:
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def zipped_folder(topdir):
|
|
||||||
f = io.BytesIO()
|
|
||||||
zipf = zipfile.ZipFile(f, mode='w')
|
|
||||||
for dirpath, dirnames, filenames in os.walk(topdir):
|
|
||||||
for filename in filenames:
|
|
||||||
zipf.write(os.path.join(dirpath, filename))
|
|
||||||
zipf.close()
|
|
||||||
return f.getvalue()
|
|
||||||
|
|
||||||
py2exe_options = {
|
py2exe_options = {
|
||||||
"bundle_files": 1,
|
"bundle_files": 1,
|
||||||
"compressed": 1,
|
"compressed": 1,
|
||||||
@ -47,7 +36,6 @@ py2exe_options = {
|
|||||||
py2exe_console = [{
|
py2exe_console = [{
|
||||||
"script": "./youtube_dl/__main__.py",
|
"script": "./youtube_dl/__main__.py",
|
||||||
"dest_base": "youtube-dl",
|
"dest_base": "youtube-dl",
|
||||||
"other_resources": [(u'LOCALE_DATA', u'locale_data.zip', zipped_folder('share'))],
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
py2exe_params = {
|
py2exe_params = {
|
||||||
|
@ -32,7 +32,6 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import traceback
|
import traceback
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
import zipfile
|
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from .compat import (
|
from .compat import (
|
||||||
@ -2514,36 +2513,12 @@ class ISO3166Utils(object):
|
|||||||
return cls._country_map.get(code.upper())
|
return cls._country_map.get(code.upper())
|
||||||
|
|
||||||
|
|
||||||
def _load_exe_resource(res_type, res_name):
|
|
||||||
kernel32 = ctypes.windll.kernel32
|
|
||||||
|
|
||||||
exe_handle = 0 # NULL: Current process
|
|
||||||
|
|
||||||
res_info = kernel32.FindResourceW(exe_handle, res_name, res_type)
|
|
||||||
res_handle = kernel32.LoadResource(exe_handle, res_info)
|
|
||||||
res_data = kernel32.LockResource(res_handle)
|
|
||||||
res_len = kernel32.SizeofResource(exe_handle, res_info)
|
|
||||||
res_arr = ctypes.cast(res_data, ctypes.POINTER(ctypes.c_char))[:res_len]
|
|
||||||
return res_arr
|
|
||||||
|
|
||||||
|
|
||||||
def g(s):
|
def g(s):
|
||||||
DOMAIN = 'youtube_dl'
|
DOMAIN = 'youtube_dl'
|
||||||
lang, _ = locale.getdefaultlocale()
|
lang, _ = locale.getdefaultlocale()
|
||||||
try:
|
try:
|
||||||
t = gettext.translation(DOMAIN, find_file_in_root('share/locale/'), [lang])
|
t = gettext.translation(DOMAIN, find_file_in_root('share/locale/'), [lang])
|
||||||
except (OSError, IOError): # OSError for 3.3+ and IOError otherwise
|
except (OSError, IOError): # OSError for 3.3+ and IOError otherwise
|
||||||
t = None
|
|
||||||
|
|
||||||
if t is None and sys.platform == 'win32' and hasattr(sys, 'frozen'):
|
|
||||||
locale_data_zip = _load_exe_resource('LOCALE_DATA', 'LOCALE_DATA.ZIP')
|
|
||||||
f = io.BytesIO(locale_data_zip)
|
|
||||||
zipf = zipfile.ZipFile(f)
|
|
||||||
with zipf.open('share/locale/%s/LC_MESSAGES/%s.mo' % (lang, DOMAIN)) as mo_file:
|
|
||||||
t = gettext.GNUTranslations(mo_file)
|
|
||||||
zipf.close()
|
|
||||||
|
|
||||||
if t is None:
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
ret = t.gettext(s)
|
ret = t.gettext(s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user