'deepl', 'name' => 'DeepL Translator', 'key' => $settings->offsetGet('deepl_api_key'), 'url' => $settings->offsetGet('deepl_api_url'), ), array ( 'id' => 'google', 'name' => 'Google Translate', 'key' => $settings->offsetGet('google_api_key'), ), array ( 'id' => 'microsoft', 'name' => 'Microsoft Translator', 'key' => $settings->offsetGet('microsoft_api_key'), 'region' => $settings->offsetGet('microsoft_api_region'), ), array ( 'id' => 'yandex', 'name' => 'Yandex.Translate', 'key' => $settings->offsetGet('yandex_api_key'), ), array ( 'id' => 'lecto', 'name' => 'Lecto AI', 'key' => $settings->offsetGet('lecto_api_key'), ), ); } /** * Get only configured APIs, and sort them fairly * @return array[] */ public static function configured(){ return self::sort( array_filter( self::export(), array(__CLASS__,'filterConfigured') ) ); } /** * @internal * @param string[] * @return bool */ private static function filterConfigured( array $api ){ return array_key_exists('key',$api) && is_string($api['key']) && '' !== $api['key']; } /** * @internal * @param string[] * @param string[] * @return int */ private static function compareNames( array $a, array $b ){ return strcasecmp($a['name'],$b['name']); } /** * Sort providers alphabetically * @param array * @return array */ public static function sort( array $apis ){ usort( $apis, array(__CLASS__,'compareNames') ); return $apis; } }