mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1907 from matmair/trans-improv
translation improvement
This commit is contained in:
commit
76572bf82f
3
.gitignore
vendored
3
.gitignore
vendored
@ -68,3 +68,6 @@ htmlcov/
|
|||||||
|
|
||||||
# Development files
|
# Development files
|
||||||
dev/
|
dev/
|
||||||
|
|
||||||
|
# Locale stats file
|
||||||
|
locale_stats.json
|
||||||
|
@ -7,12 +7,15 @@ as JSON objects and passing them to modal forms (using jQuery / bootstrap).
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
|
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
|
||||||
@ -802,6 +805,13 @@ class SettingsView(TemplateView):
|
|||||||
except:
|
except:
|
||||||
ctx["rates_updated"] = None
|
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
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ def keyvalue(dict, key):
|
|||||||
usage:
|
usage:
|
||||||
{% mydict|keyvalue:mykey %}
|
{% mydict|keyvalue:mykey %}
|
||||||
"""
|
"""
|
||||||
return dict[key]
|
return dict.get(key)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
|
@ -3,6 +3,7 @@ This script calculates translation coverage for various languages
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def calculate_coverage(filename):
|
def calculate_coverage(filename):
|
||||||
@ -36,8 +37,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
MY_DIR = os.path.dirname(os.path.realpath(__file__))
|
MY_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
LC_DIR = os.path.abspath(os.path.join(MY_DIR, '..', 'locale'))
|
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 = {}
|
||||||
|
locales_perc = {}
|
||||||
|
|
||||||
print("InvenTree translation coverage:")
|
print("InvenTree translation coverage:")
|
||||||
|
|
||||||
@ -64,5 +67,10 @@ if __name__ == '__main__':
|
|||||||
percentage = 0
|
percentage = 0
|
||||||
|
|
||||||
print(f"| {locale.ljust(4, ' ')} : {str(percentage).rjust(4, ' ')}% |")
|
print(f"| {locale.ljust(4, ' ')} : {str(percentage).rjust(4, ' ')}% |")
|
||||||
|
locales_perc[locale] = percentage
|
||||||
|
|
||||||
print("-" * 16)
|
print("-" * 16)
|
||||||
|
|
||||||
|
# write locale stats
|
||||||
|
with open(STAT_FILE, 'w') as target:
|
||||||
|
json.dump(locales_perc, target)
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
<form action="{% url 'set_language' %}" method="post">
|
<form action="{% url 'set_language' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input name="next" type="hidden" value="{% url 'settings' %}">
|
<input name="next" type="hidden" value="{% url 'settings' %}">
|
||||||
@ -80,8 +81,15 @@
|
|||||||
{% get_available_languages as LANGUAGES %}
|
{% get_available_languages as LANGUAGES %}
|
||||||
{% get_language_info_list for LANGUAGES as languages %}
|
{% get_language_info_list for LANGUAGES as languages %}
|
||||||
{% for language in languages %}
|
{% for language in languages %}
|
||||||
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
|
{% define language.code as lang_code %}
|
||||||
{{ language.name_local }} ({{ language.code }})
|
{% define locale_stats|keyvalue:lang_code as lang_translated %}
|
||||||
|
<option value="{{ lang_code }}"{% if lang_code == LANGUAGE_CODE %} selected{% endif %}>
|
||||||
|
{{ language.name_local }} ({{ lang_code }})
|
||||||
|
{% if lang_translated %}
|
||||||
|
{% blocktrans %}{{ lang_translated }}% translated{% endblocktrans %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No translations available' %}
|
||||||
|
{% endif %}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
@ -91,5 +99,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<h4>{% trans "Help the translation efforts!" %}</h4>
|
||||||
|
<p>{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the InvenTree web application is <a href="{{link}}">community contributed via crowdin</a>. Contributions are welcomed and encouraged.{% endblocktrans %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user