mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1240 from SchrodingersGat/translation-stats
Translation stats
This commit is contained in:
commit
1d6bd2c6ca
@ -28,8 +28,10 @@ def manually_translate_file(filename, save=False):
|
||||
print("For each missing translation:")
|
||||
print("a) Directly enter a new tranlation in the target language")
|
||||
print("b) Leave empty to skip")
|
||||
print("c) Press Ctrl+C to exit")
|
||||
|
||||
input("Press <ENTER> to continue")
|
||||
print("-------------------------")
|
||||
input("Press <ENTER> to start")
|
||||
print("")
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
@ -58,7 +60,10 @@ def manually_translate_file(filename, save=False):
|
||||
print("Source:", source_line)
|
||||
print("Enter translation for {t}".format(t=msgid))
|
||||
|
||||
try:
|
||||
translation = str(input(">"))
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
||||
if translation and len(translation) > 0:
|
||||
# Update the line with the new translation
|
||||
@ -71,7 +76,7 @@ def manually_translate_file(filename, save=False):
|
||||
output_file.writelines(out)
|
||||
|
||||
print("Translation done: written to", filename)
|
||||
print("Run 'make translate' to rebuild translation data")
|
||||
print("Run 'invoke translate' to rebuild translation data")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
68
InvenTree/script/translation_stats.py
Normal file
68
InvenTree/script/translation_stats.py
Normal file
@ -0,0 +1,68 @@
|
||||
"""
|
||||
This script calculates translation coverage for various languages
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def calculate_coverage(filename):
|
||||
"""
|
||||
Calculate translation coverage for a .po file
|
||||
"""
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
lines_count = 0
|
||||
lines_covered = 0
|
||||
lines_uncovered = 0
|
||||
|
||||
for line in lines:
|
||||
|
||||
if line.startswith("msgid "):
|
||||
lines_count += 1
|
||||
|
||||
elif line.startswith("msgstr"):
|
||||
if line.startswith('msgstr ""') or line.startswith("msgstr ''"):
|
||||
lines_uncovered += 1
|
||||
else:
|
||||
lines_covered += 1
|
||||
|
||||
# Return stats for the file
|
||||
return (lines_count, lines_covered, lines_uncovered)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
MY_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
LC_DIR = os.path.abspath(os.path.join(MY_DIR, '..', 'locale'))
|
||||
|
||||
locales = {}
|
||||
|
||||
print("InvenTree translation coverage:")
|
||||
|
||||
for locale in os.listdir(LC_DIR):
|
||||
path = os.path.join(LC_DIR, locale)
|
||||
if os.path.exists(path) and os.path.isdir(path):
|
||||
|
||||
locale_file = os.path.join(path, 'LC_MESSAGES', 'django.po')
|
||||
|
||||
if os.path.exists(locale_file) and os.path.isfile(locale_file):
|
||||
locales[locale] = locale_file
|
||||
|
||||
print("-" * 16)
|
||||
|
||||
for locale in locales.keys():
|
||||
locale_file = locales[locale]
|
||||
stats = calculate_coverage(locale_file)
|
||||
|
||||
(total, covered, uncovered) = stats
|
||||
|
||||
if total > 0:
|
||||
percentage = int(covered / total * 100)
|
||||
else:
|
||||
percentage = 0
|
||||
|
||||
print(f"| {locale.ljust(4, ' ')} : {str(percentage).rjust(4, ' ')}% |")
|
||||
|
||||
print("-" * 16)
|
Loading…
Reference in New Issue
Block a user