projectfluent / fluent

Fluent — planning, spec and documentation
https://projectfluent.org
Apache License 2.0
1.37k stars 43 forks source link

EVAL builtin function #350

Open juliancoffee opened 1 year ago

juliancoffee commented 1 year ago

As far as I know in Fluent we can't parametrise arguments. In a sense that this code will be impossible to parse.

skeleton = {$case ->
  [genitive] Skeleton
  [possessive] by Skeleton
}
cultist = {$case ->
  [genitive] Cultist
  [possessive] by Cultist
}
shoot = { $victim } has be shoot { $attacker(case: "possessive") }

This is obviously not a problem for English, but it is a problem for other languages with grammatical cases, for example, Slavic ones. https://en.wikipedia.org/wiki/Grammatical_case (I translated the bear was killed by another bear to Polish and got niedźwiedź został również zabity przez innego niedźwiedzia. You can see the difference between niedźwiedź and niedźwiedzia)

So to solve it, I was thinking about adding EVAL function, which would take its first parameter as a term and pass args to it.

shoot = { $victim } has been shoot { EVAL($attacker, case: "possessive") }

P. S. after creating this, I saw https://github.com/projectfluent/fluent/issues/80 which would probably cover a lot of cases, but I thought about tossing this idea here in case someone would find it valuable.