-
Notifications
You must be signed in to change notification settings - Fork 129
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
Remove the glossary tooltip inside the HTML tags #1679
Conversation
Could we avoid adding multiple preg_splits by just checking the previous chunk like this? foreach ( $singular_split as $k => $chunk ) {
// [...]
if ( $k > 0 && ( '<' === substr( $singular_split[ $k - 1 ], -1 ) || '</' === substr( $singular_split[ $k - 1 ], -2 ) ) ) {
$singular_combined .= $escaped_chunk;
continue;
} |
This patch also makes the test pass: diff --git i/gp-templates/helper-functions.php w/gp-templates/helper-functions.php
index 2b43b50b..645a6295 100644
--- i/gp-templates/helper-functions.php
+++ w/gp-templates/helper-functions.php
@@ -230,10 +230,15 @@ function map_glossary_entries_to_translation_originals( $translation, $glossary
if ( is_array( $singular_split ) ) {
$singular_combined = '';
- foreach ( $singular_split as $chunk ) {
+ foreach ( $singular_split as $k => $chunk ) {
// Create an escaped version for use later on.
$escaped_chunk = esc_translation( $chunk );
+ if ( $k > 0 && ( '<' === substr( $singular_split[ $k - 1 ], -1 ) || '"' === substr( $singular_split[ $k - 1 ], -1 ) || '</' === substr( $singular_split[ $k - 1 ], -2 ) ) ) {
+ $singular_combined .= $escaped_chunk;
+ continue;
+ }
+
// Create a lower case version to compare with the glossary terms.
$lower_chunk = strtolower( $chunk );
@@ -285,10 +290,16 @@ function map_glossary_entries_to_translation_originals( $translation, $glossary
if ( is_array( $plural_split ) ) {
$plural_combined = '';
- foreach ( $plural_split as $chunk ) {
+ foreach ( $plural_split as $k => $chunk ) {
// Create an escaped version for use later on.
$escaped_chunk = esc_translation( $chunk );
+
+ if ( $k > 0 && ( '<' === substr( $plural_split[ $k - 1 ], -1 ) || '"' === substr( $plural_split[ $k - 1 ], -1 ) || '</' === substr( $plural_split[ $k - 1 ], -2 ) ) ) {
+ $plural_combined .= $escaped_chunk;
+ continue;
+ }
+
// Create a lower case version to compare with the glossary terms.
$lower_chunk = strtolower( $chunk ); |
@akirk with the current approach we don't show the glossary suggestions into some elements like I think the best approach will be to remove these checks:
And then focus on special situations like |
We can change it to something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making that function simpler would be good.
With the previous approach used in the With the new approach, we resolve these false positives: I prefer to put this code in a new function because we use this code twice in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but I am still a bit unhappy about the complexity of the function. Check how it can be done with a state machine here: 29bc1c4
Could you cherry-pick the commit? |
Problem
When GlotPress has an HTML tag in the glossary, it shows the glossary tooltip in the HTML tag.
Fix #1382 and #1385.
Solution
This PR excludes the glossary tooltips inside the HTML tags, splitting the original strings (singular and plural) to avoid adding the glossary tooltips to the HTML tags.
Testing Instructions
This PR adds 2 tests:
To test it manually, you can:
This is s strong test <strong>strong</strong>. This is another<dd>strong</dd>, very strong test with<img src="strong.img" /> images <hr/>.
Plural. This is s strong test <strong>strong</strong>. This is another<dd>strong</dd>, very strong test with<img src="strong.img" /> images <hr/>.
strong
word only appears outside the HTML tags.