*/ protected function input_properties(): array { return array( 'bundle' => array( 'type' => 'string', 'description' => __( 'Bundle id, handle or slug.', 'acrossai-abilities-manager' ), ), 'domain' => array( 'type' => 'string', 'description' => __( 'Text domain. Omit for the bundle default.', 'acrossai-abilities-manager' ), ), 'locale' => array( 'type' => 'string', 'description' => __( 'Locale to sync.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'bundle', 'locale' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'artefacts' => array( 'type' => 'object', 'additionalProperties' => true, 'description' => __( 'Bytes written per artefact, read back from disk.', 'acrossai-abilities-manager' ), ), 'file' => array( 'type' => 'string' ), 'before_count' => array( 'type' => 'integer' ), 'after_count' => array( 'type' => 'integer' ), 'source' => array( 'type' => 'string', 'description' => __( 'Whether the template or the source code was used as the reference.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => false ); } /** * @since 0.0.34 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { $file = $this->resolve_file( $input ); if ( is_wp_error( $file ) ) { return $file; } $bundle = Bundle_Repository::find( (string) ( $input['bundle'] ?? '' ) ); if ( is_wp_error( $bundle ) ) { return $bundle; } $project = $this->resolve_project( $input ); if ( is_wp_error( $project ) ) { return $project; } $target = Translation_Repository::load( $file ); if ( is_wp_error( $target ) ) { return $target; } $before = count( Translation_Repository::messages( $target, '', PHP_INT_MAX ) ); $pot = $project->getPot(); // Prefer the template; fall back to scanning the source, which is what Loco's own sync does // when a bundle ships no POT. if ( $pot && $pot->exists() ) { $source = Translation_Repository::load( (string) $pot->getPath() ); $origin = 'template'; if ( is_wp_error( $source ) ) { return $source; } } else { $extracted = Translation_Repository::extract( $bundle, $project ); if ( is_wp_error( $extracted ) ) { return $extracted; } $source = $extracted['po']; $origin = 'source'; } $synced = Translation_Repository::sync( $target, $source, $project ); if ( is_wp_error( $synced ) ) { return $synced; } $written = Translation_Repository::write( $file, $synced['po'], $project ); if ( is_wp_error( $written ) ) { return $written; } return array( 'artefacts' => $written, 'file' => $file, 'before_count' => $before, 'after_count' => count( Translation_Repository::messages( $synced['po'], '', PHP_INT_MAX ) ), 'source' => $origin, ); } }