Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Feb 25, 2025

In the existing method of translation, we show the translated titles below the post cooked:

Screenshot 2025-02-25 at 11 18 59 AM

When using the same already-translated titles for the experimental feature, it would result in the H1 rendering:

Screenshot 2025-02-25 at 11 21 48 AM

We've been sending the topic.title in for translation, instead of the escaped topic.fancy_title, which works well for the existing method. I had considered changing our implementation to send the fancy_titles (escaped) in for translation instead, but that would result in our existing methods titles being double-escaped

Screenshot 2025-02-25 at 11 17 20 AM

To keep compatibility between existing and experimental, I will only escape it for the experimental feature. This PR does that.

.topic
.translation_for(I18n.locale)
.presence
&.then { |t| Topic.fancy_title(t) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh TIL about #then, pretty neat! What happens if we get blank translation? Should we fallback to the original? Or is this handled on the client side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modifier in core handles the case when this value is nil. (discourse/discourse@5f00ae2)

@nattsw nattsw merged commit e0105f8 into main Feb 25, 2025
5 checks passed
@nattsw nattsw deleted the escape-new-feature-only branch February 25, 2025 07:55
@nattsw
Copy link
Contributor Author

nattsw commented Feb 25, 2025

Thaaanks @OsamaSayegh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants