PluginProbe
Translation with DeepL API / 1.0
Translation with DeepL API v1.0
trunk 0.1.20180323 1.0 1.2.5.1 1.5.2.5 1.7.5 2.4.3.12 2.4.3.9 2.4.5
wpdeepl / client / deeplapi-functions.php

deeplapi-functions.php in Translation with DeepL API 1.0, at client/deeplapi-functions.php

28 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function deepl_translate( $source_lang = false, $target_lang, $strings = array(), $cache_prefix = '' ) {
4 $DeepLApiTranslate = new DeepLApiTranslate();
5 $DeepLApiTranslate->setCachePrefix( $cache_prefix );
6
7 if( $source_lang ) {
8 $DeepLApiTranslate->setLangFrom( $source_lang );
9 }
10
11 if( !$DeepLApiTranslate->setLangTo( $target_lang ))
12 return new WP_Error( $target_lang, __( "Target language '$target_lang' not valid", 'wpdeepl' ));
13
14 $DeepLApiTranslate->setTagHandling( 'xml' );
15
16 $translations = $DeepLApiTranslate->getTranslations( $strings );
17 $request = array(
18 'cached' => $DeepLApiTranslate->wasItCached(),
19 'time' => $DeepLApiTranslate->getTimeElapsed(),
20 'cache_file_request' => $DeepLApiTranslate->getCacheFile( 'request' ),
21 'cache_file_response' => $DeepLApiTranslate->getCacheFile( 'response' ),
22 );
23
24 $return = compact( 'request', 'translations' );
25 return apply_filters( 'deepl_translate', $return, $source_lang, $target_lang, $strings, $cache_prefix );
26 }
27
28