Prusa-Firmware/lang/lang-check.py
3d-gussner bd7bb5acb3
Update new messages and their translations (#2835)
* Add missing translations

* Add missing CZ and IT translations

* Update CZ, FR, IT, ES translations
CZ thanks to @DRracer
FR thanks to Carlin Dcustom
ES tried myself
IT thanks to @wavexx

Only missing is PL

* Improve wording +change keys

* Add missing PL translations

* Fix copy paste error in Italian
fix double translations

* Make PL translation shorter

* Fix some length issues and capital letters

* Fixed again translations length issues
updated po files

* Update FR translation - thanks @awenelo

* Fix execution of lang-check.py

- Make lang-check.py executable
- Execute directly instead of specifying the python interpreter manually
  ("python" is no longer available on Debian, and would default to
  version 2 prior to that despite being written for python 3)

* Fix permissions of translation files

Co-authored-by: D.R.racer <drracer@drracer.eu>
Co-authored-by: Yuri D'Elia <wavexx@thregr.org>
2020-09-18 16:50:25 +02:00

76 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Check lang files."""
from argparse import ArgumentParser
from traceback import print_exc
from sys import stderr
def parse_txt(lang, no_warning):
"""Parse txt file and check strings to display definition."""
if lang == "en":
file_path = "lang_en.txt"
else:
file_path = "lang_en_%s.txt" % lang
lines = 1
with open(file_path) as src:
while True:
comment = src.readline().split(' ')
src.readline() # source
translation = src.readline()[:-1]
cols = None
rows = None
for item in comment[1:]:
key, val = item.split('=')
if key == 'c':
cols = int(val)
elif key == 'r':
rows = int(val)
else:
raise RuntimeError(
"Unknown display definition %s on line %d" %
(' '.join(comment), lines))
if cols is None and rows is None:
if not no_warning:
print("[W]: No display definition on line %d" % lines)
cols = len(translation) # propably fullscreen
if rows is None:
rows = 1
if len(translation)-2 > cols*rows:
stderr.write(
"[E]: Text %s is longer then definiton on line %d\n" %
(translation, lines))
stderr.flush()
if len(src.readline()) != 1: # empty line
break
lines += 4
def main():
"""Main function."""
parser = ArgumentParser(
description=__doc__,
usage="$(prog)s lang")
parser.add_argument(
"lang", nargs='?', default="en", type=str,
help="Check lang file (en|cs|de|es|fr|it|pl)")
parser.add_argument(
"--no-warning", action="store_true",
help="Disable warnings")
args = parser.parse_args()
try:
parse_txt(args.lang, args.no_warning)
return 0
except Exception as exc:
print_exc()
parser.error("%s" % exc)
return 1
if __name__ == "__main__":
exit(main())