WordPress.org

Making WordPress.org

Changeset 9312


Ignore:
Timestamp:
12/05/2019 06:37:42 AM (7 months ago)
Author:
dd32
Message:

Translate: Localise links to Plugin/Theme pages within the project description when viewing on a locale-specific page.

Fixes #2768.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r8751 r9312  
    362362        return $sub_projects;
    363363    }
     364
     365    /**
     366     * Localize any WordPress.org links.
     367     *
     368     * @param string $content   The content to search for WordPress.org links in.
     369     * @param string $wp_locale The WP_Locale subdomain that the content should reference.
     370     * @return string Filtered $content where any WordPress.org links have been replaced with $wp_locale subdomain links.
     371     */
     372    function localize_links( $content, $wp_locale = false ) {
     373        global $wpdb;
     374
     375        static $subdomains = null;
     376        if ( is_null( $subdomains ) && $wp_locale ) {
     377            $subdomains = $wpdb->get_results( 'SELECT locale, subdomain FROM wporg_locales', OBJECT_K );
     378        }
     379
     380        if ( $wp_locale && isset( $subdomains[ $wp_locale ] ) ) {
     381            $content = preg_replace(
     382                '!(?<=[\'"])https?://wordpress.org/!i', // Only match when it's a url within an attribute.
     383                'https://' . $subdomains[ $wp_locale ]->subdomain . '.wordpress.org/',
     384                $content
     385            );
     386        }
     387
     388        return $content;
     389    }
    364390}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/locale-project.php

    r8558 r9312  
    1212
    1313<div class="project-header">
    14     <p class="project-description"><?php echo $sub_project->description; ?></p>
     14    <p class="project-description"><?php
     15        $description = apply_filters( 'project_description', $sub_project->description, $sub_project );
     16
     17        // Localize the links to the currently viewed locale.
     18        $description = WordPressdotorg\GlotPress\Customizations\Plugin::get_instance()->localize_links( $description, $locale->wp_locale );
     19
     20        echo $description;
     21    ?></p>
    1522
    1623    <div class="project-box percent-<?php echo $project_status->percent_complete; ?>">
     
    3340                            <?php
    3441                            foreach ( $variants as $variant ) {
    35                                 $selected =
    3642                                printf(
    3743                                    '<option name="%s" data-project-url="%s"%s>%s</option>',
Note: See TracChangeset for help on using the changeset viewer.