offline avatar offline committed 6fe0d8c

translation updates

Comments (0)

Files changed (5)

openauth/fields.py

 from annoying.functions import get_object_or_None
 
 from openauth import settings
+from openauth import lang
 
 
 class LoginField(forms.CharField):
         super(LoginField, self).__init__(*args, **kwargs)
         if not settings.LOGIN_LABEL:
             if settings.AUTHENTICATION_TYPE == settings.USERNAME:
-                self.label = _("Login")
+                self.label = lang.LOGIN
             if settings.AUTHENTICATION_TYPE == settings.EMAIL:
-                self.label = _("Email")
+                self.label = lang.EMAIL
         else:
             self.label = settings.LOGIN_LABEL
 
         """
         super(LoginField, self).clean(value)
         if len(value) < settings.LOGIN_MIN_LENGTH:
-            raise forms.ValidationError(_(u'Login length is less than %(min)d') % {'min': settings.LOGIN_MIN_LENGTH})
+            raise forms.ValidationError(lang.LOGIN_MIN_LENGTH % {'min': settings.LOGIN_MIN_LENGTH})
         if len(value) > settings.LOGIN_MAX_LENGTH:
-            raise forms.ValidationError(_(u'Login length is more than %(max)d') % {'max': settings.LOGIN_MAX_LENGTH})
+            raise forms.ValidationError(lang.LOGIN_MAX_LENGTH % {'max': settings.LOGIN_MAX_LENGTH})
         if not settings.LOGIN_REGEX.match(value):
-            raise forms.ValidationError(_(u'%s contains restricted symbols') % self.label)
+            raise forms.ValidationError(lang.LOGIN_RESTRICTED_SYMBOLS % self.label)
         return value
 
 
         """
         super(PasswordField, self).clean(value)
         if len(value) < settings.PASSWORD_MIN_LENGTH:
-            raise forms.ValidationError(_(u'Password length is less than %(min)d') % {'min': settings.PASSWORD_MIN_LENGTH})
+            raise forms.ValidationError(lang.PASSWORD_MIN_LENGTH % {'min': settings.PASSWORD_MIN_LENGTH})
         if len(value) > settings.PASSWORD_MAX_LENGTH:
-            raise forms.ValidationError(_(u'Password length is more than %(max)d') % {'max': settings.PASSWORD_MAX_LENGTH})
+            raise forms.ValidationError(lang.PASSWORD_MAX_LENGTH % {'max': settings.PASSWORD_MAX_LENGTH})
         if not settings.PASSWORD_REGEX.match(value):
-            raise forms.ValidationError(_(u'Password contains restricted symbols'))
+            raise forms.ValidationError(lang.PASSWORD_RESTRICTED_SYMBOLS)
         return value
 

openauth/forms.py

     file for instractions.
     """
     def __init__(self, *args, **kwargs):
+        super(RegistrationForm, self).__init__(*args, **kwargs)
         if settings.DISPLAYNAME_REQUIRED:
-            self.base_fields['username'] = forms.CharField()
-        super(RegistrationForm, self).__init__(*args, **kwargs)
+            self.fields['username'] = forms.CharField()
 
     login = LoginField()
-    password = PasswordField(label=_('Password'))
-    password_dup = PasswordField(label=_('Password (confirmation)'))
+    password = PasswordField(label=lang.PASSWORD)
+    password_dup = PasswordField(label=lang.PASSWORD_CONFIRMATION)
 
 
     def clean_login(self):
         """
         if settings.AUTHENTICATION_TYPE == settings.EMAIL:
             if get_object_or_None(User, email=self.cleaned_data['login'].lower()):
-                raise forms.ValidationError(_(u'This email already registered'))
+                raise forms.ValidationError(lang.LOGIN_ALREADY_USED % self.fields['login'].label)
         elif settings.AUTHENTICATION_TYPE == settings.USERNAME:
             if get_object_or_None(User, username=self.cleaned_data['login']):
-                raise forms.ValidationError(_(u'This login name is already taken'))
+                raise forms.ValidationError(lang.LOGIN_ALREADY_USED % self.fields['login'].label)
         return self.cleaned_data['login']
 
 
         """
         if settings.UNIQUE_USERNAME:
             if get_object_or_None(User, username=self.cleaned_data['username']):
-                raise forms.ValidationError(_(u'This display name already registered'))
+                raise forms.ValidationError(lang.DISPLAY_NAME_ALREADY_TAKEN)
         return self.cleaned_data['username']
 
 
         pwd2 = self.cleaned_data.get('password_dup')
         if pwd1 and pwd2:
             if pwd1 != pwd2:
-                raise forms.ValidationError(_(u'Passwords do not match'))
+                raise forms.ValidationError(lang.PASSWORD_MATCH_ERROR)
         return self.cleaned_data
 
 
                 user = get_object_or_None(User, username=login)
             elif settings.AUTHENTICATION_TYPE == settings.EMAIL:
                 user = get_object_or_None(User, email=login.lower())
-            if user and  user.check_password(password):
+            if user and user.check_password(password):
                 if settings.ACTIVATION_REQUIRED and not user.is_active:
-                    raise forms.ValidationError(_(u'Your account is not active. Please activate it.'))
+                    raise forms.ValidationError(lang.ACCOUNT_NOT_ACTIVE)
                 user.backend = 'django.contrib.auth.backends.ModelBackend'
                 login_user(self.request, user)
                 return self.cleaned_data
             else:
-                raise forms.ValidationError(_(u'Incorrect authentication data'))
+                raise forms.ValidationError(lang.INCORRECT_AUTHENTICATION)
 
 LoginForm = autostrip(LoginForm)
 
     This form will send confirmation link to user asocciated with this email. 
     Please note that users without email can't reset their passwords. 
     """
-    email = forms.EmailField(label=_('Email'))
+    email = forms.EmailField(label=lang.EMAIL)
 
     def clean_email(self):
         """
         if get_object_or_None(User, email=email):
             return email
         else:
-            raise forms.ValidationError(_(u'This email is not registered'))
+            raise forms.ValidationError(lang.EMAIL_DOESNT_EXISTS)
 
 ResetPasswordForm = autostrip(ResetPasswordForm)
 
     """
     Form for changing user's password.
     """
-    password = PasswordField(label=_(u'Password'))
-    password_confirmation = PasswordField(label=_(u'Password (confirmation)'))
+    password = PasswordField(label=lang.PASSWORD)
+    password_confirmation = PasswordField(label=lang.PASSWORD_CONFIRMATION)
 
     def clean_password_confirmation(self):
         pass1 = self.cleaned_data['password']
         pass2 = self.cleaned_data['password_confirmation']
         if pass1 != pass2:
-            raise forms.ValidationError(_(u'The passwords do not match'))
+            raise forms.ValidationError(lang.PASSWORD_MATCH_ERROR)
         else:
             return pass1
 
 from django.utils.translation import ugettext as _
 
-LOGOUT_BEFORE_REGISTRATION = _('You have to logout before new account registration')
-REGISTRATION_DISABLED = _('We are sorry, but registration is disabled. Come back later')
-PLEASE_ACTIVATE = _("You have successfully registered. Check your inbox for email with activation link.")
-ERROR_SENDING_MAIL = _('Unfortunately we could not send you email in current time. Please, try later')
-LOGIN_NOW = _("You have successfully registered. You can login now")
-MUST_ACTIVATE_FIRST = _("You must activate your account first. Please check you email for activation link")
-SUCCESSFULL_LOGIN = _('You have successfully logged-in')
-PLEASE_LOGOUT = _('Please logout before proceeding to this page')
-CHECK_YOUR_EMAIL = _('Check your email please')
-PASSWORD_CHANGED = _('Password changed')
-LOGGED_OUT = _('You have been logged out')
+from annoying.functions import get_config
+
+# form translations
+LOGIN = get_config('OPENAUTH_LOGIN', _('Login'))
+EMAIL = get_config('OPENAUTH_EMAIL', _('Email'))
+PASSWORD = get_config('OPENAUTH_PASSWORD', _('Password'))
+PASSWORD_CONFIRMATION = get_config('OPENAUTH_PASSWORD_CONFIRMATION', _('Password confirmation'))
+LOGIN_MIN_LENGTH = get_config('OPENAUTH_LIGIN_MIN_LENGTH', _('Login length is less than %(min)d'))
+LOGIN_MAX_LENGTH = get_config('OPENAUTH_LIGIN_MAX_LENGTH', _('Login length is more than %(max)d'))
+LOGIN_RESTRICTED_SYMBOLS = get_config('OPENAUTH_LOGIN_RESTRICTED_SYMBOLS', _('%s contains restricted symbols'))
+PASSWORD_MIN_LENGTH = get_config('OPENAUTH_PASSWORD_MIN_LENGTH', _('Password length is less than %(min)d'))
+PASSWORD_MAX_LENGTH = get_config('OPENAUTH_PASSWORD_MAX_LENGTH', _('Password length is more than %(max)d'))
+PASSWORD_RESTRICTED_SYMBOLS = get_config('OPENAUTH_PASSWORD_RESTRICTED_SYMBOLS', _('Password contains restricted symbols'))
+LOGIN_ALREADY_USED = get_config('OPENAUTH_LOGIN_ALREADY_USED', _('%s already used'))
+DISPLAY_NAME_ALREADY_TAKEN = get_config('OPENAUTH_DISPLAY_NAME_ALREADY_TAKEN', _(u'This display name already registered'))
+PASSWORD_MATCH_ERROR = get_config('OPENAUTH_PASSWORD_MATCH_ERROR', _('Passwords do not match'))
+ACCOUNT_NOT_ACTIVE = get_config('OPENAUTH_ACCOUNT_NOT_ACTIVE', _('Your account is not activeted. Please activate and come back.'))
+INCORRECT_AUTHENTICATION = get_config('OPENAUTH_INCORRECT_AUTHENTICATION', _('Incorrect authentication data'))
+EMAIL_DOESNT_EXISTS = get_config('OPENAUTH_EMAIL_DOESNT_EXISTS', _(u'This email doesnt exists in our database'))
+
+# views translation
+REGISTRATION_DISABLED = get_config('OPENAUTH_REGISTRATION_DISABLED', _('We are sorry, but registration is disabled. Come back later'))
+PLEASE_ACTIVATE = get_config('OPENAUTH_PLEASE_ACTIVATE',_("You have successfully registered. Check your inbox for email with activation link."))
+ERROR_SENDING_MAIL = get_config('OPENAUTH_ERROR_SENDING_MAIL',_('Unfortunately we could not send you email in current time. Please, try later'))
+LOGIN_NOW = get_config('OPENAUTH_LOGIN_NOW',_('You have successfully registered. You can login now'))
+MUST_ACTIVATE_FIRST = get_config('OPENAUTH_MUST_ACTIVATE_FIRST', _("You must activate your account first. Please check you email for activation link"))
+SUCCESSFULL_LOGIN = get_config('OPENAUTH_SUCCESSFULL_LOGIN', _('You have successfully logged-in'))
+PLEASE_LOGOUT = get_config('OPENAUTH_PLEASE_LOGOUT', _('Please logout before proceeding to this page'))
+CHECK_YOUR_EMAIL = get_config('OPENAUTH_CHECK_YOUR_EMAIL', _('Check your email please'))
+PASSWORD_CHANGED = get_config('OPENAUTH_PASSWORD_CHANGED', _('Password changed'))
+LOGGED_OUT = get_config('OPENAUTH_LOGGED_OUT', _('You have been logged out'))
+

openauth/signals.py

 from confirmation.models import Confirmation
 from confirmation.signals import successfull_confirmation
 
-import openauth
-
+from openauth import settings
 
 
 @signals(successfull_confirmation, sender=Confirmation)
 def sighandler(request, instance, confirmation_type, **kwargs):
-    if confirmation_type == openauth.settings.ACTIVATION_TYPE:
+    if confirmation_type == settings.ACTIVATION_TYPE:
         user = instance
         user.is_active = True
         user.save()
-        if openauth.settings.ACTIVATION_AUTO_LOGIN:
+        if settings.ACTIVATION_AUTO_LOGIN:
             user.backend = 'django.contrib.auth.backends.ModelBackend'
             auth.login(request, user)
             
-    elif confirmation_type == openauth.settings.PASSWORD_RESET_TYPE:
+    elif confirmation_type == settings.PASSWORD_RESET_TYPE:
         user = instance
         user.backend = 'django.contrib.auth.backends.ModelBackend'
         auth.login(request, user)    

openauth/views.py

 @login_required
 def logout(request):
     auth.logout(request)
-    messages.success(request, lang.PASSWORD_CHANGED)
+    messages.success(request, lang.LOGGED_OUT)
     return redirect(settings.LOGOUT_REDIRECT_URL)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.