Page MenuHomePhabricator

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

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.

Event Timeline

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

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

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.

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.

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

We've deployed this on translatewiki.net. For OpenStreetMap, the valid values for html.direction have been set to ltr, rtl.

image.png (589×1 px, 82 KB)