Syntax check `lang_en.txt`

Display correct line having issues
This commit is contained in:
3d-gussner 2022-01-10 09:52:43 +01:00
parent 687746a80a
commit db4859ce9a
1 changed files with 98 additions and 87 deletions

View File

@ -121,10 +121,11 @@ def parse_txt(lang, no_warning, warn_empty):
print(green("Start %s lang-check" % lang)) print(green("Start %s lang-check" % lang))
lines = 1 lines = 0
with open(file_path) as src: with open(file_path) as src:
while True: while True:
message = src.readline() message = src.readline()
lines += 1
#print(message) #Debug #print(message) #Debug
#check syntax 1st line starts with `#MSG` #check syntax 1st line starts with `#MSG`
if (message[0:4] != '#MSG'): if (message[0:4] != '#MSG'):
@ -151,7 +152,7 @@ def parse_txt(lang, no_warning, warn_empty):
if cols is None and rows is None: if cols is None and rows is None:
if not no_warning: if not no_warning:
print(yellow("[W]: No display definition on line %d" % lines)) print(yellow("[W]: No display definition on line %d" % lines))
cols = len(translation) # propably fullscreen cols = len(source) # propably fullscreen
if rows is None: if rows is None:
rows = 1 rows = 1
elif rows > 1 and cols != 20: elif rows > 1 and cols != 20:
@ -159,32 +160,35 @@ def parse_txt(lang, no_warning, warn_empty):
#Wrap text to 20 chars and rows #Wrap text to 20 chars and rows
source = src.readline()[:-1] #read whole line source = src.readline()[:-1] #read whole line
lines += 1
#check if 2nd line of origin message beginns and ends with " double quote #check if 2nd line of origin message beginns and ends with " double quote
if (source[0]!="\""): if (source[0]!="\""):
print(red('[E]: Critical syntax error: Missing " at beginning of message in source on line %d' % lines)) print(red('[E]: Critical syntax error: Missing " double quotes at beginning of message in source on line %d' % lines))
print(red(source)) print(red(source))
exit(1) exit(1)
if (source[-1]=="\""): if (source[-1]=="\""):
source = source.strip('"') #remove " double quotes from message source = source.strip('"') #remove " double quotes from message
else: else:
print(red('[E]: Critical syntax error: Missing " at end of message in source on line %d' % lines)) print(red('[E]: Critical syntax error: Missing " double quotes at end of message in source on line %d' % lines))
print(red(source)) print(red(source))
exit(1) exit(1)
#print(source) #Debug #print(source) #Debug
if lang != "en":
translation = src.readline()[:-1]#read whole line translation = src.readline()[:-1]#read whole line
lines += 1
#check if 3rd line of translation message beginns and ends with " double quote #check if 3rd line of translation message beginns and ends with " double quote
if (translation[0]!="\""): if (translation[0]!="\""):
print(red('[E]: Critical syntax error: Missing " at beginning of message in translation on line %d' % lines)) print(red('[E]: Critical syntax error: Missing " double quotes at beginning of message in translation on line %d' % lines))
print(red(translation)) print(red(translation))
exit(1) exit(1)
if (translation[-1]=="\""): if (translation[-1]=="\""):
#print ("End ok") #print ("End ok")
translation = translation.strip('"') #remove " double quote from message translation = translation.strip('"') #remove " double quote from message
else: else:
print(red('[E]: Critical syntax error: Missing " at end of message in translation on line %d' % lines)) print(red('[E]: Critical syntax error: Missing " double quotes at end of message in translation on line %d' % lines))
print(red(translation)) print(red(translation))
exit(1) exit(1)
#print (translation) #print(translation) #Debug
if translation == '\\x00': if translation == '\\x00':
# crude hack to handle intentionally-empty translations # crude hack to handle intentionally-empty translations
translation = '' translation = ''
@ -194,6 +198,7 @@ def parse_txt(lang, no_warning, warn_empty):
print(red(source)) print(red(source))
exit(1) exit(1)
#check if translation is ascii only #check if translation is ascii only
if lang != "en":
if translation.isascii() == False: if translation.isascii() == False:
print(red('[E]: Critical syntax: Non ascii chars found on line %d' % lines)) print(red('[E]: Critical syntax: Non ascii chars found on line %d' % lines))
print(red(translation)) print(red(translation))
@ -201,11 +206,13 @@ def parse_txt(lang, no_warning, warn_empty):
# handle backslash sequences # handle backslash sequences
source = unescape(source) source = unescape(source)
if lang != "en":
translation = unescape(translation) translation = unescape(translation)
#print (translation) #Debug #print (translation) #Debug
wrapped_source = wrap_text(source, cols) wrapped_source = wrap_text(source, cols)
rows_count_source = len(wrapped_source) rows_count_source = len(wrapped_source)
if lang != "en":
wrapped_translation = wrap_text(translation, cols) wrapped_translation = wrap_text(translation, cols)
rows_count_translation = len(wrapped_translation) rows_count_translation = len(wrapped_translation)
@ -224,6 +231,7 @@ def parse_txt(lang, no_warning, warn_empty):
print() print()
# Missing translation # Missing translation
if lang != "en":
if len(translation) == 0 and (warn_empty or rows > 1): if len(translation) == 0 and (warn_empty or rows > 1):
if rows == 1: if rows == 1:
print(yellow("[W]: Empty translation for \"%s\" on line %d" % (source, lines))) print(yellow("[W]: Empty translation for \"%s\" on line %d" % (source, lines)))
@ -284,10 +292,13 @@ def parse_txt(lang, no_warning, warn_empty):
print_source_translation(source, translation, print_source_translation(source, translation,
wrapped_source, wrapped_translation, wrapped_source, wrapped_translation,
rows, cols) rows, cols)
if len(src.readline()) != 1: # empty line delimiter = src.readline()
print(red('[E]: Critical Syntax error: Missing empty line between messages between lines: %d and %d' % (lines+3,lines+4))) lines += 1
if ("" == delimiter):
break
elif len(delimiter) != 1: # empty line
print(red('[E]: Critical Syntax error: Missing empty line between messages between lines: %d and %d' % (lines-1,lines)))
break break
lines += 4
print(green("End %s lang-check" % lang)) print(green("End %s lang-check" % lang))