use Smartling placeholders for shortcode detection (WP-879)#520
Merged
vsolovei-smartling merged 4 commits intoMar 4, 2024
Conversation
dimitrystd
reviewed
Feb 28, 2024
|
|
||
| public function hasPlaceholders(string $string): bool | ||
| { | ||
| return preg_match('~' . self::SMARTLING_PLACEHOLDER_MASK_START . '.+' . self::SMARTLING_PLACEHOLDER_MASK_END . '~', $string); |
Contributor
There was a problem hiding this comment.
Use non non-greedy pattern. Test this string #sl-start#test1#sl-end# test2 #sl-start#test3#sl-end#
Suggested change
| return preg_match('~' . self::SMARTLING_PLACEHOLDER_MASK_START . '.+' . self::SMARTLING_PLACEHOLDER_MASK_END . '~', $string); | |
| return preg_match('~' . self::SMARTLING_PLACEHOLDER_MASK_START . '.+?' . self::SMARTLING_PLACEHOLDER_MASK_END . '~', $string); |
Contributor
Author
There was a problem hiding this comment.
We only detect placeholder strings without matching, I've added a test, and it passes as-is
PavelLoparev
approved these changes
Feb 29, 2024
dimitrystd
approved these changes
Feb 29, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The connector uses the shortcodes that are registered in WP or added in fine-tuning section. It appears the fine-tuning was not set up, as when testing locally with the proper setup, no
#sl-start#or#sl-end#tags appear. Without setting up the fine-tuning, the result is as experienced by the reporter. I'll update the documentation accordingly, but this PR could also help to resolve the issue. The plugin only wraps registered shortcodes in said tags, and the potential for false-positives is quite low, I believe.I could think of no other way to determine shortcodes presence, as a string that looks like a WP shortcode
[text]might as well be plain text that is meant for translation.