jenkins-bot has submitted this change and it was merged.
Change subject: API support to get untranslated, translated and outdated
messages in the target language, using MessageCollection.
......................................................................
API support to get untranslated, translated and outdated messages in the target
language, using MessageCollection.
By default:
* the source language is the wiki's content language,
* the target language is the interface language.
Use parameter 'filter=untranslated' to get the untranslated messages,
'filter=translated' to get the translated messages and
'filter=fuzzy' to get the outdated messages.
Bug: T106931
Change-Id: I7c55a9b73ef32301fa50fe6a4ef780267ba9cd1c
---
M api/ApiSearchTranslations.php
M i18n/api/en.json
M i18n/api/qqq.json
3 files changed, 59 insertions(+), 11 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/ApiSearchTranslations.php b/api/ApiSearchTranslations.php
index d2ff211..eb2ff13 100644
--- a/api/ApiSearchTranslations.php
+++ b/api/ApiSearchTranslations.php
@@ -12,29 +12,64 @@
$config = $wgTranslateTranslationServices[$params['service']];
$server = TTMServer::factory( $config );
- $searchResults = $server->search(
- $params['query'],
- $params,
- array( '', '' )
- );
-
$result = $this->getResult();
- $documents = $server->getDocuments( $searchResults );
+ if ( $params['filter'] !== '' ) {
+ $translationSearch = new
CrossLanguageTranslationSearchQuery( $params, $server );
+ $documents = $translationSearch->getDocuments();
+ $total = $translationSearch->getTotalHits();
+ } else {
+ $searchResults = $server->search(
+ $params['query'],
+ $params,
+ array( '', '' )
+ );
+ $documents = $server->getDocuments( $searchResults );
+ $total = $server->getTotalHits( $searchResults );
+ }
+ $result->addValue( array( 'search', 'metadata' ), 'total',
$total );
$result->addValue( 'search', 'translations', $documents );
}
- public function getAllowedParams() {
+ protected function getAvailableTranslationServices() {
global $wgTranslateTranslationServices;
+
+ $good = array();
+ foreach ( $wgTranslateTranslationServices as $id => $config ) {
+ if ( TTMServer::factory( $config ) instanceof
SearchableTTMServer ) {
+ $good[] = $id;
+ }
+ }
+
+ return $good;
+ }
+
+ protected function getAllowedFilters() {
+ return array(
+ '',
+ 'translated',
+ 'fuzzy',
+ 'untranslated'
+ );
+ }
+
+ public function getAllowedParams() {
+ global $wgLanguageCode;
+ $available = $this->getAvailableTranslationServices();
+ $filters = $this->getAllowedFilters();
return array(
'service' => array(
- ApiBase::PARAM_TYPE => array_keys(
$wgTranslateTranslationServices ),
+ ApiBase::PARAM_TYPE => $available,
ApiBase::PARAM_DFLT => 'TTMServer',
),
'query' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'sourcelanguage' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => $wgLanguageCode,
),
'language' => array(
ApiBase::PARAM_TYPE => 'string',
@@ -42,6 +77,10 @@
),
'group' => array(
ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => '',
+ ),
+ 'filter' => array(
+ ApiBase::PARAM_TYPE => $filters,
ApiBase::PARAM_DFLT => '',
),
'offset' => array(
@@ -62,6 +101,7 @@
public function getExamples() {
return array(
'api.php?action=searchtranslations&language=fr&query=aide',
+
'api.php?action=searchtranslations&language=fr&query=edit&filter=untranslated'
);
}
@@ -70,6 +110,8 @@
return array(
'action=searchtranslations&language=fr&query=aide'
=> 'apihelp-searchtranslations-example-1',
+
'action=searchtranslations&language=fr&query=edit&filter=untranslated'
+ => 'apihelp-searchtranslations-example-2',
);
}
}
diff --git a/i18n/api/en.json b/i18n/api/en.json
index 06876b3..b0f259f 100644
--- a/i18n/api/en.json
+++ b/i18n/api/en.json
@@ -78,9 +78,12 @@
"apihelp-searchtranslations-description": "Search translations.",
"apihelp-searchtranslations-param-service": "Which of the available
translation services to use.",
"apihelp-searchtranslations-param-query": "The string to search for.",
+ "apihelp-searchtranslations-param-sourcelanguage": "The language code
of the source text.",
"apihelp-searchtranslations-param-language": "The language code to
search string for.",
"apihelp-searchtranslations-param-group": "The group id to search
string in.",
+ "apihelp-searchtranslations-param-filter": "Message translation status
filter.",
"apihelp-searchtranslations-param-offset": "Offset for the
translations.",
"apihelp-searchtranslations-param-limit": "Size of the result.",
- "apihelp-searchtranslations-example-1": "Show translations for the
language."
+ "apihelp-searchtranslations-example-1": "Show translations for the
language.",
+ "apihelp-searchtranslations-example-2": "Show untranslated messages
matching the query in the source language."
}
diff --git a/i18n/api/qqq.json b/i18n/api/qqq.json
index fccd583..4217fa6 100644
--- a/i18n/api/qqq.json
+++ b/i18n/api/qqq.json
@@ -83,9 +83,12 @@
"apihelp-searchtranslations-description":
"{{doc-apihelp-description|searchtranslations}}",
"apihelp-searchtranslations-param-service":
"{{doc-apihelp-param|searchtranslations|service}}",
"apihelp-searchtranslations-param-query":
"{{doc-apihelp-param|searchtranslations|query}}",
+ "apihelp-searchtranslations-param-sourcelanguage":
"{{doc-apihelp-param|searchtranslations|sourcelanguage}}",
"apihelp-searchtranslations-param-language":
"{{doc-apihelp-param|searchtranslations|language}}",
"apihelp-searchtranslations-param-group":
"{{doc-apihelp-param|searchtranslations|group}}",
+ "apihelp-searchtranslations-param-filter":
"{{doc-apihelp-param|searchtranslations|filter}}",
"apihelp-searchtranslations-param-offset":
"{{doc-apihelp-param|searchtranslations|offset}}",
"apihelp-searchtranslations-param-limit":
"{{doc-apihelp-param|searchtranslations|limit}}",
- "apihelp-searchtranslations-example-1":
"{{doc-apihelp-example|searchtranslations}}"
+ "apihelp-searchtranslations-example-1":
"{{doc-apihelp-example|searchtranslations}}",
+ "apihelp-searchtranslations-example-2":
"{{doc-apihelp-example|searchtranslations}}"
}
--
To view, visit https://gerrit.wikimedia.org/r/227677
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7c55a9b73ef32301fa50fe6a4ef780267ba9cd1c
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Phoenix303 <[email protected]>
Gerrit-Reviewer: Nemo bis <[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