mwstake / mediawiki-component-deepl-translator
1.0.2
2024-09-16 13:06 UTC
Requires
- composer/installers: ~1.0|~2
- mwstake/mediawiki-componentloader: ~1
Requires (Dev)
- mediawiki/mediawiki-codesniffer: 41.0.0
- mediawiki/minus-x: 1.1.1
- php-parallel-lint/php-console-highlighter: 1.0.0
- php-parallel-lint/php-parallel-lint: 1.3.2
- phpunit/phpunit: ^8.5
README
$GLOBALS['mwsgDeeplTranslateServiceAuth'] = 'your-auth-key-here'; $GLOBALS['mwsgDeeplTranslateServiceUrl'] = 'https://api.deepl.com/v2'; // Optional - special cases $GLOBALS['mwsgDeeplTranslateTranslateUrl'] = $GLOBALS['mwsgDeeplTranslateServiceUrl'] . '/translate'; $GLOBALS['mwsgDeeplTranslateLanguagesUrl'] = $GLOBALS['mwsgDeeplTranslateServiceUrl'] . '/languages';
Usage
Direct service
$translator = \MediaWiki\MediaWikiServices::getInstance()->getService( 'MWStake.DeepLTranslator' ); $translation = $translator->translateText( 'Hello, world!', 'EN', 'DE' );
API
curl -X POST "https://your-wiki/rest.php/mws/v1/deepl/translate" -H "Content-Type: application/json" --data '{"text":"Hello, world!","source_lang":"EN","target_lang":"DE"}'
JS
mws.deepltranslator.translateText( 'Hello, world!', 'EN', 'DE' ).then( function( translation ) { console.log( translation ); } );