mwstake/mediawiki-component-deepl-translator

1.0.2 2024-09-16 13:06 UTC

This package is auto-updated.

Last update: 2024-12-19 14:05:29 UTC


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 );
} );