eemeli / message-resource-wg

Developing a standard for Unicode MessageFormat 2 resources
4 stars 1 forks source link

Allow a method for specifying variations / modifiers #20

Open SimonClark opened 9 months ago

SimonClark commented 9 months ago

As a resource bundle author, I want to specify variations of a string...

mouse_ItemName = mouse

@modifiers pluralform-many
mouse_ItemName = mice

iPhone_ItemName = iPhone

@modifiers sentence-start
iPhone_ItemName = iPhone

Further, it should be possible to specify multiple modifiers:

racoon_ItemName = racoon

@modifiers pluralform-many
racoon_ItemName = racoons

@modifiers slang
racoon_ItemName = trash panda

@modifiers pluralform-many slang
racoon_ItemName = trash pandas

I would expect there to be a set of common modifiers that most implementors would find useful, however, the modifiers should not be limited to that set, but open for extension...

taxJurisdiction_FieldLabel = Tax jurisdiction

@modifiers locale-US
taxJurisdiction_FieldLabel = Nexus
eemeli commented 9 months ago

These sorts of modifiers are perhaps best handled in the message format itself; they're a core feature of MF2. With that, your examples could be expressed as:

mouse_ItemName = .match {$num :plural}
  one {{mouse}}
  * {{mice}}

iPhone_ItemName = .match {$pos :position}
  sentence-start {{iPhone}}
  * {{iPhone}}

raccoon_ItemName = .match {$tone :tone} {$count :plural}
  slang one {{trash panda}}
  slang *   {{trash pandas}}
  *     one {{raccoon}}
  *     *   {{raccoons}}

taxJurisdiction_FieldLabel = .match {$locale :region}
  us {{Nexus}
  * {{Tax jurisdiction}}

Note that all of the non-pattern whitespace in MF2 effectively collapses to a single space, so it's there only for legibility. Also, only the :plural selector of the above is included in the MF2 core set; all the others would need some custom implementations.

SimonClark commented 9 months ago

Yes, good point. And in many cases this might be the ideal solution.

One of the usecases that I am trying to solve for is where the variants and the parameters may be more freeform and unknown at authoring time.

Suppose I have field level help for a "Subsidiary" field on my employee record. The field level help states that the subsidiary field is not mandatory.

A partner delivers a new platform app that pays benefits in the Canadian market. So, if that app is installed and if the employee is Canadian, then the partner needs to deliver a variant of field level help that will only be seen on employee forms of Canadian employees.

They should be able to deliver a resource file that is merged in with the existing resources

@modifiers canadian_employee
employeeSubsidiary_FieldHelp = The subsidiary must be specified for Canadian employees in order to pay CPP benefits