Add locale_escape compat function
@@ -6,6 +6,7 @@ import ftfy
import sys
import ujson
import itertools
+import locale
from thinc.neural.util import copy_array
@@ -113,3 +114,12 @@ def import_file(name, loc):
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
+
+
+def locale_escape(string, errors='replace'):
+ '''
+ Mangle non-supported characters, for savages with ascii terminals.
+ '''
+ encoding = locale.getpreferredencoding()
+ string = string.encode(encoding, errors).decode('utf8')
+ return string
