Page MenuHomePhabricator

Allow custom source languages for aggregate groups
Closed, ResolvedPublic

Description

As of T37489, Translate supports arbitrary source languages for translatable pages, which can either be set via Special:PageContentLanguage or programmatically via a PageContentLanguage hook. This does not extend to aggregate groups yet, which are still hardcoded to English. As a result, trying to translate the whole group at once into English via Special:Translate doesn't work, with ApiQueryMessageCollection returning a apiwarn-translate-language-disabled-source message.

For now, the simplest way to achieve this would be to add a new optional metadata key, consistent with MessageGroupBase::getSourceLanguage(), to at least allow manual configuration by inserting rows into the translate_metadata table. On top of 7c2802b:

diff
--- a/messagegroups/loaders/AggregateMessageGroupLoader.php
+++ b/messagegroups/loaders/AggregateMessageGroupLoader.php
@@ -104,20 +104,23 @@ class AggregateMessageGroupLoader extends MessageGroupLoader
 		foreach ( $groupIds as $id ) {
 			$conf = [];
 			$conf['BASIC'] = [
 				'id' => $id,
 				'label' => TranslateMetadata::get( $id, 'name' ),
 				'description' => TranslateMetadata::get( $id, 'description' ),
 				'meta' => 1,
 				'class' => AggregateMessageGroup::class,
 				'namespace' => NS_TRANSLATIONS,
 			];
+			if ( $sourcelanguage = TranslateMetadata::get( $id, 'sourcelanguage' ) ) {
+				$conf['BASIC']['sourcelanguage'] = $sourcelanguage;
+			}
 			$conf['GROUPS'] = TranslateMetadata::getSubgroups( $id );
 			$groups[$id] = $conf;
 		}
 
 		return $groups;
 	}

It's not optimal because an aggregate group may still contain pages in any source language, which you may or may not want to prevent. But it'd be good enough for a first step.

Event Timeline

Yes, that proposal would work fine for my use case as well.

This comment T301311#7714254 from @Nikerabbit might be the best option to go for as we don't need to complicate the source language selection with options like calculating the most common source language in an aggregate group. This brings up the question as to how we should handle a case where one of the message groups is in es and another is in fr; which, I also don't imagine would be an impossible scenario. Should we restrict that and ensure all message groups under the aggregate are in the same source language? How would that affect existing aggregate groups?

image.png (225×738 px, 19 KB)

P.S we might also want to consider OOUI updates to the page.

We had a discussion with @Pginer-WMF and @Nikerabbit regarding this feature request.

Here's what was identified:

Every aggregate group will have a source language that can be identified in either of two ways:

  1. Add a drop-down and the user selects the source language when creating the aggregate group.
  2. Determine the aggregate group using the first message group that is added to the aggregate group.

We are currently leaning towards the first option due to its simplicity.

Users will not be allowed to add message groups having a different source language than the language of the aggregate groups. Editing of aggregate groups to change the source language should require removing all the current message groups under it and then updating the language. This can be automated later.

For existing aggregate groups, the source language will be assumed to be English. Existing aggregate groups may already contain message groups that have different source languages. To not break existing aggregate groups, we may allow aggregate groups to not define a source language.

If the user specifies a source language for an aggregate group that has message groups with different source languages, we should show them a warning that informs them off these message groups that have a different source language then the one selected.

Change 882423 had a related patch set uploaded (by Wangombe; author: Wangombe):

[mediawiki/extensions/Translate@master] Special:AggregateGroups source language selection

https://gerrit.wikimedia.org/r/882423

Change 883505 had a related patch set uploaded (by Wangombe; author: Wangombe):

[mediawiki/extensions/Translate@master] Special:AggregateGroups - source language selection

https://gerrit.wikimedia.org/r/883505

Change 882423 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] Special:AggregateGroups: Add source language selector

https://gerrit.wikimedia.org/r/882423

Change 883505 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] AggregateGroups: Allow setting a source language

https://gerrit.wikimedia.org/r/883505

Change 886870 had a related patch set uploaded (by Wangombe; author: Wangombe):

[mediawiki/extensions/Translate@master] Big fixes when on Special:AggregateGroups

https://gerrit.wikimedia.org/r/886870

Change 886870 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] Special:AggregateGroups: Bug fixes in source language implementation

https://gerrit.wikimedia.org/r/886870

Deployed on Translatewiki, found a couple of issues:

  • When displaying alert, the group names don't have namespaces.
  • "Unselecting" a source language does not work. It retains the previously selected source language.

These were solved in the[[ https://gerrit.wikimedia.org/r/886870 | subsequent patch ]]