diff --git a/.gitignore b/.gitignore index c53a837e24..5610fc4304 100644 --- a/.gitignore +++ b/.gitignore @@ -67,4 +67,7 @@ secret_key.txt htmlcov/ # Development files -dev/ \ No newline at end of file +dev/ + +# Locale stats file +locale_stats.json diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 9749fd60d0..69deb8fd97 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -7,12 +7,15 @@ as JSON objects and passing them to modal forms (using jQuery / bootstrap). # -*- coding: utf-8 -*- from __future__ import unicode_literals +import os +import json from django.utils.translation import gettext_lazy as _ from django.template.loader import render_to_string from django.http import HttpResponse, JsonResponse, HttpResponseRedirect from django.urls import reverse_lazy from django.shortcuts import redirect +from django.conf import settings from django.contrib.auth.mixins import PermissionRequiredMixin @@ -802,6 +805,13 @@ class SettingsView(TemplateView): except: ctx["rates_updated"] = None + # load locale stats + STAT_FILE = os.path.abspath(os.path.join(settings.BASE_DIR, 'InvenTree/locale_stats.json')) + try: + ctx["locale_stats"] = json.load(open(STAT_FILE, 'r')) + except: + ctx["locale_stats"] = {} + return ctx diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 5ebc939305..dce3d248e5 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -269,7 +269,7 @@ def keyvalue(dict, key): usage: {% mydict|keyvalue:mykey %} """ - return dict[key] + return dict.get(key) @register.simple_tag() diff --git a/InvenTree/script/translation_stats.py b/InvenTree/script/translation_stats.py index f47a21f168..c6126f2944 100644 --- a/InvenTree/script/translation_stats.py +++ b/InvenTree/script/translation_stats.py @@ -3,6 +3,7 @@ This script calculates translation coverage for various languages """ import os +import json def calculate_coverage(filename): @@ -36,8 +37,10 @@ if __name__ == '__main__': MY_DIR = os.path.dirname(os.path.realpath(__file__)) LC_DIR = os.path.abspath(os.path.join(MY_DIR, '..', 'locale')) + STAT_FILE = os.path.abspath(os.path.join(MY_DIR, '..', 'InvenTree/locale_stats.json')) locales = {} + locales_perc = {} print("InvenTree translation coverage:") @@ -64,5 +67,10 @@ if __name__ == '__main__': percentage = 0 print(f"| {locale.ljust(4, ' ')} : {str(percentage).rjust(4, ' ')}% |") + locales_perc[locale] = percentage print("-" * 16) + + # write locale stats + with open(STAT_FILE, 'w') as target: + json.dump(locales_perc, target) diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index 140d2f6b86..922e9ebc79 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -71,25 +71,38 @@
-
- {% csrf_token %} - -
- -
-
- -
-
+
+
+ {% csrf_token %} + +
+ +
+
+ +
+
+
+
+

{% trans "Help the translation efforts!" %}

+

{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the InvenTree web application is community contributed via crowdin. Contributions are welcomed and encouraged.{% endblocktrans %}

+
{% endblock %} \ No newline at end of file