Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
i18n: Fix some ineffective calls to ugettext at top level.
Anders Kaseorgf461a64a6bee
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex b8c5032f5aa..c13b2ef2703 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -15,6 +15,7 @@ from django.db import transactionfrom django.utils.timezone import now as timezone_nowfrom django.utils.translation import override as override_languagefrom django.utils.translation import ugettext as _+from django.utils.translation import ugettext_lazyfrom 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 = messageclass 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_licensebilling_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)diff --git a/corporate/views.py b/corporate/views.pyindex 913b4690a45..f6a30a4a094 100644--- a/corporate/views.py+++ b/corporate/views.py@@ -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:diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.pyindex 20c84bd9ebb..1a61b242a32 100644--- a/zerver/lib/exceptions.py+++ b/zerver/lib/exceptions.py@@ -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@staticmethoddef 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@staticmethoddef 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@staticmethoddef 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@staticmethoddef msg_format() -> str:- return StreamAdministratorRequired.ADMIN_REQUIRED_MESSAGE+ return _("Must be an organization or stream administrator")class MarkdownRenderingException(Exception):passdiff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex c57cc75b9f9..2900ff57cef 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -5,8 +5,9 @@ from typing import Any, Dict, List, Optional, Sequence, Tuplefrom django.conf.urls import urlfrom django.contrib.staticfiles.storage import staticfiles_storagefrom django.urls.resolvers import RegexPattern+from django.utils.functional import Promisefrom django.utils.module_loading import import_string-from django.utils.translation import ugettext as _+from django.utils.translation import ugettext as ugettext_lazyfrom zerver.lib.storage import static_pathfrom zerver.lib.types import Validator@@ -30,21 +31,21 @@ Over time, we expect this registry to grow additional conveniencefeatures 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:diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.pyindex ec3425b3b03..d21149707db 100644--- a/zerver/views/user_settings.py+++ b/zerver/views/user_settings.py@@ -8,6 +8,7 @@ from django.shortcuts import renderfrom django.utils.html import escapefrom django.utils.safestring import SafeStringfrom django.utils.translation import ugettext as _+from django.utils.translation import ugettext_lazyfrom confirmation.models import (Confirmation,@@ -45,7 +46,7 @@ from zerver.lib.validator import check_bool, check_int, check_int_in, check_strifrom zerver.models import UserProfile, avatar_changes_disabled, name_changes_disabledfrom 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) -> HttpRreturn 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) -> HttpRdef 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)