Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4141204
MintCxserverWebService.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
MintCxserverWebService.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\WebService
;
/**
* Implements support for MinT translation service via the Cxserver API
* @ingroup TranslationWebService
* @author Abijeet Patro
* @license GPL-2.0-or-later
* @since 2023.06
*/
class
MintCxserverWebService
extends
CxserverWebService
{
private
const
WIKITEXT_REGEX
=
[
'/
\b
(PLURAL|GRAMMAR|GENDER)
\b
/'
,
'/==
\s
*([^=]+)
\s
*==/'
,
// heading
"/''.+?''/"
,
// italics & bold
'/
\[\[
([^
\[\]
]+)
\]\]
/'
,
// links
'/
\{\{
([^{}]+)
\}\}
/'
,
// templates
];
private
const
EXCLUDED_TARGET_LANGUAGES
=
[
'zh'
];
protected
function
handlePairsForService
(
array
$response
):
array
{
$pairs
=
[];
foreach
(
$response
[
$this
->
getServiceName
()]
as
$source
=>
$targets
)
{
$filteredTargets
=
array_diff
(
$targets
,
self
::
EXCLUDED_TARGET_LANGUAGES
);
foreach
(
$filteredTargets
as
$target
)
{
$pairs
[
$source
][
$target
]
=
true
;
}
}
return
$pairs
;
}
protected
function
getServiceName
():
string
{
return
'MinT'
;
}
protected
function
handleServiceResponse
(
array
$responseBody
):
string
{
return
trim
(
$this
->
unwrapUntranslatable
(
$responseBody
[
'contents'
]
)
);
}
protected
function
wrapUntranslatable
(
string
$text
):
string
{
// Check if at least one instance of the patterns exists in the source string
foreach
(
self
::
WIKITEXT_REGEX
as
$pattern
)
{
if
(
preg_match
(
$pattern
,
$text
)
)
{
throw
new
TranslationWebServiceInvalidInputException
(
'Wikitext instance(s) in source string. See T349375'
);
}
}
return
$text
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 15:51 (3 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
dc/f0/51c709dd13d56ea53a9b195c9b21
Default Alt Text
MintCxserverWebService.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment