Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1426318
RemoteTTMServerWebService.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
RemoteTTMServerWebService.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\WebService
;
use
FormatJson
;
/**
* Class for querying external translation service. Implements support for ttmserver via MediaWiki API.
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2013-01-01
* @ingroup TranslationWebService
* @see https://www.mediawiki.org/wiki/Help:Extension:Translate/Translation_memories
*/
class
RemoteTTMServerWebService
extends
TranslationWebService
{
/** @inheritDoc */
public
function
getType
():
string
{
return
'ttmserver'
;
}
/** @inheritDoc */
protected
function
mapCode
(
string
$code
):
string
{
return
$code
;
// Unused
}
/** @inheritDoc */
protected
function
doPairs
():
array
{
return
[];
// Unused
}
/** @inheritDoc */
protected
function
getQuery
(
string
$text
,
string
$sourceLanguage
,
string
$targetLanguage
):
TranslationQuery
{
$params
=
[
'format'
=>
'json'
,
'action'
=>
'ttmserver'
,
'sourcelanguage'
=>
$sourceLanguage
,
'targetlanguage'
=>
$targetLanguage
,
'text'
=>
$text
];
if
(
isset
(
$this
->
config
[
'service'
]
)
)
{
$params
[
'service'
]
=
$this
->
config
[
'service'
];
}
return
TranslationQuery
::
factory
(
$this
->
config
[
'url'
]
)
->
timeout
(
intval
(
$this
->
config
[
'timeout'
]
)
)
->
queryParameters
(
$params
);
}
/** @inheritDoc */
protected
function
parseResponse
(
TranslationQueryResponse
$reply
)
{
$body
=
$reply
->
getBody
();
$parsed
=
FormatJson
::
decode
(
$body
,
true
);
if
(
!
is_array
(
$parsed
)
)
{
throw
new
TranslationWebServiceException
(
'Invalid json: '
.
serialize
(
$body
)
);
}
if
(
!
isset
(
$parsed
[
'ttmserver'
]
)
)
{
throw
new
TranslationWebServiceException
(
'Unexpected reply from remote server'
);
}
return
$parsed
[
'ttmserver'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 13:02 (1 d, 15 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8a/aa/b30b48e40a23508576fbbaf64b51
Default Alt Text
RemoteTTMServerWebService.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment