[cleanup] removed old translation format utility scripts

Dieser Commit ist enthalten in:
Reinder Feenstra 2025-12-13 23:34:12 +01:00
Ursprung ac9ef4ee49
Commit a1a0c284d0
5 geänderte Dateien mit 0 neuen und 120 gelöschten Zeilen

Datei anzeigen

@ -1,12 +0,0 @@
import sys
from traintastic import read_locale_file, write_locale_file
def format_locale(filename):
(strings, header, garbage) = read_locale_file(filename)
write_locale_file(filename, header, strings, garbage)
if __name__ == "__main__":
for f in sys.argv[1:]:
format_locale(f)

Datei anzeigen

@ -1,20 +0,0 @@
import sys
import os
import json
import codecs
from traintastic import read_locale_file
def to_json(filename_txt, filename_json):
(strings, header, garbage) = read_locale_file(filename_txt)
out = []
for s in strings:
if not s['hash']:
out.append({'term': s['id'], 'definition': s['value']})
with codecs.open(filename_json, 'w', 'utf-8') as f:
json.dump(out, f, indent=' ')
if __name__ == "__main__":
for f in sys.argv[1:]:
to_json(f, os.path.splitext(f)[0] + '.json')

Datei anzeigen

@ -1,16 +0,0 @@
import sys
from traintastic import read_locale_file, write_locale_file
def locale_add_missing(source, destination):
src_strings = read_locale_file(source)[0]
(strings, header, garbage) = read_locale_file(destination)
for src in src_strings:
if not any((s['id'] == src['id'] and s['ns'] == src['ns']) for s in strings):
src['hash'] = True
strings.append(src)
write_locale_file(destination, header, strings, garbage)
if __name__ == "__main__":
locale_add_missing(sys.argv[1], sys.argv[2])

Datei anzeigen

@ -1,15 +0,0 @@
import sys
from traintastic import read_locale_file, write_locale_file
def locale_remove_old(source, destination):
src_strings = read_locale_file(source)[0]
(strings, header, garbage) = read_locale_file(destination)
strings = list(filter(lambda s: any((s['id'] == src['id'] and s['ns'] == src['ns']) for src in src_strings), strings))
write_locale_file(destination, header, strings, garbage)
if __name__ == "__main__":
locale_remove_old(sys.argv[1], sys.argv[2])

Datei anzeigen

@ -1,57 +0,0 @@
import os
import re
import codecs
def read_locale_file(filename):
with codecs.open(filename, 'r', 'utf-8') as f:
lines = f.readlines()
header = ''
for line in lines:
if line.startswith('##'):
header += line
else:
break
r = re.compile(r'^(#|)(([a-z0-9_\.:]*):([a-z0-9_\.-]+|[DINWECF][0-9]{4}))=(.*)$')
strings = []
garbage = ''
for line in lines:
m = r.match(line)
if m is not None:
strings.append({
'id': m.group(2),
'ns': m.group(3),
'value': m.group(5),
'hash': m.group(1) == '#',
})
elif line != '\n' and line != '\r\n' and not line.startswith('##'):
garbage += line
return (strings, header, garbage)
def write_locale_file(filename, header, strings, garbage=''):
txt = header
ns = None
for s in sorted(strings, key=lambda k: k['id']):
if ns != s['ns']:
ns = s['ns']
txt += '\n'
txt += ('#' if s['hash'] else '') + s['id'] + '=' + s['value'] + '\n'
if garbage != '':
txt += '\n\n#! Garbage\n' + garbage
i = 0
while True:
backup = filename + '~' + str(i)
if not os.path.exists(backup):
break
i += 1
os.rename(filename, backup)
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(txt)