Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.78k stars 895 forks source link

Try to come up with a solution where HTML tags in translations are not reliant on the order #19701

Open igorschoester opened 1 year ago

igorschoester commented 1 year ago

Example from Settings' site representation:

sprintf(
    // translators: %1$s and %2$s are replaced by opening and closing <a> tags.
    __( "This info is intended to appear in %1$sGoogle's Knowledge Graph%2$s.", "wordpress-seo" ),
    "<a>",
    "</a>"
),

If the translation were to swap the %1$s and %2$s our code would error due to the invalid HTML tags (in this case Cannot read properties of undefined (reading 'prevOffset')).

Maybe we can try and prevent situations like these by only allowing ordering for actual translations and not HTML tags. Something like %s twice for the tags would prevent this. If a translation needs both you would get some complications, I haven't thought this through. Let's investigate.

ibanner commented 1 year ago

Hi @igorschoester - I just got that error message after initial setup and activation of Yoast. This is a Hebrew site. It's also in development and protected by HTTP AUTH. Perhaps this is the reason? Anyway, I'd be grateful for any tips you might have 馃檹

igorschoester commented 1 year ago

Hello @ibanner 馃憢

Indeed, the culprit seems to be the translation for:

Set the basic info for your website. You can use %1$stagline%2$s and %1$sseparator%2$s as %3$sreplacement variables%4$s when configuring the search appearance of your content.

Now as to what the correct translations should be, that is very hard to determine for me 馃槄 But it seems also strange with the browser seemingly switching directions mid-sentence.

A new translation would have to be submitted and approved on translate.wordpress.org before it can show up in your site's translation downloads. Here is a link that includes a search for the above translation: https://translate.wordpress.org/projects/wp-plugins/wordpress-seo/stable/he/default/?filters%5Bterm%5D=Set+the+basic+info+for+your+website.+You+can+use+%251%24stagline%252%24s+and+%251%24sseparator%252%24s+as+%253%24sreplacement+variables%254%24s+when+configuring+the+search+appearance+of+your+content.&filters%5Bterm_scope%5D=scope_any&filters%5Bstatus%5D=current_or_waiting_or_fuzzy_or_untranslated&filters%5Buser_login%5D=&filter=Apply+Filters&sort%5Bby%5D=priority&sort%5Bhow%5D=desc

As an example. I don't think is actually correctly highlighting the words, though at least it does not crash:

讛讙讚专 讗转 讛诪讬讚注 讛讘住讬住讬 注讘讜专 讛讗转专 砖诇讱. 谞讬转谉 诇讛砖转诪砖 讘-%1$s转讬讜讙%2$s讜讘诪驻专讬讚%1$s %2$s讘转讜专 %3$s 诪砖转谞讬 讛讞诇驻讛%4$s 讘注转 讛讙讚专转 诪专讗讛 讛讞讬驻讜砖 砖诇 讛转讜讻谉 砖诇讱.

vraja-pro commented 3 weeks ago

Hello @ibanner I fixed the translation, you shouldn't get the error now.