Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7419635
QueryAggregatorAwareTranslationAid.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
QueryAggregatorAwareTranslationAid.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Aid
;
use
MediaWiki\Extension\Translate\WebService\QueryAggregator
;
use
MediaWiki\Extension\Translate\WebService\QueryAggregatorAware
;
use
MediaWiki\Extension\Translate\WebService\TranslationWebService
;
/**
* Helper class for translation aids that use web services.
* @ingroup TranslationAids
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2015.02
*/
abstract
class
QueryAggregatorAwareTranslationAid
extends
TranslationAid
implements
QueryAggregatorAware
{
/** @var array[] */
private
$queries
=
[];
/** @var QueryAggregator */
private
$aggregator
;
public
function
setQueryAggregator
(
QueryAggregator
$aggregator
):
void
{
$this
->
aggregator
=
$aggregator
;
}
/**
* Stores a web service query for later execution.
* @param TranslationWebService $service
* @param string $from
* @param string $to
* @param string $text
* @return void
*/
protected
function
storeQuery
(
TranslationWebService
$service
,
string
$from
,
string
$to
,
string
$text
):
void
{
$queries
=
$service
->
getQueries
(
$text
,
$from
,
$to
);
foreach
(
$queries
as
$query
)
{
$this
->
queries
[]
=
[
'id'
=>
$this
->
aggregator
->
addQuery
(
$query
),
'language'
=>
$from
,
'text'
=>
$text
,
'service'
=>
$service
,
];
}
}
/**
* Returns all stored queries.
* @return array Map of executed queries:
* - language: string: source language
* - text: string: source text
* - response: TranslationQueryResponse
*/
protected
function
getQueryData
():
array
{
foreach
(
$this
->
queries
as
&
$queryData
)
{
$queryData
[
'response'
]
=
$this
->
aggregator
->
getResponse
(
$queryData
[
'id'
]
);
unset
(
$queryData
[
'id'
]
);
}
return
$this
->
queries
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 04:34 (1 d, 5 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
14/7b/7ca031c0e0ce5983ddcd2ce5ae28
Default Alt Text
QueryAggregatorAwareTranslationAid.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment