From 038de393edd5ba721de574ed2ac1e809f85908de Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 13 Sep 2023 10:53:48 +0800 Subject: [PATCH] DEV: Raise an error in test env when I18n interpolate argument is missing (#23527) Why this change? We have been bitten by bugs where tests are not catching missing interpolate argument in our client side code because the JavaScript tests are also using `I18n.translate` to assert that the right message is shown. Before this change, `I18n.interpolate` will just replace the missing interpolation argument in the final translation with some placeholder. As a result, we ended up comparing a broken translation with another broken translation in the test environment. Why does this change do? This change introduces the `I18n.testing` property which when set to `true` will cause `I18n.translate` to throw an error when an interpolate argument is missing. With this commit, we also set `I18n.testing = true` when running qunit acceptance test. --- .../discourse/app/components/d-lightbox.hbs | 1 + .../d-lightbox/screen-reader-announcer.hbs | 14 +++++---- .../discourse/app/components/group-post.js | 2 +- .../discourse/app/components/modal/history.js | 8 +++-- .../components/modal/history/topic-footer.hbs | 16 +++++----- .../tests/fixtures/group-fixtures.js | 20 +++++++++++++ .../discourse/tests/helpers/qunit-helpers.js | 4 +++ .../discourse/tests/unit/lib/i18n-test.js | 24 +++++++++++++++ app/assets/javascripts/locales/i18n.js | 29 +++++++++++++++---- .../addon/components/notifications-filter.js | 1 + .../javascripts/acceptance/mentions-test.js | 1 + 11 files changed, 97 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/d-lightbox.hbs b/app/assets/javascripts/discourse/app/components/d-lightbox.hbs index a4ab8c8b943..68a57c9806c 100644 --- a/app/assets/javascripts/discourse/app/components/d-lightbox.hbs +++ b/app/assets/javascripts/discourse/app/components/d-lightbox.hbs @@ -71,6 +71,7 @@ @toggleZoom={{this.toggleZoom}} @zoomButtonIcon={{this.zoomButtonIcon}} /> + - {{i18n - "experimental_lightbox.screen_reader_image_title" - current=@counterIndex - total=@totalItemCount - title=@currentItem.title - }} + {{#if @currentItem.title}} + {{i18n + "experimental_lightbox.screen_reader_image_title" + current=@counterIndex + total=@totalItemCount + title=@currentItem.title + }} + {{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/group-post.js b/app/assets/javascripts/discourse/app/components/group-post.js index a233bc12cc0..5cbfbf211d5 100644 --- a/app/assets/javascripts/discourse/app/components/group-post.js +++ b/app/assets/javascripts/discourse/app/components/group-post.js @@ -43,7 +43,7 @@ export default Component.extend({ return userPath(username.toLowerCase()); }, - @discourseComputed("post.topic.title", "post.post_number") + @discourseComputed("post.title", "post.post_number") titleAriaLabel(title, postNumber) { return I18n.t("groups.aria_post_number", { postNumber, title }); }, diff --git a/app/assets/javascripts/discourse/app/components/modal/history.js b/app/assets/javascripts/discourse/app/components/modal/history.js index c31b85bc85b..ce9470c412f 100644 --- a/app/assets/javascripts/discourse/app/components/modal/history.js +++ b/app/assets/javascripts/discourse/app/components/modal/history.js @@ -162,9 +162,11 @@ export default class History extends Component { } get revertToRevisionText() { - return I18n.t("post.revisions.controls.revert", { - revision: this.previousVersion, - }); + if (this.previousVersion) { + return I18n.t("post.revisions.controls.revert", { + revision: this.previousVersion, + }); + } } refresh(postId, postVersion) { diff --git a/app/assets/javascripts/discourse/app/components/modal/history/topic-footer.hbs b/app/assets/javascripts/discourse/app/components/modal/history/topic-footer.hbs index fc2f24c0675..436ae424b58 100644 --- a/app/assets/javascripts/discourse/app/components/modal/history/topic-footer.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/history/topic-footer.hbs @@ -45,13 +45,15 @@ {{/if}} {{#if @isStaff}} - + {{#if @revertToRevisionText}} + + {{/if}} {{#if @model.previous_hidden}}