Plugin Directory

Changeset 3492016


Ignore:
Timestamp:
03/26/2026 05:10:59 PM (2 days ago)
Author:
John Dagelmore
Message:

2.27.10 trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gptranslate/trunk/serverside-translations.php

    r3474048 r3492016  
    354354            // Translate <meta name="description" content="...">
    355355            $html = preg_replace_callback(
    356                 '~<meta\s+(?:name|property)=["\'](?:description|og:description|twitter:description)["\']\s+content=["\'](.*?)["\'][^>]*>~i',
     356                '~<meta\s+(?:name|property)=["\'](?:description|og:description|twitter:description|dc\.description)["\']\s+content=["\'](.*?)["\'][^>]*>~i',
    357357                function ($matches) use ($altTranslations, $caseInsensitive, $matchQuotes) {
    358358                    $originalTag = $matches[0];
     
    392392            if (preg_match('~<title[^>]*>(.*?)</title>~is', $html, $titleMatch)) {
    393393                $translatedTitle = trim(strip_tags($titleMatch[1]));
    394                
     394
    395395                // Step 2: Replace og:title content directly
    396396                $html = preg_replace(
     
    399399                    $html
    400400                );
    401                
     401
    402402                // Step 3: Replace twitter:title content with the same translated title
    403403                $html = preg_replace(
    404404                    '~(<meta\s+name=["\']twitter:title["\']\s+content=["\']).*?(["\'][^>]*>)~i',
     405                    '$1' . htmlspecialchars($translatedTitle, ENT_QUOTES, 'UTF-8') . '$2',
     406                    $html
     407                );
     408
     409                // Step 4: Replace Dublin Core (SEOPress) dc.title content with the same translated title
     410                $html = preg_replace(
     411                    '~(<meta\s+name=["\']dc\.title["\']\s+content=["\']).*?(["\'][^>]*>)~i',
    405412                    '$1' . htmlspecialchars($translatedTitle, ENT_QUOTES, 'UTF-8') . '$2',
    406413                    $html
     
    969976                }
    970977               
    971                 // Translate meta descriptions (standard, Open Graph, Twitter)
     978                // Translate meta descriptions (standard, Open Graph, Twitter, Dublin Core)
    972979                $metaDescriptions = $xpath->query(
    973980                    '//meta[
     
    975982                        or (@name="twitter:description")
    976983                        or (@property="og:description")
     984                        or (@name="dc.description")
    977985                    ]'
    978986                );
     
    10151023                        foreach ($twitterTitleNodes as $twitterTitleNode) {
    10161024                            $twitterTitleNode->setAttribute('content', trim($translatedTitle));
     1025                        }
     1026
     1027                        // Set Dublin Core (SEOPress) dc:title with the same value as <title>
     1028                        $dcTitleNodes = $xpath->query('//meta[@name="dc.title"]');
     1029                        foreach ($dcTitleNodes as $dcTitleNode) {
     1030                            $dcTitleNode->setAttribute('content', trim($translatedTitle));
    10171031                        }
    10181032                    }
     
    14231437               
    14241438                // Translate <meta name="description">
    1425                 foreach ($htmlObj->find('meta[name=description], meta[name=twitter:description], meta[property=og:description]') as $metaNode) {
     1439                foreach ($htmlObj->find('meta[name=description], meta[name=twitter:description], meta[property=og:description], meta[name=dc.description]') as $metaNode) {
    14261440                    $contentValue = $metaNode->content;
    14271441                   
     
    14731487                        // Set twitter:title with the same value as <title>
    14741488                        $metaTwitterTitleNode->content = trim($translatedTitle);
     1489                    }
     1490                }
     1491
     1492                // Translate <meta name="dc:title"> (Dublin Core - SEOPress) with the same value as <title> tag
     1493                foreach ($htmlObj->find('meta[name=dc.title]') as $metaDcTitleNode) {
     1494                    // Find the <title> tag to get the translated title
     1495                    $titleNode = $htmlObj->find('title', 0);
     1496
     1497                    if ($titleNode) {
     1498                        // Get the translated title text
     1499                        $translatedTitle = $titleNode->plaintext;
     1500
     1501                        // Set dc:title with the same value as <title>
     1502                        $metaDcTitleNode->content = trim($translatedTitle);
    14751503                    }
    14761504                }
Note: See TracChangeset for help on using the changeset viewer.