i18n: Fix some ineffective calls to ugettext at top level.

Translation has no effect when we don’t yet know what language we’re
translating for.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-10-16 18:42:50 -07:00
committed by Tim Abbott
parent bba43f35ca
commit f461a64a6b
5 changed files with 38 additions and 43 deletions

View File

@@ -15,6 +15,7 @@ from django.db import transaction
from django.utils.timezone import now as timezone_now
from django.utils.translation import override as override_language
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from corporate.models import (
Customer,
@@ -143,14 +144,14 @@ def get_idempotency_key(ledger_entry: LicenseLedger) -> Optional[str]:
class BillingError(Exception):
# error messages
CONTACT_SUPPORT = _("Something went wrong. Please contact {email}.").format(
email=settings.ZULIP_ADMINISTRATOR,
)
TRY_RELOADING = _("Something went wrong. Please reload the page.")
CONTACT_SUPPORT = ugettext_lazy("Something went wrong. Please contact {email}.")
TRY_RELOADING = ugettext_lazy("Something went wrong. Please reload the page.")
# description is used only for tests
def __init__(self, description: str, message: str=CONTACT_SUPPORT) -> None:
def __init__(self, description: str, message: Optional[str] = None) -> None:
self.description = description
if message is None:
message = BillingError.CONTACT_SUPPORT.format(email=settings.ZULIP_ADMINISTRATOR)
self.message = message
class StripeCardError(BillingError):
@@ -188,7 +189,7 @@ def catch_stripe_errors(func: CallableT) -> CallableT:
raise StripeConnectionError(
'stripe connection error',
_("Something went wrong. Please wait a few seconds and try again."))
raise BillingError('other stripe error', BillingError.CONTACT_SUPPORT)
raise BillingError('other stripe error')
return cast(CallableT, wrapped)
@catch_stripe_errors
@@ -373,7 +374,7 @@ def process_initial_upgrade(user: UserProfile, licenses: int, automanage_license
billing_logger.warning(
"Customer %s trying to upgrade, but has an active subscription", customer,
)
raise BillingError('subscribing with existing subscription', BillingError.TRY_RELOADING)
raise BillingError('subscribing with existing subscription', str(BillingError.TRY_RELOADING))
billing_cycle_anchor, next_invoice_date, period_end, price_per_license = compute_plan_parameters(
automanage_licenses, billing_schedule, customer.default_discount, free_trial)

View File

@@ -142,7 +142,7 @@ def upgrade(request: HttpRequest, user: UserProfile,
return json_error(e.message, data={'error_description': e.description})
except Exception:
billing_logger.exception("Uncaught exception in billing:", stack_info=True)
error_message = BillingError.CONTACT_SUPPORT
error_message = BillingError.CONTACT_SUPPORT.format(email=settings.ZULIP_ADMINISTRATOR)
error_description = "uncaught exception during upgrade"
return json_error(error_message, data={'error_description': error_description})
else:

View File

@@ -193,50 +193,42 @@ class InvalidJSONError(JsonableError):
class OrganizationMemberRequired(JsonableError):
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
MEMBER_REQUIRED_MESSAGE = _("Must be an organization member")
def __init__(self) -> None:
super().__init__(self.MEMBER_REQUIRED_MESSAGE)
pass
@staticmethod
def msg_format() -> str:
return OrganizationMemberRequired.MEMBER_REQUIRED_MESSAGE
return _("Must be an organization member")
class OrganizationAdministratorRequired(JsonableError):
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
ADMIN_REQUIRED_MESSAGE = _("Must be an organization administrator")
def __init__(self) -> None:
super().__init__(self.ADMIN_REQUIRED_MESSAGE)
pass
@staticmethod
def msg_format() -> str:
return OrganizationAdministratorRequired.ADMIN_REQUIRED_MESSAGE
return _("Must be an organization administrator")
class OrganizationOwnerRequired(JsonableError):
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
OWNER_REQUIRED_MESSAGE = _("Must be an organization owner")
def __init__(self) -> None:
super().__init__(self.OWNER_REQUIRED_MESSAGE)
pass
@staticmethod
def msg_format() -> str:
return OrganizationOwnerRequired.OWNER_REQUIRED_MESSAGE
return _("Must be an organization owner")
class StreamAdministratorRequired(JsonableError):
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
ADMIN_REQUIRED_MESSAGE = _("Must be an organization or stream administrator")
def __init__(self) -> None:
super().__init__(self.ADMIN_REQUIRED_MESSAGE)
pass
@staticmethod
def msg_format() -> str:
return StreamAdministratorRequired.ADMIN_REQUIRED_MESSAGE
return _("Must be an organization or stream administrator")
class MarkdownRenderingException(Exception):
pass

View File

@@ -5,8 +5,9 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple
from django.conf.urls import url
from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls.resolvers import RegexPattern
from django.utils.functional import Promise
from django.utils.module_loading import import_string
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext as ugettext_lazy
from zerver.lib.storage import static_path
from zerver.lib.types import Validator
@@ -30,21 +31,21 @@ Over time, we expect this registry to grow additional convenience
features for writing and configuring integrations efficiently.
"""
CATEGORIES: Dict[str, str] = {
'meta-integration': _('Integration frameworks'),
'continuous-integration': _('Continuous integration'),
'customer-support': _('Customer support'),
'deployment': _('Deployment'),
'communication': _('Communication'),
'financial': _('Financial'),
'hr': _('HR'),
'marketing': _('Marketing'),
'misc': _('Miscellaneous'),
'monitoring': _('Monitoring tools'),
'project-management': _('Project management'),
'productivity': _('Productivity'),
'version-control': _('Version control'),
'bots': _('Interactive bots'),
CATEGORIES: Dict[str, Promise] = {
'meta-integration': ugettext_lazy('Integration frameworks'),
'continuous-integration': ugettext_lazy('Continuous integration'),
'customer-support': ugettext_lazy('Customer support'),
'deployment': ugettext_lazy('Deployment'),
'communication': ugettext_lazy('Communication'),
'financial': ugettext_lazy('Financial'),
'hr': ugettext_lazy('HR'),
'marketing': ugettext_lazy('Marketing'),
'misc': ugettext_lazy('Miscellaneous'),
'monitoring': ugettext_lazy('Monitoring tools'),
'project-management': ugettext_lazy('Project management'),
'productivity': ugettext_lazy('Productivity'),
'version-control': ugettext_lazy('Version control'),
'bots': ugettext_lazy('Interactive bots'),
}
class Integration:

View File

@@ -8,6 +8,7 @@ from django.shortcuts import render
from django.utils.html import escape
from django.utils.safestring import SafeString
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from confirmation.models import (
Confirmation,
@@ -45,7 +46,7 @@ from zerver.lib.validator import check_bool, check_int, check_int_in, check_stri
from zerver.models import UserProfile, avatar_changes_disabled, name_changes_disabled
from zproject.backends import check_password_strength, email_belongs_to_ldap
AVATAR_CHANGES_DISABLED_ERROR = _("Avatar changes are disabled in this organization.")
AVATAR_CHANGES_DISABLED_ERROR = ugettext_lazy("Avatar changes are disabled in this organization.")
def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpResponse:
try:
@@ -242,7 +243,7 @@ def set_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpR
return json_error(_("You must upload exactly one avatar."))
if avatar_changes_disabled(user_profile.realm) and not user_profile.is_realm_admin:
return json_error(AVATAR_CHANGES_DISABLED_ERROR)
return json_error(str(AVATAR_CHANGES_DISABLED_ERROR))
user_file = list(request.FILES.values())[0]
if ((settings.MAX_AVATAR_FILE_SIZE * 1024 * 1024) < user_file.size):
@@ -260,7 +261,7 @@ def set_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpR
def delete_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
if avatar_changes_disabled(user_profile.realm) and not user_profile.is_realm_admin:
return json_error(AVATAR_CHANGES_DISABLED_ERROR)
return json_error(str(AVATAR_CHANGES_DISABLED_ERROR))
do_change_avatar_fields(user_profile, UserProfile.AVATAR_FROM_GRAVATAR, acting_user=user_profile)
gravatar_url = avatar_url(user_profile)