From 29cbae8ff76b15793d05a1b0b3b213eb23c305ff Mon Sep 17 00:00:00 2001 From: Paarhati Ozkasgarli Date: Mon, 6 Feb 2017 00:42:57 +0300 Subject: [PATCH] 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 --- authcp/forms.py | 13 +++++----- authcp/views.py | 7 +++++- dash_stack_dashboard/_i18n.py | 2 +- locale/tr/LC_MESSAGES/django.po | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 locale/tr/LC_MESSAGES/django.po diff --git a/authcp/forms.py b/authcp/forms.py index 5b1a9f8..83cfd55 100644 --- a/authcp/forms.py +++ b/authcp/forms.py @@ -1,22 +1,23 @@ import re +from oslo_i18n import translate as _ from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django import forms class UserRegisterForm(forms.Form): - email = forms.EmailField(label='Email') + email = forms.EmailField(label=_('Email')) password1 = forms.CharField( - label='Password', + label=_('Password'), widget=forms.PasswordInput(), ) password2 = forms.CharField( - label='Password (Again)', + label=_('Password (Again)'), widget=forms.PasswordInput(), ) tos = forms.BooleanField( required=True, - error_messages={'required': 'You must accept TOS.'} + error_messages={'required': _('You must accept TOS.')} ) def clean_email(self): @@ -25,7 +26,7 @@ class UserRegisterForm(forms.Form): User.objects.get(email=email) except ObjectDoesNotExist: return email - raise forms.ValidationError('Email address is not available.') + raise forms.ValidationError(_('Email address is not available.')) def clean_password2(self): if 'password1' in self.cleaned_data: @@ -33,4 +34,4 @@ class UserRegisterForm(forms.Form): password2 = self.cleaned_data['password2'] if password1 == password2: return password2 - raise forms.ValidationError('Password do not match.') + raise forms.ValidationError(_('Password do not match.')) diff --git a/authcp/views.py b/authcp/views.py index 3e6794b..c5a8785 100644 --- a/authcp/views.py +++ b/authcp/views.py @@ -1,5 +1,7 @@ import random, hashlib, datetime +from oslo_i18n import translate as _ + from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.core.mail import EmailMultiAlternatives @@ -27,6 +29,7 @@ def send_email(con,subject,email_to,email_from): def index(request): return render(request, "authcp/index.html", {}) +# user registration def register_user(request): if request.method == 'POST': form = UserRegisterForm(request.POST) @@ -46,7 +49,7 @@ def register_user(request): "%Y-%m-%d %H:%M:%S") profile.save() send_email({'u': u, 'profil': profile}, - 'Welcome to our cloud', + _('Welcome to our cloud'), u.email, settings.DEFAULT_EMAIL_FROM, ) @@ -59,9 +62,11 @@ def register_user(request): form = UserRegisterForm() return render(request, 'authcp/register.html', {'form': form}) +# user registration success page def register_success(request): return render(request, 'authcp/success.html', {}) +# user activation def activation(request, key): activation_expired=False already_active=False diff --git a/dash_stack_dashboard/_i18n.py b/dash_stack_dashboard/_i18n.py index 9bb519a..8a3fce9 100644 --- a/dash_stack_dashboard/_i18n.py +++ b/dash_stack_dashboard/_i18n.py @@ -12,7 +12,7 @@ _ = _translators.primary # The contextual translation function using the name "_C" # requires oslo.i18n >=2.1.0 _C = _translators.contextual_form -ya + # The plural translation function using the name "_P" # requires oslo.i18n >=2.1.0 _P = _translators.plural_form diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po new file mode 100644 index 0000000..b303838 --- /dev/null +++ b/locale/tr/LC_MESSAGES/django.po @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 ""