Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5993605
MatchSetValidator.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
MatchSetValidator.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Validation\Validators
;
use
InvalidArgumentException
;
use
MediaWiki\Extension\Translate\MessageLoading\Message
;
use
MediaWiki\Extension\Translate\Validation\MessageValidator
;
use
MediaWiki\Extension\Translate\Validation\ValidationIssue
;
use
MediaWiki\Extension\Translate\Validation\ValidationIssues
;
/**
* Ensures that the translation for a message matches a value from a list.
* @license GPL-2.0-or-later
* @since 2019.12
*/
class
MatchSetValidator
implements
MessageValidator
{
/** @var string[] */
private
array
$possibleValues
;
/** @var string[] */
private
array
$normalizedValues
;
private
bool
$caseSensitive
;
public
function
__construct
(
array
$params
)
{
$this
->
possibleValues
=
$params
[
'values'
]
??
[];
$this
->
caseSensitive
=
(
bool
)(
$params
[
'caseSensitive'
]
??
true
);
if
(
$this
->
possibleValues
===
[]
)
{
throw
new
InvalidArgumentException
(
'No values provided for MatchSet validator.'
);
}
if
(
$this
->
caseSensitive
)
{
$this
->
normalizedValues
=
$this
->
possibleValues
;
}
else
{
$this
->
normalizedValues
=
array_map
(
'strtolower'
,
$this
->
possibleValues
);
}
}
public
function
getIssues
(
Message
$message
,
string
$targetLanguage
):
ValidationIssues
{
$issues
=
new
ValidationIssues
();
$translation
=
$message
->
translation
();
if
(
$this
->
caseSensitive
)
{
$translation
=
strtolower
(
$translation
);
}
if
(
!
in_array
(
$translation
,
$this
->
normalizedValues
,
true
)
)
{
$issue
=
new
ValidationIssue
(
'value-not-present'
,
'invalid'
,
'translate-checks-value-not-present'
,
[
[
'PLAIN-PARAMS'
,
$this
->
possibleValues
],
[
'COUNT'
,
count
(
$this
->
possibleValues
)
]
]
);
$issues
->
add
(
$issue
);
}
return
$issues
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 4 2026, 02:50 (4 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bc/54/c76ba515da2e16a54b0576d5500e
Default Alt Text
MatchSetValidator.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment