mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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:
committed by
Tim Abbott
parent
bba43f35ca
commit
f461a64a6b
@@ -15,6 +15,7 @@ from django.db import transaction
|
|||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
from django.utils.translation import override as override_language
|
from django.utils.translation import override as override_language
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from corporate.models import (
|
from corporate.models import (
|
||||||
Customer,
|
Customer,
|
||||||
@@ -143,14 +144,14 @@ def get_idempotency_key(ledger_entry: LicenseLedger) -> Optional[str]:
|
|||||||
|
|
||||||
class BillingError(Exception):
|
class BillingError(Exception):
|
||||||
# error messages
|
# error messages
|
||||||
CONTACT_SUPPORT = _("Something went wrong. Please contact {email}.").format(
|
CONTACT_SUPPORT = ugettext_lazy("Something went wrong. Please contact {email}.")
|
||||||
email=settings.ZULIP_ADMINISTRATOR,
|
TRY_RELOADING = ugettext_lazy("Something went wrong. Please reload the page.")
|
||||||
)
|
|
||||||
TRY_RELOADING = _("Something went wrong. Please reload the page.")
|
|
||||||
|
|
||||||
# description is used only for tests
|
# 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
|
self.description = description
|
||||||
|
if message is None:
|
||||||
|
message = BillingError.CONTACT_SUPPORT.format(email=settings.ZULIP_ADMINISTRATOR)
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
class StripeCardError(BillingError):
|
class StripeCardError(BillingError):
|
||||||
@@ -188,7 +189,7 @@ def catch_stripe_errors(func: CallableT) -> CallableT:
|
|||||||
raise StripeConnectionError(
|
raise StripeConnectionError(
|
||||||
'stripe connection error',
|
'stripe connection error',
|
||||||
_("Something went wrong. Please wait a few seconds and try again."))
|
_("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)
|
return cast(CallableT, wrapped)
|
||||||
|
|
||||||
@catch_stripe_errors
|
@catch_stripe_errors
|
||||||
@@ -373,7 +374,7 @@ def process_initial_upgrade(user: UserProfile, licenses: int, automanage_license
|
|||||||
billing_logger.warning(
|
billing_logger.warning(
|
||||||
"Customer %s trying to upgrade, but has an active subscription", customer,
|
"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(
|
billing_cycle_anchor, next_invoice_date, period_end, price_per_license = compute_plan_parameters(
|
||||||
automanage_licenses, billing_schedule, customer.default_discount, free_trial)
|
automanage_licenses, billing_schedule, customer.default_discount, free_trial)
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ def upgrade(request: HttpRequest, user: UserProfile,
|
|||||||
return json_error(e.message, data={'error_description': e.description})
|
return json_error(e.message, data={'error_description': e.description})
|
||||||
except Exception:
|
except Exception:
|
||||||
billing_logger.exception("Uncaught exception in billing:", stack_info=True)
|
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"
|
error_description = "uncaught exception during upgrade"
|
||||||
return json_error(error_message, data={'error_description': error_description})
|
return json_error(error_message, data={'error_description': error_description})
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -193,50 +193,42 @@ class InvalidJSONError(JsonableError):
|
|||||||
class OrganizationMemberRequired(JsonableError):
|
class OrganizationMemberRequired(JsonableError):
|
||||||
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
||||||
|
|
||||||
MEMBER_REQUIRED_MESSAGE = _("Must be an organization member")
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(self.MEMBER_REQUIRED_MESSAGE)
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def msg_format() -> str:
|
def msg_format() -> str:
|
||||||
return OrganizationMemberRequired.MEMBER_REQUIRED_MESSAGE
|
return _("Must be an organization member")
|
||||||
|
|
||||||
class OrganizationAdministratorRequired(JsonableError):
|
class OrganizationAdministratorRequired(JsonableError):
|
||||||
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
||||||
|
|
||||||
ADMIN_REQUIRED_MESSAGE = _("Must be an organization administrator")
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(self.ADMIN_REQUIRED_MESSAGE)
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def msg_format() -> str:
|
def msg_format() -> str:
|
||||||
return OrganizationAdministratorRequired.ADMIN_REQUIRED_MESSAGE
|
return _("Must be an organization administrator")
|
||||||
|
|
||||||
class OrganizationOwnerRequired(JsonableError):
|
class OrganizationOwnerRequired(JsonableError):
|
||||||
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
||||||
|
|
||||||
OWNER_REQUIRED_MESSAGE = _("Must be an organization owner")
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(self.OWNER_REQUIRED_MESSAGE)
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def msg_format() -> str:
|
def msg_format() -> str:
|
||||||
return OrganizationOwnerRequired.OWNER_REQUIRED_MESSAGE
|
return _("Must be an organization owner")
|
||||||
|
|
||||||
class StreamAdministratorRequired(JsonableError):
|
class StreamAdministratorRequired(JsonableError):
|
||||||
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
code: ErrorCode = ErrorCode.UNAUTHORIZED_PRINCIPAL
|
||||||
|
|
||||||
ADMIN_REQUIRED_MESSAGE = _("Must be an organization or stream administrator")
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(self.ADMIN_REQUIRED_MESSAGE)
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def msg_format() -> str:
|
def msg_format() -> str:
|
||||||
return StreamAdministratorRequired.ADMIN_REQUIRED_MESSAGE
|
return _("Must be an organization or stream administrator")
|
||||||
|
|
||||||
class MarkdownRenderingException(Exception):
|
class MarkdownRenderingException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.urls.resolvers import RegexPattern
|
from django.urls.resolvers import RegexPattern
|
||||||
|
from django.utils.functional import Promise
|
||||||
from django.utils.module_loading import import_string
|
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.storage import static_path
|
||||||
from zerver.lib.types import Validator
|
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.
|
features for writing and configuring integrations efficiently.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CATEGORIES: Dict[str, str] = {
|
CATEGORIES: Dict[str, Promise] = {
|
||||||
'meta-integration': _('Integration frameworks'),
|
'meta-integration': ugettext_lazy('Integration frameworks'),
|
||||||
'continuous-integration': _('Continuous integration'),
|
'continuous-integration': ugettext_lazy('Continuous integration'),
|
||||||
'customer-support': _('Customer support'),
|
'customer-support': ugettext_lazy('Customer support'),
|
||||||
'deployment': _('Deployment'),
|
'deployment': ugettext_lazy('Deployment'),
|
||||||
'communication': _('Communication'),
|
'communication': ugettext_lazy('Communication'),
|
||||||
'financial': _('Financial'),
|
'financial': ugettext_lazy('Financial'),
|
||||||
'hr': _('HR'),
|
'hr': ugettext_lazy('HR'),
|
||||||
'marketing': _('Marketing'),
|
'marketing': ugettext_lazy('Marketing'),
|
||||||
'misc': _('Miscellaneous'),
|
'misc': ugettext_lazy('Miscellaneous'),
|
||||||
'monitoring': _('Monitoring tools'),
|
'monitoring': ugettext_lazy('Monitoring tools'),
|
||||||
'project-management': _('Project management'),
|
'project-management': ugettext_lazy('Project management'),
|
||||||
'productivity': _('Productivity'),
|
'productivity': ugettext_lazy('Productivity'),
|
||||||
'version-control': _('Version control'),
|
'version-control': ugettext_lazy('Version control'),
|
||||||
'bots': _('Interactive bots'),
|
'bots': ugettext_lazy('Interactive bots'),
|
||||||
}
|
}
|
||||||
|
|
||||||
class Integration:
|
class Integration:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from django.shortcuts import render
|
|||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.safestring import SafeString
|
from django.utils.safestring import SafeString
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from confirmation.models import (
|
from confirmation.models import (
|
||||||
Confirmation,
|
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 zerver.models import UserProfile, avatar_changes_disabled, name_changes_disabled
|
||||||
from zproject.backends import check_password_strength, email_belongs_to_ldap
|
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:
|
def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
@@ -242,7 +243,7 @@ def set_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpR
|
|||||||
return json_error(_("You must upload exactly one avatar."))
|
return json_error(_("You must upload exactly one avatar."))
|
||||||
|
|
||||||
if avatar_changes_disabled(user_profile.realm) and not user_profile.is_realm_admin:
|
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]
|
user_file = list(request.FILES.values())[0]
|
||||||
if ((settings.MAX_AVATAR_FILE_SIZE * 1024 * 1024) < user_file.size):
|
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:
|
def delete_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
if avatar_changes_disabled(user_profile.realm) and not user_profile.is_realm_admin:
|
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)
|
do_change_avatar_fields(user_profile, UserProfile.AVATAR_FROM_GRAVATAR, acting_user=user_profile)
|
||||||
gravatar_url = avatar_url(user_profile)
|
gravatar_url = avatar_url(user_profile)
|
||||||
|
|||||||
Reference in New Issue
Block a user