Merge pull request #1306 from XieJiSS/master
fix: unicode-related error during .ts generation
This commit is contained in:
commit
19414c767b
@ -5,25 +5,36 @@ import os
|
|||||||
import glob
|
import glob
|
||||||
from tabnanny import check
|
from tabnanny import check
|
||||||
|
|
||||||
|
def pad_start(s, n, c = ' '):
|
||||||
|
if len(s) >= n:
|
||||||
|
return s
|
||||||
|
return c * (n - len(s)) + s
|
||||||
|
|
||||||
|
def safe_unicode(s):
|
||||||
|
res = ""
|
||||||
|
for c in s:
|
||||||
|
res += r"\u{}".format(pad_start(hex(ord(c))[2:], 4, '0'))
|
||||||
|
return res
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print('export const LANGS = {')
|
print('export const LANGS = {')
|
||||||
for fn in glob.glob('../../../src/lang/*'):
|
for fn in glob.glob('../../../src/lang/*'):
|
||||||
lang = os.path.basename(fn)[:-3]
|
lang = os.path.basename(fn)[:-3]
|
||||||
if lang == 'template': continue
|
if lang == 'template': continue
|
||||||
print(' %s: {'%lang)
|
print(' %s: {'%lang)
|
||||||
for ln in open(fn):
|
for ln in open(fn, encoding='utf-8'):
|
||||||
ln = ln.strip()
|
ln = ln.strip()
|
||||||
if ln.startswith('("'):
|
if ln.startswith('("'):
|
||||||
toks = ln.split('", "')
|
toks = ln.split('", "')
|
||||||
assert(len(toks) == 2)
|
assert(len(toks) == 2)
|
||||||
a = toks[0][2:]
|
a = toks[0][2:]
|
||||||
b = toks[1][:-3]
|
b = toks[1][:-3]
|
||||||
print(' "%s": "%s",'%(a, b))
|
print(' "%s": "%s",'%(safe_unicode(a), safe_unicode(b)))
|
||||||
print(' },')
|
print(' },')
|
||||||
print('}')
|
print('}')
|
||||||
check_if_retry = ['', False]
|
check_if_retry = ['', False]
|
||||||
KEY_MAP = ['', False]
|
KEY_MAP = ['', False]
|
||||||
for ln in open('../../../src/client.rs'):
|
for ln in open('../../../src/client.rs', encoding='utf-8'):
|
||||||
ln = ln.strip()
|
ln = ln.strip()
|
||||||
if 'check_if_retry' in ln:
|
if 'check_if_retry' in ln:
|
||||||
check_if_retry[1] = True
|
check_if_retry[1] = True
|
||||||
@ -55,7 +66,7 @@ def main():
|
|||||||
print('export const KEY_MAP: any = {')
|
print('export const KEY_MAP: any = {')
|
||||||
print(KEY_MAP[0])
|
print(KEY_MAP[0])
|
||||||
print('}')
|
print('}')
|
||||||
for ln in open('../../../Cargo.toml'):
|
for ln in open('../../../Cargo.toml', encoding='utf-8'):
|
||||||
if ln.startswith('version ='):
|
if ln.startswith('version ='):
|
||||||
print('export const ' + ln)
|
print('export const ' + ln)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user