Page MenuHomePhabricator

Add validator to ensure that a certain key / keys can only contain a set of values
Open, MediumPublic

Description

For the OSM Website project the language direction can either be ltr or rtl.

For this we need a validator that can validate that translation for certain key / keys can be one of a given set.

Details

Related Gerrit Patches:

Event Timeline

abi_ created this task.Sep 5 2019, 11:05 AM

Did we have another task for generic support of limiting the validator only to certain keys? I can't find such one.

abi_ added a comment.Sep 5 2019, 12:51 PM

Did we have another task for generic support of limiting the validator only to certain keys? I can't find such one.

Yes, here - T231705: Limit validation to certain messages

abi_ updated the task description. (Show Details)Nov 9 2019, 12:16 PM
abi_ added a comment.Nov 9 2019, 1:32 PM

Validator name: MatchSetValidator

Syntax

- id: MatchSetValidator
  params: 
    values:            # Possible values for the translation
      - ltr 
      - rtl
      - hello
    min: 1             # Out of the set, atleast one value should be present in translation
    max: 2             # Out of the set, atleast two distinct (duplicate: false) values should be present in translation
    duplicate: false   # Should duplicate values from the set be allowed
abi_ renamed this task from Add validator to validate that a certain key / keys can only contain a set of values to Add validator to ensure that a certain key / keys can only contain a set of values.Nov 9 2019, 1:33 PM
abi_ triaged this task as Medium priority.

Adding to the current language board, since this validator will be needed for OSM website.

abi_ added a comment.Nov 9 2019, 2:03 PM

For now, keeping things simple, and planning to get rid of the min / max parameters. These will be a little trickier to support. For eg, given the above configuration, user translated a string to:

ltr, rtl

We have an extra , above that complicates things. That comma could be instead replaced by a ;, <space>, | etc.

So sticking with the following options for now,

- id: MatchSetValidator
  params: 
    values:                        # Possible values for the translation
      - ltr 
      - rtl
      - hello
    caseSensitive:  true / false   # Whether a case sensitive comparison should be performed. True by default.
abi_ claimed this task.Nov 9 2019, 4:54 PM

Change 549977 had a related patch set uploaded (by Abijeet Patro; owner: Abijeet Patro):
[mediawiki/extensions/Translate@master] Add validator to check that translation matches value from a set

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

Change 549977 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] Add validator to check that translation matches value from a set

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