diff --git a/docs/translating/internationalization.md b/docs/translating/internationalization.md index 0d1a65ee52..d3bf441340 100644 --- a/docs/translating/internationalization.md +++ b/docs/translating/internationalization.md @@ -258,12 +258,11 @@ If you are passing a translated string to a Handlebars partial, you can use: The syntax for block strings or strings containing variables is: ``` -{{#tr context}} +{{#tr}} Block of English text. {{/tr}} -var context = {'variable': 'variable value'}; -{{#tr context}} +{{#tr}} Block of English text with a {variable}. {{/tr}} ``` diff --git a/static/js/templates.js b/static/js/templates.js index c69ea242b4..2842790eff 100644 --- a/static/js/templates.js +++ b/static/js/templates.js @@ -59,25 +59,22 @@ Handlebars.registerHelper("t", (message) => { return intl.formatMessage(descriptor); }); -Handlebars.registerHelper("tr", function (context, options) { +Handlebars.registerHelper("tr", function (options) { // Marks a block for translation. // Example usage 1: - // {{#tr context}} + // {{#tr}} //

some English text

// {{/tr}} // // Example usage 2: - // {{#tr context}} - //

This {variable} will get value from context

+ // {{#tr}} + //

This {variable} will get value from the current context

// {{/tr}} // - // Notes: - // 1. `context` is very important. It can be `this` or an - // object or key of the current context. - // 2. Use `{` and `}` instead of `{{` and `}}` to declare - // expressions. + // Note: use `{` and `}` instead of `{{` and `}}` to declare + // variables. const message = options - .fn(context) + .fn(this) .trim() .split("\n") .map((s) => s.trim()) @@ -92,7 +89,7 @@ Handlebars.registerHelper("tr", function (context, options) { ]), ), ...Object.fromEntries( - Object.entries(context ?? {}).map(([key, value]) => [ + Object.entries(this ?? {}).map(([key, value]) => [ key, Handlebars.Utils.escapeExpression(value), ]), diff --git a/static/templates/actions_popover_content.hbs b/static/templates/actions_popover_content.hbs index cb456b6584..92963ee90a 100644 --- a/static/templates/actions_popover_content.hbs +++ b/static/templates/actions_popover_content.hbs @@ -64,7 +64,7 @@
  • - {{#tr this}}Mute the topic {topic}{{/tr}} (M) + {{#tr}}Mute the topic {topic}{{/tr}} (M)
  • {{/if}} @@ -73,7 +73,7 @@
  • - {{#tr this}}Unmute the topic {topic}{{/tr}} + {{#tr}}Unmute the topic {topic}{{/tr}}
  • {{/if}} @@ -82,7 +82,7 @@
  • - {{#tr this}}Add emoji reaction{{/tr}} + {{#tr}}Add emoji reaction{{/tr}}
  • {{/if}} diff --git a/static/templates/all_messages_sidebar_actions.hbs b/static/templates/all_messages_sidebar_actions.hbs index 0e7b172d67..75a254bb56 100644 --- a/static/templates/all_messages_sidebar_actions.hbs +++ b/static/templates/all_messages_sidebar_actions.hbs @@ -4,7 +4,7 @@ {{! tabindex="0" Makes anchor tag focusable. Needed for keyboard support. }} - {{#tr this}}Mark all messages as read{{/tr}} + {{#tr}}Mark all messages as read{{/tr}} diff --git a/static/templates/announce_stream_docs.hbs b/static/templates/announce_stream_docs.hbs index f456d79e40..d3b3867457 100644 --- a/static/templates/announce_stream_docs.hbs +++ b/static/templates/announce_stream_docs.hbs @@ -1,7 +1,7 @@ {{! Explanation of what "announce stream" does when creating a stream }}
    - {{#tr this}} + {{#tr}}

    Stream will be announced in #{notifications_stream}.

    {{/tr}}

    {{t 'Organization administrators can change this in the organization settings.' }}

    diff --git a/static/templates/archive_recipient_row.hbs b/static/templates/archive_recipient_row.hbs index 3a63c24585..602c37496b 100644 --- a/static/templates/archive_recipient_row.hbs +++ b/static/templates/archive_recipient_row.hbs @@ -5,7 +5,7 @@ + title="{{#tr}}Narrow to stream "{display_recipient}"{{/tr}}"> {{display_recipient}} {{! topic stuff }} @@ -13,7 +13,7 @@ {{! topic link }} + title="{{#tr}}Narrow to stream "{display_recipient}", topic "{topic}"{{/tr}}"> {{topic}} diff --git a/static/templates/compose_all_everyone.hbs b/static/templates/compose_all_everyone.hbs index 5d282b485e..0a207651c2 100644 --- a/static/templates/compose_all_everyone.hbs +++ b/static/templates/compose_all_everyone.hbs @@ -1,6 +1,6 @@
    - {{#tr this}} + {{#tr}} Are you sure you want to mention all {count} people in this stream?
    This will send email and mobile push notifications to most of those {count} users. diff --git a/static/templates/compose_announce.hbs b/static/templates/compose_announce.hbs index 7dd0a4a1fa..79d1e851ff 100644 --- a/static/templates/compose_announce.hbs +++ b/static/templates/compose_announce.hbs @@ -1,6 +1,6 @@
    - {{#tr this}} + {{#tr}} This stream is reserved for announcements.
    Are you sure you want to message all {count} people in this stream? diff --git a/static/templates/compose_invite_users.hbs b/static/templates/compose_invite_users.hbs index 85f34565e9..0042ca899b 100644 --- a/static/templates/compose_invite_users.hbs +++ b/static/templates/compose_invite_users.hbs @@ -1,10 +1,10 @@
    {{#if can_subscribe_other_users}} -

    {{#tr this}}{name} is not subscribed to this stream. They will not be notified unless you subscribe them.{{/tr}}

    +

    {{#tr}}{name} is not subscribed to this stream. They will not be notified unless you subscribe them.{{/tr}}

    {{else}} -

    {{#tr this}}{name} is not subscribed to this stream. They will not be notified if you mention them.{{/tr}}

    +

    {{#tr}}{name} is not subscribed to this stream. They will not be notified if you mention them.{{/tr}}

    {{/if}}
    diff --git a/static/templates/compose_not_subscribed.hbs b/static/templates/compose_not_subscribed.hbs index 255755070b..484475bbdc 100644 --- a/static/templates/compose_not_subscribed.hbs +++ b/static/templates/compose_not_subscribed.hbs @@ -1,6 +1,6 @@

    - {{#tr this}} + {{#tr}} You're not subscribed to this stream. You will not be notified if other users reply to your message. {{/tr}}

    diff --git a/static/templates/compose_private_stream_alert.hbs b/static/templates/compose_private_stream_alert.hbs index cef115efe4..4e663abf44 100644 --- a/static/templates/compose_private_stream_alert.hbs +++ b/static/templates/compose_private_stream_alert.hbs @@ -1,5 +1,5 @@
    - {{#tr this}}Warning: {stream_name} is a private stream.{{/tr}} + {{#tr}}Warning: {stream_name} is a private stream.{{/tr}}
    diff --git a/static/templates/confirm_delete_user.hbs b/static/templates/confirm_delete_user.hbs index 89a3821947..119d452f68 100644 --- a/static/templates/confirm_delete_user.hbs +++ b/static/templates/confirm_delete_user.hbs @@ -1,5 +1,5 @@

    - {{#tr this}} + {{#tr}} Are you sure you want to delete {group_name}? {{/tr}}

    diff --git a/static/templates/confirm_delete_user_avatar.hbs b/static/templates/confirm_delete_user_avatar.hbs index 26ca53a1de..030cad606b 100644 --- a/static/templates/confirm_delete_user_avatar.hbs +++ b/static/templates/confirm_delete_user_avatar.hbs @@ -1,5 +1,5 @@

    - {{#tr this}} + {{#tr}} Are you sure you want to delete your profile picture? {{/tr}}

    diff --git a/static/templates/confirm_unstar_all_messages.hbs b/static/templates/confirm_unstar_all_messages.hbs index 3dacce78bc..b13ffa6933 100644 --- a/static/templates/confirm_unstar_all_messages.hbs +++ b/static/templates/confirm_unstar_all_messages.hbs @@ -1,5 +1,5 @@

    - {{#tr this}} + {{#tr}} Would you like to unstar all starred messages? This action cannot be undone. {{/tr}}

    diff --git a/static/templates/confirm_unstar_all_messages_in_topic.hbs b/static/templates/confirm_unstar_all_messages_in_topic.hbs index 923e8219b8..c33790b631 100644 --- a/static/templates/confirm_unstar_all_messages_in_topic.hbs +++ b/static/templates/confirm_unstar_all_messages_in_topic.hbs @@ -1,5 +1,5 @@

    - {{#tr this}} + {{#tr}} Are you sure you want to unstar all messages in topic {topic}? This action cannot be undone. {{/tr}}

    diff --git a/static/templates/delete_topic_modal.hbs b/static/templates/delete_topic_modal.hbs index 2aa178f6c4..30c565b5d7 100644 --- a/static/templates/delete_topic_modal.hbs +++ b/static/templates/delete_topic_modal.hbs @@ -7,7 +7,7 @@