i18n: Deal with lazy strings more carefully.

This uses a more specific type `_StrPromise` to replace `Promise`
providing typing information for lazy translation strings.

In places where the callee evaluates the `_StrPromise` object in all
cases we simply force the evaluation with `str()`. This includes
`JsonableError` that ends up handled by the error handler middleware,
and `internal_send_stream_message` that depends on `check_stream_topic`,
requiring the `topic` to be evaluated anyway. In other siuations, the
callee is expected to be able to handle `StrPromise` explicitly.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-08-08 13:53:11 -04:00
committed by Tim Abbott
parent ab9279aabe
commit bb9e80d7a2
8 changed files with 46 additions and 24 deletions

View File

@@ -740,7 +740,7 @@ def send_messages_for_new_subscribers(
internal_prep_stream_message(
sender=sender,
stream=stream,
topic=Realm.STREAM_EVENTS_NOTIFICATION_TOPIC,
topic=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC),
content=_(
"**{policy}** stream created by {user_name}. **Description:**"
).format(