*/ protected function input_properties(): array { return array( 'bundle' => array( 'type' => 'string', 'description' => __( 'Restrict the in-use list to one bundle. Omit for the whole site.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array(); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'site_locale' => array( 'type' => 'string' ), 'installed' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => __( 'Locales WordPress has language packs for.', 'acrossai-abilities-manager' ), ), 'in_use' => array( 'type' => 'array', 'items' => array( 'type' => 'object', 'additionalProperties' => true ), 'description' => __( 'Locales that already have at least one PO file.', 'acrossai-abilities-manager' ), ), 'in_use_count' => array( 'type' => 'integer' ), ); } /** * @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 ) { $scope = isset( $input['bundle'] ) && '' !== $input['bundle'] ? Bundle_Repository::find( (string) $input['bundle'] ) : null; if ( is_wp_error( $scope ) ) { return $scope; } $bundles = null !== $scope ? array( $scope ) : Bundle_Repository::all(); if ( is_wp_error( $bundles ) ) { return $bundles; } $counts = array(); foreach ( $bundles as $bundle ) { foreach ( $bundle as $project ) { foreach ( (array) $project->findLocaleFiles( 'po' ) as $file ) { $locale = Bundle_Repository::locale_from_path( (string) $file->getPath() ); if ( '' === $locale ) { continue; } $counts[ $locale ] = ( $counts[ $locale ] ?? 0 ) + 1; } } } ksort( $counts ); $rows = array(); foreach ( $counts as $locale => $files ) { $rows[] = array( 'locale' => (string) $locale, 'po_files' => (int) $files, ); } return array( 'site_locale' => (string) get_locale(), 'installed' => function_exists( 'get_available_languages' ) ? array_values( (array) get_available_languages() ) : array(), 'in_use' => $rows, 'in_use_count' => count( $rows ), ); } }