Making WordPress.org


Ignore:
Timestamp:
06/21/2016 10:06:58 AM (10 years ago)
Author:
tellyworth
Message:

Plugin directory: include all available translations in pseudo-meta for search.

Also add some defensive code, better testing and bugfixes.

See #1691, #1692

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r3511 r3519  
    420420                return $content;
    421421        }
     422
     423        /**
     424         * Returns a list of translation locales for a given plugin slug and branch.
     425         *
     426         * @param string $slug    Plugin slug.
     427         * @param string $branch  Branch - 'stable-readme' for example.
     428         * @param string $min_percent     Only return locales where percent_translated is >= this value.
     429         * @return array
     430         */
     431        public function find_all_translations_for_plugin( $slug, $branch, $min_percent = 0 ) {
     432
     433                // This naively hits the API. It could probably be re-written to query the DB instead.
     434                $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $slug . '/' . $branch, array( 'https' ) );
     435
     436                $out = array();
     437                if ( $json = file_get_contents( $api_url ) ) {
     438                        if ( $data = json_decode( $json ) ) {
     439                                if ( isset( $data->translation_sets ) ) {
     440                                        foreach ( $data->translation_sets as $translation ) {
     441                                                if ( $translation->percent_translated >= $min_percent )
     442                                                        $out[] = $translation->wp_locale;
     443                                        }
     444                                }
     445                        }
     446                }
     447
     448                return $out;
     449        }
     450
    422451}
Note: See TracChangeset for help on using the changeset viewer.