jenkins-bot has submitted this change and it was merged.
Change subject: braceBalanceCheck/XhtmlCheck: do not add warning if same as
definition
......................................................................
braceBalanceCheck/XhtmlCheck: do not add warning if same as definition
Let's not enforce these checks even if the definition has warnable content as
it is
counter-intuitive for translators. This is especially a problem for translatable
pages as the translation gets fuzzied if there is warning so the translation
page
does not get re-rendered even if the unit was updated. That behavior should
probably
be changed but that's for a separate patch.
Bug: T134692
Bug: T53226
Change-Id: I8943a0a9d50edeb82214c22106fc5e15cd91d1bf
---
M MediaWikiMessageChecker.php
M MessageChecks.php
2 files changed, 25 insertions(+), 3 deletions(-)
Approvals:
Nikerabbit: Checked; Looks good to me, approved
jenkins-bot: Verified
diff --git a/MediaWikiMessageChecker.php b/MediaWikiMessageChecker.php
index 43df31d..7942501 100644
--- a/MediaWikiMessageChecker.php
+++ b/MediaWikiMessageChecker.php
@@ -117,11 +117,18 @@
'~<(BR|Br|bR) />~su' => '<br />',
);
+ $definition = $message->definition();
+
$wrongTags = array();
foreach ( $tags as $wrong => $correct ) {
$matches = array();
preg_match_all( $wrong, $translation, $matches,
PREG_PATTERN_ORDER );
foreach ( $matches[0] as $wrongMatch ) {
+ if ( strpos( $definition, $wrongMatch )
!== false ) {
+ // If the message definition
contains a
+ // non-strict string, do not
enforce it
+ continue;
+ }
$wrongTags[$wrongMatch] = "$wrongMatch
→ $correct";
}
}
diff --git a/MessageChecks.php b/MessageChecks.php
index df6d604..793f7a5 100644
--- a/MessageChecks.php
+++ b/MessageChecks.php
@@ -308,6 +308,9 @@
/**
* Checks if the translation has even number of opening and closing
* parentheses. {, [ and ( are checked.
+ * Note that this will not add a warning if the message definition
+ * has an unbalanced amount of braces.
+ *
* @param TMessage[] $messages Iterable list of TMessage objects.
* @param string $code Language code
* @param array $warnings Array where warnings are appended to.
@@ -331,16 +334,18 @@
$counts[$char]++;
}
+ $definition = $message->definition();
+
$balance = array();
- if ( $counts['['] !== $counts[']'] ) {
+ if ( $counts['['] !== $counts[']'] &&
self::checkStringCountEqual( $definition, '[', ']' ) ) {
$balance[] = '[]: ' . ( $counts['['] -
$counts[']'] );
}
- if ( $counts['{'] !== $counts['}'] ) {
+ if ( $counts['{'] !== $counts['}'] &&
self::checkStringCountEqual( $definition, '{', '}' ) ) {
$balance[] = '{}: ' . ( $counts['{'] -
$counts['}'] );
}
- if ( $counts['('] !== $counts[')'] ) {
+ if ( $counts['('] !== $counts[')'] &&
self::checkStringCountEqual( $definition, '(', ')' ) ) {
$balance[] = '(): ' . ( $counts['('] -
$counts[')'] );
}
@@ -356,6 +361,16 @@
}
/**
+ * @param string $source
+ * @param string $str1
+ * @param string $str2
+ * @return bool whether $source has an equal number of occurences of
$str1 and $str2
+ */
+ protected static function checkStringCountEqual( $source, $str1, $str2
) {
+ return substr_count( $source, $str1 ) === substr_count(
$source, $str2 );
+ }
+
+ /**
* Checks for missing and unknown printf formatting characters in
* translations.
* @param TMessage[] $messages Iterable list of TMessage objects.
--
To view, visit https://gerrit.wikimedia.org/r/287889
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8943a0a9d50edeb82214c22106fc5e15cd91d1bf
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits