qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
554 stars 105 forks source link

Other missing translated fields - Yoast #1034

Open pjrobertson opened 3 years ago

pjrobertson commented 3 years ago

Apologies, I don't have time to make the commits right now, but logging these for the record:

  1. Article titles not translated (I think the following is needed):

    if ( !function_exists('imd_wpseo_frontend_presentation') ) {
    
        function imd_wpseo_frontend_presentation( $presentation, $context ) {
    
                // FIX TITLES..
                $presentation->title = wpseo_replace_vars(get_post_meta(get_the_ID(), '_yoast_wpseo_title', true), []);
                $presentation->open_graph_title = $presentation->title;
    
                // FIX DESCRIPTIONS..
                #$presentation->meta_description = wpseo_replace_vars(get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true), []);
                $presentation->open_graph_description = $presentation->meta_description;
    
                // FIX URLS..
                if ( function_exists('qtranxf_convertURL') ) {
                        $presentation->canonical = qtranxf_convertURL( $presentation->canonical, qtranxf_getLanguage() );
                        $presentation->open_graph_url = qtranxf_convertURL( $presentation->open_graph_url, qtranxf_getLanguage() );
                }
    
                return $presentation;
        }
        add_filter( 'wpseo_frontend_presentation', 'imd_wpseo_frontend_presentation', 10, 2 );
    
        // DEBUG SCHEMA..
        // add_filter( 'yoast_seo_development_mode', '__return_true' );
    }
  2. Twitter and social description/titles:
        'wpseo_opengraph-title',
        'wpseo_opengraph-description',
        'wpseo_twitter-title',
        'wpseo_twitter-description',
bagaweb commented 3 years ago

Thank @pjrobertson where should I insert those lines?

herrvigg commented 3 years ago

@bagaweb If needed this should go in modules/wp-seo-front.php / qtranxf_wpseo_add_filters_front.

@pjrobertson the 4 items for the second part are already there, but the filter names are slightly different: https://github.com/qtranslate/qtranslate-xt/blob/b27047deb5aa0b36d5072de9dc4b03ac5e511c78/modules/wp-seo/wp-seo-front.php#L10-L19

Reference: https://developer.yoast.com/customization/apis/metadata-api.

Can you confirm the first part is needed?

pjrobertson commented 3 years ago

Thank @pjrobertson where should I insert those lines?

Sorry, wasn't clear. Herrvigg is correct, I inserted them here: https://github.com/qtranslate/qtranslate-xt/blob/master/modules/wp-seo/wp-seo-front.php#L25

pjrobertson commented 3 years ago

Can you confirm the first part is needed?

@herrvigg I just checked my test install, and the title and meta->description tags appear properly for the language for which the page was last saved. But for all other language, the values will be in the last-saved language.

This is the issue with the new Yoast plugin: it saves the indexables on blog post save. If I'm editing the English language version of an article, Yoast will save the English values to the indexables. If I'm editing the German language version of a post, Yoast will save the German values to the indexables.

In that case, I think this qtranslate module should either: a) Disable indexables as per this comment - note, I have not tested this. Plus, the whole reason indexables were created by Yoast was to improve performance. Disabling may be a 'regression'. (However, in my mind these indexables were a terrible architecture choice, and performance should be improved through web-caching a whole page, not pre-caching certain values in the database. But that's a different discussion ;-) ) b) For each yoast value, use the filter to re-generate the content based on the active language. This is what my first code snippet above does. This method isn't great though, as it basically would require copying the logic to generate each indexable into the yoast module, and updating if yoast ever changed it.

I would vote for a) whereby indexables aren't saved, so values would be (I believe) created on the fly, and then they could be filtered with qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage immediately. (Untested, however)

herrvigg commented 3 years ago

@pjrobertson it seems you know better how to improve the integration, I don't use Yoast myself so I rely on your feedback.

I don't really follow your last comment vs the first part you mentioned earlier. a) where should we put wpseo_should_save_indexable, also in the front end filters? b) When you write "use the filter to re-generate the content", do you mean wpseo_frontend_presentation ? Is that an alternative to point a)? I don't really get it.

Also I don't follow the last point with qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage.

Are we fine with point 2 from what we have already in master?

Maybe you could push a PR with all the required changes to close this ticket?