# wpdeepl/1.0/client/deeplapi-functions.php

Translation with DeepL API, version 1.0. 28 lines.

- Page: https://pluginprobe.com/plugins/wpdeepl/1.0/code/client/deeplapi-functions.php
- Raw: https://pluginprobe.com/plugins/wpdeepl/1.0/raw/client/deeplapi-functions.php
- Modified: 2023-01-28T04:28:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpdeepl/1.0/code/client/deeplapi-functions.php#L10-L20`.

```php
<?php

function deepl_translate( $source_lang = false, $target_lang, $strings = array(), $cache_prefix = '' ) {
		$DeepLApiTranslate = new DeepLApiTranslate();
		$DeepLApiTranslate->setCachePrefix( $cache_prefix );

		if( $source_lang ) {
			$DeepLApiTranslate->setLangFrom( $source_lang );
		}

		if( !$DeepLApiTranslate->setLangTo( $target_lang ))
			return new WP_Error( $target_lang, __( "Target language '$target_lang' not valid", 'wpdeepl' ));

		$DeepLApiTranslate->setTagHandling( 'xml' );

		$translations = $DeepLApiTranslate->getTranslations( $strings );
		$request = array(
			'cached'				=> $DeepLApiTranslate->wasItCached(),
			'time'					=> $DeepLApiTranslate->getTimeElapsed(),
			'cache_file_request'	=> $DeepLApiTranslate->getCacheFile( 'request' ),
			'cache_file_response'	=> $DeepLApiTranslate->getCacheFile( 'response' ),
		);

		$return = compact( 'request', 'translations' );
		return apply_filters( 'deepl_translate', $return, $source_lang, $target_lang, $strings, $cache_prefix );
}

	
```
