Internationalization i18n

This commit is contained in:
Reena-cell 2022-05-31 13:22:35 +02:00
parent 78d11a8303
commit 3cc6771514
6 changed files with 249 additions and 485 deletions

View File

@ -7,7 +7,7 @@
<!--<h1>Welcome to API Manager</h1>-->
<div class="well" id="intro">
<p>
{% trans "This app gives you access to management functionality for the OBP instance at" %} <a href="{{ API_HOST }}">{{ API_HOST }}</a>. {% trans "You have to" %}<a href="{{ API_HOST }}/user_mgt/sign_up" title="Register at {{ API_HOST }}">{% trans "register" %}</a> {% trans "an account before being able to proceed. The logged-in user needs to have specific roles granted to use the functionality." %}
{% trans "This app gives you access to management functionality for the OBP instance at" %} <a href="{{ API_HOST }}">{{ API_HOST }}</a>. {% trans "You have to" %}<a href="{{ API_HOST }}/user_mgt/sign_up" title="Register at {{ API_HOST }}"> {% trans "register" %} </a> {% trans "an account before being able to proceed" %}.{% trans "The logged-in user needs to have specific roles granted to use the functionality." %}
</p>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
from translate import Translator # Convert one language to another
from concurrent.futures import ThreadPoolExecutor as tpe # Multithreading
from threading import Lock # Locking Purpose
lock=Lock() # Intializing Lock
languages=['de','es','fr','hi'] # Defining languages
# This class is used for converting languages
class clsTranslate():
def translateText(self, strString, strTolang):
"""
This function translates one language into another language. It takes two
parameters
1. strString :=> String that you want to convert
2. strTolang :=> Languages(fr,hi,es etc)
"""
self.strString = strString
self.strTolang = strTolang
translator = Translator(to_lang=self.strTolang)
translation = translator.translate(self.strString)
return (str(translation))
# This is method for writing file
def writeFile(language):
print(language,"Started")
fileName=f'locale/{language}/LC_MESSAGES/django.po' # Openning a file
try:
with open(fileName,encoding='utf-8') as f: # Reading from the file
a=[i.replace("\n","") for i in f.readlines()] # Reading everyline from a file and store it into a
except Exception as e:
print(fileName, e)
b=0
for i in range(len(a)):
if 'msgid' in a[i] and a[i]!='msgid ""':
b=i
break
if b!=0:
trans=clsTranslate() # Creating object for translation class
for i in range(b-1,len(a)):
try:
if "msgid" in a[i]:
msgid,msgstr=a[i],a[i+1]
if msgstr == 'msgstr ""':
ms=msgid[7:len(msgid)-1]
val=trans.translateText(ms,language)
a[i+1]=f'msgstr "{val}"'
# print(a[i])
except: pass
try:
lock.acquire()
with open(fileName,'w',encoding='utf-8') as f:
for i in a:
f.write(f"{i}\n")
print(language,"is completed")
lock.release()
except Exception as e:
print(e)
lock.release()
else:
print(language,"is completed")
with tpe() as e:
e.map(writeFile,languages)

View File

@ -21,7 +21,7 @@
<div class="col-xs-6 col-sm-3">
{% if form.from_date.errors %}<div class="alert alert-danger">{{ form.from_date.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "from_date" %} </strong>
<strong>{% trans "from date" %} </strong>
{{ form.from_date }}
</div>
</div>
@ -52,7 +52,7 @@
<div class="col-xs-6 col-sm-3">
{% if form.consumer_id.errors %}<div class="alert alert-danger">{{ form.consumer_id.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "consumer_id" %} </strong>
<strong>{% trans "consumer id" %} </strong>
{{ form.consumer_id }}
</div>
</div>
@ -105,7 +105,7 @@
<div class="col-xs-7">
{% if form.implemented_by_partial_function.errors %}<div class="alert alert-danger">{{ form.implemented_by_partial_function.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "implemented_by_partial_function" %} </strong>
<strong>{% trans "implemented by partial function" %} </strong>
{{ form.implemented_by_partial_function }}
</div>
</div>
@ -113,7 +113,7 @@
<div class="col-xs-5">
{% if form.implemented_in_version.errors %}<div class="alert alert-danger">{{ form.implemented_in_version.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "implemented_in_version" %} </strong>
<strong>{% trans "implemented in version" %} </strong>
{{ form.implemented_in_version }}
</div>
</div>

View File

@ -19,21 +19,21 @@
<div class="col-xs-12 col-sm-4">
{% if form.bank_id.errors %}<div class="alert alert-danger">{{ form.bank_id.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "bank_id" %} </strong>
<strong>{% trans "Bank Id" %} </strong>
{{ form.bank_id }}
</div>
</div>
<div class="col-xs-12 col-sm-4">
{% if form.first_name.errors %}<div class="alert alert-danger">{{ form.first_name.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "first_name" %} </strong>
<strong>{% trans "First Name" %} </strong>
{{ form.first_name }}
</div>
</div>
<div class="col-xs-12 col-sm-4">
{% if form.last_name.errors %}<div class="alert alert-danger">{{ form.last_name.errors }}</div>{% endif %}
<div class="form-group">
<strong>{% trans "last_name" %} </strong>
<strong>{% trans "Last Name" %} </strong>
{{ form.last_name }}
</div>
</div>