Page MenuHomePhabricator

Section Translation: Proper initialization of source/target language pair
Closed, ResolvedPublic

Description

Problem definition
Currently when Section Application is initialized, target language is being set to the first enabled target language (as declared inside "SectionTranslationTargetLanguages" configuration parameter). If this configuration parameter is null or empty, then (and only then) the target language is being set to the value of the "to" URL parameter, if it exists. Finally, if no such URL parameter exists, the target language is set to "es" language, which is the language that we use for test purposes.

The above logic worked well for our case until now, since we only had one single language enabled for target language in production. However, this logic leads to several issues, when enabling more target languages:

  1. Considering we want to enable Section Translation for Igbo, Hausa, Yoruba and Thai languages, the "SectionTranslationTargetLanguages" will look like this:
SectionTranslationTargetLanguages": ["bn", "ig", "ha", "yo", "th"]

Because of the way target language is initialized right now, "bn" will be the initial target language in Section Translation application, even if user visits "ig" or any other Wikipedia.

  1. The "to" URL parameter will never be respected in production since "SectionTranslationTargetLanguages" configuration parameter is always set in this environment.

Solution
To begin with, since target language seems more important for our purposes, it should be defined first. In case of matching source-target languages, the source language should be updated to a different language according to some logic (source and target languages cannot be the same language).

Initializing target language

Target language should be initialized according to the logic below:

  1. If URL parameter "to" exists, then the value of this parameter should be taken into account first, and target language should be set to this value if possible. By possible, we mean that the value of this "to" URL parameter is a valid language code and this language code is enabled as target language for this wiki (if "SectionTranslationTargetLanguages" configuration parameter is set).
  2. If step 1 fails to set target language, then current wiki language should be used to set as target language if possible. Again, this language code should be enabled as target language or "SectionTranslationTargetLanguages" parameter should bet unset.
  3. If step 2 fails too, then the first enabled target language should be set as target language, if "SectionTranslationTargetLanguages" configuration parameter is set. If not, the target language should be set to "es" language, which is the default language for our test purposes.

Initializing source language
As it has already been referred, the initialization of target language is prioritized over the source language. This means that the source language is initialized after the target language and can only be set to values that are different than the already initialized target language. More specifically:

  1. the source language should be set to the "from" URL parameter if it exists and is different than the target language
  2. If not, it should be set to the default source language ("en") if target language is not equal to "en"
  3. If not, it should be set to the current wiki language, if target language is not equal to this language
  4. and finally if neither of the above cases work, the source language is set to the default target language ("es") that we use for our test purposes.

The above logic means that in the case of a dev environment with empty "SectionTranslationTargetLanguages" and "en" set as current wiki language, the default language pair will be "es" to "en".

Following the calculation of the language pair, the application will either store these values inside the application's Vuex Store, or redirect to the appropriate wiki. This behaviour depends on "ContentTranslationTranslateInTarget" configuration parameter, which indicates whether a translation in a target language can only be published from the corresponding wiki in this language. This parameter is set to false for development and test environments and is true for production environments.

Event Timeline

Change 725315 had a related patch set uploaded (by Nik Gkountas; author: Nik Gkountas):

[mediawiki/extensions/ContentTranslation@master] SX: Add initializeLanguages vuex action

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

Change 725315 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] SX: Add initializeLanguages vuex action

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

Peding: Refactor the current implementation to make sure URL param access and navigation changes are outside the application store.