Skip to content

use Smartling placeholders for shortcode detection (WP-879)#520

Merged
vsolovei-smartling merged 4 commits into
masterfrom
WP-879-placeholders-in-translated-body
Mar 4, 2024
Merged

use Smartling placeholders for shortcode detection (WP-879)#520
vsolovei-smartling merged 4 commits into
masterfrom
WP-879-placeholders-in-translated-body

Conversation

@vsolovei-smartling

@vsolovei-smartling vsolovei-smartling commented Feb 27, 2024

Copy link
Copy Markdown
Contributor

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.


public function hasPlaceholders(string $string): bool
{
return preg_match('~' . self::SMARTLING_PLACEHOLDER_MASK_START . '.+' . self::SMARTLING_PLACEHOLDER_MASK_END . '~', $string);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We only detect placeholder strings without matching, I've added a test, and it passes as-is

@vsolovei-smartling vsolovei-smartling merged commit 3808481 into master Mar 4, 2024
@vsolovei-smartling vsolovei-smartling deleted the WP-879-placeholders-in-translated-body branch March 4, 2024 05:12
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.

3 participants