feat(send-to-caas): support CTA URL localization via caasLocaleInject metadata flag #4538
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change adds the ability to automatically prepend the page's locale segment to primary and secondary CTA URLs when a page is localized, controlled by a new metadata flag.
Previously, localization logic was missed in the post-processing step in
getCaaSMetadata()
. We've refactored it so the locale injection is scoped entirely to the CTA URL computations insend-utils.js
, making the metadata builder itself simpler and preserving its original responsibility.Resolves: MWPW-167994
What's Changed
localizeCtaUrl(val)
helper (intools/send-to-caas/send-utils.js
)<meta name="caaslocaleinject" content="true">
(case‐sensitive)getPageLocale(window.location.pathname)
to detect if the page is localizedcheckCtaUrl(...)
for bothcta1url
andcta2url
/${locale}
to the URL path only once, if not already localizedprops.cta1url
andprops.cta2url
to calllocalizeCtaUrl(checkCtaUrl(...))
URL.pathname
always begins with "/"Why
To test
Author a word doc and put some already localized links and others not.

Toggle this

caasLocaleInject
parameter (either omit it for legacy consumers or let it be true for consumers who need this)You will see the unlocalized link localized and the localized link stay the same.

Test URLs: