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,25 +71,38 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<form action="{% url 'set_language' %}" method="post">
|
<div class="col">
|
||||||
{% csrf_token %}
|
<form action="{% url 'set_language' %}" method="post">
|
||||||
<input name="next" type="hidden" value="{% url 'settings' %}">
|
{% csrf_token %}
|
||||||
<div class="col-sm-6" style="width: 200px;"><div id="div_id_language" class="form-group"><div class="controls ">
|
<input name="next" type="hidden" value="{% url 'settings' %}">
|
||||||
<select name="language" class="select form-control">
|
<div class="col-sm-6" style="width: 200px;"><div id="div_id_language" class="form-group"><div class="controls ">
|
||||||
{% get_current_language as LANGUAGE_CODE %}
|
<select name="language" class="select form-control">
|
||||||
{% get_available_languages as LANGUAGES %}
|
{% get_current_language as LANGUAGE_CODE %}
|
||||||
{% get_language_info_list for LANGUAGES as languages %}
|
{% get_available_languages as LANGUAGES %}
|
||||||
{% for language in languages %}
|
{% get_language_info_list for LANGUAGES as languages %}
|
||||||
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
|
{% for language in languages %}
|
||||||
{{ language.name_local }} ({{ language.code }})
|
{% define language.code as lang_code %}
|
||||||
</option>
|
{% define locale_stats|keyvalue:lang_code as lang_translated %}
|
||||||
{% endfor %}
|
<option value="{{ lang_code }}"{% if lang_code == LANGUAGE_CODE %} selected{% endif %}>
|
||||||
</select>
|
{{ language.name_local }} ({{ lang_code }})
|
||||||
</div></div></div>
|
{% if lang_translated %}
|
||||||
<div class="col-sm-6" style="width: auto;">
|
{% blocktrans %}{{ lang_translated }}% translated{% endblocktrans %}
|
||||||
<input type="submit" value="{% trans 'Set Language' %}" class="btn btn btn-primary">
|
{% else %}
|
||||||
</div>
|
{% trans 'No translations available' %}
|
||||||
</form>
|
{% endif %}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div></div></div>
|
||||||
|
<div class="col-sm-6" style="width: auto;">
|
||||||
|
<input type="submit" value="{% trans 'Set Language' %}" class="btn btn btn-primary">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</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>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user