[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/cli/ -> import-originals.php (source)

   1  <?php
   2  
   3  class GP_CLI_Import_Originals extends WP_CLI_Command {
   4      /**
   5       * Import originals for a project from a file
   6       *
   7       * ## OPTIONS
   8       *
   9       * <project>
  10       * : Project name
  11       *
  12       * <file>
  13       * : File to import from
  14       *
  15       * [--format=<format>]
  16       * : Accepted values: po, mo, android, resx, strings. Default: po
  17       */
  18  	public function __invoke( $args, $assoc_args ) {
  19          // Double-check for compatibility
  20          if ( '-p' === $args[0] || '-f' === $args[1] ) {
  21              WP_CLI::error( __( '-p and -f are no longer required and should be removed.', 'glotpress' ) );
  22          }
  23  
  24          $project = GP::$project->by_path( $args[0] );
  25          if ( ! $project ) {
  26              WP_CLI::error( __( 'Project not found!', 'glotpress' ) );
  27          }
  28  
  29          $format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'po';
  30          $format = gp_array_get( GP::$formats, $format, null );
  31          if ( ! $format ) {
  32              WP_CLI::error( __( 'No such format.', 'glotpress' ) );
  33          }
  34  
  35          $translations = $format->read_originals_from_file( $args[1], $project );
  36          if ( ! $translations ) {
  37              WP_CLI::error( __( "Couldn't load translations from file!", 'glotpress' ) );
  38          }
  39  
  40          list( $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted, $originals_error ) = GP::$original->import_for_project( $project, $translations );
  41  
  42          $notice = sprintf(
  43              /* translators: 1: number added, 2: number updated, 3: number fuzzied, 4: number obsoleted */
  44              __( '%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.', 'glotpress' ),
  45              $originals_added,
  46              $originals_existing,
  47              $originals_fuzzied,
  48              $originals_obsoleted
  49          );
  50  
  51          if ( $originals_error ) {
  52              $notice = ' ' . sprintf(
  53                  /* translators: %s: number of errors */
  54                  _n( '%s new string was not imported due to an error.', '%s new strings were not imported due to an error.', $originals_error, 'glotpress' ),
  55                  $originals_error
  56              );
  57          }
  58  
  59          WP_CLI::line( $notice );
  60      }
  61  }


Generated: Tue Mar 19 01:01:21 2024 Cross-referenced by PHPXref 0.7.1