*/ 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 such as de_DE. Omit to address the POT template instead of a translation.', 'acrossai-abilities-manager' ), ), 'filter' => array( 'type' => 'string', 'enum' => array( 'all', 'untranslated', 'fuzzy' ), 'default' => 'all', 'description' => __( 'Narrow to strings needing work.', 'acrossai-abilities-manager' ), ), 'search' => array( 'type' => 'string', 'description' => __( 'Case-insensitive match against source or translation.', 'acrossai-abilities-manager' ), ), 'per_page' => array( 'type' => 'integer', 'minimum' => 1, 'maximum' => 500, 'default' => 100, ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'bundle' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'strings' => array( 'type' => 'array', 'items' => array( 'type' => 'object', 'additionalProperties' => true ), ), 'count' => array( 'type' => 'integer' ), 'total' => array( 'type' => 'integer' ), 'file' => array( 'type' => 'string' ), ); } /** * @since 0.0.34 * @return array */ protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @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; } $po = Translation_Repository::load( $file ); if ( is_wp_error( $po ) ) { return $po; } $filter = isset( $input['filter'] ) ? (string) $input['filter'] : 'all'; $all = Translation_Repository::messages( $po, 'all' === $filter ? '' : $filter, PHP_INT_MAX ); $needle = isset( $input['search'] ) ? strtolower( trim( (string) $input['search'] ) ) : ''; if ( '' !== $needle ) { $all = array_values( array_filter( $all, static function ( array $row ) use ( $needle ): bool { return false !== strpos( strtolower( $row['source'] . ' ' . $row['target'] ), $needle ); } ) ); } $limit = isset( $input['per_page'] ) ? (int) $input['per_page'] : 100; return array( 'strings' => array_slice( $all, 0, $limit ), 'count' => min( count( $all ), $limit ), 'total' => count( $all ), 'file' => $file, ); } }