Making WordPress.org

Changeset 3515


Ignore:
Timestamp:
06/21/2016 09:32:38 AM (9 years ago)
Author:
ocean90
Message:

Plugin Directory: Import translations on initial commit.

See #1691.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n
Files:
3 edited

Legend:

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

    r3507 r3515  
    8888        }
    8989
    90         parent::set_glotpress_for_plugin( $this->plugin, 'code' );
     90        $result = $this->set_glotpress_for_plugin( $this->plugin, 'code' );
     91        if ( is_wp_error( $result ) ) {
     92            throw new Exception( $result->get_error_message() );
     93        }
    9194
    9295        $branch = ( 'trunk' === $tag ) ? 'dev' : 'stable';
    93         parent::import_pot_to_glotpress_project( $this->plugin, $branch, $pot_file );
     96        $this->import_pot_to_glotpress_project( $this->plugin, $branch, $pot_file );
    9497
    95         // @todo: Import translations only once.
     98        // Import translations on initial import.
     99        if ( 'created' === $result ) {
     100            $this->import_translations_to_glotpress_project( $export_directory, $this->plugin, $branch );
     101        }
    96102    }
    97103}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-i18n-import.php

    r3507 r3515  
    22namespace WordPressdotorg\Plugin_Directory\CLI\I18N;
    33use WordPressdotorg\Plugin_Directory\Plugin_I18n;
     4use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    45use WP_Error;
    56
     
    6970
    7071    /**
    71      * Import generated POT file to GlotPress
     72     * Import generated POT file to GlotPress.
    7273     *
    73      * @param string $project GP project slug to import to
    74      * @param string $branch GP project branch to import to (dev|stable)
    75      * @param string $file Path to POT file
     74     * @param string $project       GP project slug to import to
     75     * @param string $branch        GP project branch to import to (dev|stable)
     76     * @param string $file          Path to POT file
    7677     * @param array $str_priorities GP string priorities
    7778     */
    78     function import_pot_to_glotpress_project( $project, $branch, $file, $str_priorities = array() ) {
     79    public function import_pot_to_glotpress_project( $project, $branch, $file, $str_priorities = array() ) {
    7980        global $wpdb;
    8081
     
    102103        }
    103104    }
     105
     106    /**
     107     * Import existing plugin translations to GlotPress.
     108     * See translate/bin/translations/import-plugin-translations.php
     109     *
     110     * @param string $export_directory Relative path as provided by Dotorg_Plugins_Tracker.
     111     * @param string $project          GP project slug to import to
     112     * @param string $branch           GP project branch to import to (dev|stable)
     113     */
     114    public function import_translations_to_glotpress_project( $export_directory, $project, $branch ) {
     115        $files = Filesystem::list_files( $export_directory, true, '/\.po$/' );
     116
     117        if ( empty( $files ) ) {
     118            $files = Filesystem::list_files( $export_directory, true, '/\.mo$/' );
     119        }
     120
     121        foreach ( $files as $file ) {
     122            $filename = basename( $file );
     123            if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).(po|mo)$/', $filename, $match ) ) {
     124                continue;
     125            }
     126
     127            list( , , $language, $ext ) = $match;
     128
     129            // Fix some locales.
     130            switch ( $language ) {
     131                case 'ga_IR' :
     132                    $language = 'ga';
     133                    break;
     134                case 'ca_ES' :
     135                    $language = 'ca';
     136                    break;
     137                case 'el_GR' :
     138                    $language = 'el';
     139                    break;
     140                case 'af_ZA' :
     141                    $language = 'af';
     142                    break;
     143                case 'zh_cn' :
     144                case 'zh_ZH' :
     145                    $language = 'zh_CN';
     146                    break;
     147                case 'uk_UA' :
     148                    $language = 'uk';
     149                    break;
     150                case 'sq_AL' :
     151                    $language = 'sq';
     152                    break;
     153                case 'ga_IE' :
     154                    $language = 'ga';
     155                    break;
     156                case 'gu_IN' :
     157                    $language = 'gu';
     158                    break;
     159                case 'hy_AM' :
     160                    $language = 'hy';
     161                    break;
     162                case 'eo_EO' :
     163                    $language = 'eo';
     164                    break;
     165                case 'ar_AR' :
     166                    $language = 'ar';
     167                    break;
     168                case 'hr_HR' :
     169                    $language = 'hr';
     170                    break;
     171                case 'cs_CS' :
     172                    $language = 'cs_CZ';
     173                    break;
     174                case 'vi_VN' :
     175                    $language = 'vi';
     176                    break;
     177                case 'ja_JP' :
     178                    $language = 'ja';
     179                    break;
     180                case 'tr' :
     181                    $language = 'tr_TR';
     182                    break;
     183                case 'be_BY' :
     184                case 'be' :
     185                    $language = 'bel';
     186                    break;
     187            }
     188
     189            $cmd = WPORGTRANSLATE_WPCLI . ' wporg-translate import-plugin-translations ' . escapeshellarg( "wp-plugins/{$project}/{$branch}" ) . ' ' . escapeshellarg( $language ) . ' ' . escapeshellarg( $file ) . ' --format=' . escapeshellarg( $ext );
     190            echo shell_exec( $cmd . ' 2>&1' );
     191        }
     192    }
    104193}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php

    r3507 r3515  
    3939     */
    4040    public function import_from_tag( $tag ) {
    41         global $wpdb;
    42 
    4341        $files = SVN::ls( self::PLUGIN_SVN_BASE . "/{$this->plugin}/{$tag}" );
    4442        if ( ! $files ) {
     
    151149        }
    152150
    153         parent::set_glotpress_for_plugin( $this->plugin, 'readme' );
     151        $result = $this->set_glotpress_for_plugin( $this->plugin, 'readme' );
     152        if ( is_wp_error( $result ) ) {
     153            throw new Exception( $result->get_error_message() );
     154        }
    154155
    155156        $branch = ( 'trunk' === $tag ) ? 'dev' : 'stable';
    156         parent::import_pot_to_glotpress_project( $this->plugin, $branch, $pot_file, $str_priorities );
     157        $this->import_pot_to_glotpress_project( $this->plugin, $branch, $pot_file, $str_priorities );
    157158    }
    158159
     
    166167     * @return array
    167168     */
    168     function handle_translator_comment( $array, $key, $val ) {
     169    private function handle_translator_comment( $array, $key, $val ) {
    169170        $val = trim( preg_replace( '/[^a-z0-9]/i', ' ', $val ) ); // cleanup key names for display.
    170171
Note: See TracChangeset for help on using the changeset viewer.