Initial Multi Language Support

From this change onward all strings must tagged with oslo_i18n
translate tag.

Welcome multi language support and do not forget to tag missing
strings.

Change-Id: I9c59b2c91a31cb92abe1f0cb092efd611b300dfa
This commit is contained in:
Paarhati Ozkasgarli 2017-02-06 00:42:57 +03:00
parent 34af7eadf4
commit 29cbae8ff7
4 changed files with 57 additions and 8 deletions

View File

@ -1,22 +1,23 @@
import re import re
from oslo_i18n import translate as _
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django import forms from django import forms
class UserRegisterForm(forms.Form): class UserRegisterForm(forms.Form):
email = forms.EmailField(label='Email') email = forms.EmailField(label=_('Email'))
password1 = forms.CharField( password1 = forms.CharField(
label='Password', label=_('Password'),
widget=forms.PasswordInput(), widget=forms.PasswordInput(),
) )
password2 = forms.CharField( password2 = forms.CharField(
label='Password (Again)', label=_('Password (Again)'),
widget=forms.PasswordInput(), widget=forms.PasswordInput(),
) )
tos = forms.BooleanField( tos = forms.BooleanField(
required=True, required=True,
error_messages={'required': 'You must accept TOS.'} error_messages={'required': _('You must accept TOS.')}
) )
def clean_email(self): def clean_email(self):
@ -25,7 +26,7 @@ class UserRegisterForm(forms.Form):
User.objects.get(email=email) User.objects.get(email=email)
except ObjectDoesNotExist: except ObjectDoesNotExist:
return email return email
raise forms.ValidationError('Email address is not available.') raise forms.ValidationError(_('Email address is not available.'))
def clean_password2(self): def clean_password2(self):
if 'password1' in self.cleaned_data: if 'password1' in self.cleaned_data:
@ -33,4 +34,4 @@ class UserRegisterForm(forms.Form):
password2 = self.cleaned_data['password2'] password2 = self.cleaned_data['password2']
if password1 == password2: if password1 == password2:
return password2 return password2
raise forms.ValidationError('Password do not match.') raise forms.ValidationError(_('Password do not match.'))

View File

@ -1,5 +1,7 @@
import random, hashlib, datetime import random, hashlib, datetime
from oslo_i18n import translate as _
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
@ -27,6 +29,7 @@ def send_email(con,subject,email_to,email_from):
def index(request): def index(request):
return render(request, "authcp/index.html", {}) return render(request, "authcp/index.html", {})
# user registration
def register_user(request): def register_user(request):
if request.method == 'POST': if request.method == 'POST':
form = UserRegisterForm(request.POST) form = UserRegisterForm(request.POST)
@ -46,7 +49,7 @@ def register_user(request):
"%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
profile.save() profile.save()
send_email({'u': u, 'profil': profile}, send_email({'u': u, 'profil': profile},
'Welcome to our cloud', _('Welcome to our cloud'),
u.email, u.email,
settings.DEFAULT_EMAIL_FROM, settings.DEFAULT_EMAIL_FROM,
) )
@ -59,9 +62,11 @@ def register_user(request):
form = UserRegisterForm() form = UserRegisterForm()
return render(request, 'authcp/register.html', {'form': form}) return render(request, 'authcp/register.html', {'form': form})
# user registration success page
def register_success(request): def register_success(request):
return render(request, 'authcp/success.html', {}) return render(request, 'authcp/success.html', {})
# user activation
def activation(request, key): def activation(request, key):
activation_expired=False activation_expired=False
already_active=False already_active=False

View File

@ -12,7 +12,7 @@ _ = _translators.primary
# The contextual translation function using the name "_C" # The contextual translation function using the name "_C"
# requires oslo.i18n >=2.1.0 # requires oslo.i18n >=2.1.0
_C = _translators.contextual_form _C = _translators.contextual_form
ya
# The plural translation function using the name "_P" # The plural translation function using the name "_P"
# requires oslo.i18n >=2.1.0 # requires oslo.i18n >=2.1.0
_P = _translators.plural_form _P = _translators.plural_form

View File

@ -0,0 +1,43 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-05 21:41+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: authcp/forms.py:9
msgid "Email"
msgstr ""
#: authcp/forms.py:11
msgid "Password"
msgstr ""
#: authcp/forms.py:15
msgid "Password (Again)"
msgstr ""
#: authcp/forms.py:20
msgid "You must accept TOS."
msgstr ""
#: authcp/forms.py:29
msgid "Email address is not available."
msgstr ""
#: authcp/forms.py:37
msgid "Password do not match."
msgstr ""