Making WordPress.org


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

Plugin Directory: Import translations on initial commit.

See #1691.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.