*/ 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' ), ), 'source' => array( 'type' => 'string', 'description' => __( 'The exact source text, as it appears in the file.', 'acrossai-abilities-manager' ), ), 'context' => array( 'type' => 'string', 'description' => __( 'Gettext context, when the same source text appears more than once.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'bundle', 'source' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'string' => array( 'type' => 'object', 'additionalProperties' => true ), '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; } $source = (string) ( $input['source'] ?? '' ); $context = (string) ( $input['context'] ?? '' ); foreach ( Translation_Repository::messages( $po, '', PHP_INT_MAX ) as $row ) { if ( $row['source'] === $source && $row['context'] === $context ) { return array( 'string' => $row, 'file' => $file, ); } } return new WP_Error( 'unknown_string', sprintf( /* translators: %s: the source text searched for. */ __( 'No string with that exact source text in this file. Source text must match byte for byte, including punctuation and placeholders; call translations/list-strings with a search term to find it. Searched for: %s', 'acrossai-abilities-manager' ), $source ) ); } }