Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow concat in frontend t()-string sources #4945

Merged
merged 1 commit into from
May 23, 2024

Conversation

p2edwards
Copy link
Contributor

Description

Safely allow string concatenation in frontend translated strings.

Purpose

  • Restore some translation strings that were missing
  • Improve code formatting flexibility in the future

Details

Supports usage like

   const textContent = __(
     'This translation string is split ' +
     'across several lines to' + // to allow this kind of comment and
     'keep the column width low.'
   );

Without this fix, examples like the above would be missing from the build output without warning.1 If you compare extracted-strings.json before and afterwards you'll see maybe 8 or 9 translation strings turn up that were previously missing. Some of them can be seen here: GitHub search 🔎

I wrote some more explanation about how this patch works in my upstream PR 🍴 on grassator/webpack-extract-translation-keys.

  • The diff there is likely more reviewable than the one here, so read more there if you're curious.
  • The version bump here (6.0.0->6.1.0) is because my other patch got merged. I finally got around to upgrading us so I could base the new patch on that.
  • Right now we apply this patch with patch-package, but if it gets merged upstream we can change this to just bumping the version number again.

Related issues

Part of #4944

Checklist

  1. If you've added code that should be tested, add tests
  2. If you've changed APIs, update (or create!) the documentation
  3. Ensure the tests pass
  4. Make sure that your code lints and that you've followed our coding style
  5. Write a title and, if necessary, a description of your work suitable for publishing in our release notes
  6. Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE)
  7. Open an issue in the docs if there are UI/UX changes

Footnotes

  1. Previously discussed here and here (internal links)

Fixes a problem where if you concatenate string literals inside a t()
call, the t-string would be excluded, without any error message, from
`extracted-strings.json`

If you run the webpack build after this patch, you'll see about 9
translation strings in the output that were missing before.

(This commit also removes the previous patch on 6.0.0 and upgrades
webpack-extract-translation-keys-plugin to 6.1.0 where that patch was
merged upstream.)
Base automatically changed from task-412-tos-privacy-links to beta May 23, 2024 17:44
Copy link
Member

@jnm jnm left a comment

Choose a reason for hiding this comment

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

Tested and found several additional strings added to extracted-strings.json

@jnm jnm merged commit b3e7b7d into beta May 23, 2024
5 checks passed
@jnm jnm deleted the allow-concat-in-frontend-t-string-sources branch May 23, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants