Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5988204
GettextNewlineValidator.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
GettextNewlineValidator.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Validation\Validators
;
use
MediaWiki\Extension\Translate\MessageLoading\Message
;
use
MediaWiki\Extension\Translate\Validation\ValidationIssues
;
/**
* Ensures that the translation has the same number of newlines as the source
* message at the beginning and end of the string. This works specifically
* for GettextFormat.
* @author Abijeet Patro
* @license GPL-2.0-or-later
* @since 2019.09
*/
class
GettextNewlineValidator
extends
NewlineValidator
{
public
function
getIssues
(
Message
$message
,
string
$targetLanguage
):
ValidationIssues
{
$translation
=
$message
->
translation
();
$definition
=
$message
->
definition
();
// ending newlines in GetText are bounded by a "\"
$definition
=
$this
->
removeTrailingSlash
(
$definition
);
$translation
=
$this
->
removeTrailingSlash
(
$translation
);
$definitionStartNewline
=
$this
->
getStartingNewLinesCount
(
$definition
);
$definitionEndNewline
=
$this
->
getEndingNewLineCount
(
$definition
);
$translationStartNewline
=
$this
->
getStartingNewLinesCount
(
$translation
);
$translationEndNewline
=
$this
->
getEndingNewLineCount
(
$translation
);
$failingChecks
=
array_merge
(
$this
->
validateStartingNewline
(
$definitionStartNewline
,
$translationStartNewline
),
$this
->
validateEndingNewline
(
$definitionEndNewline
,
$translationEndNewline
)
);
return
$this
->
createIssues
(
$failingChecks
);
}
private
function
removeTrailingSlash
(
string
$str
):
string
{
if
(
substr
(
$str
,
-
strlen
(
'
\\
'
)
)
===
'
\\
'
)
{
return
substr
(
$str
,
0
,
-
1
);
}
return
$str
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Oct 4, 00:43 (3 w, 9 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
80/90/6c2dc8dc1220715f32b7bfedc616
Default Alt Text
GettextNewlineValidator.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment