projectfluent / fluent

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

Can Terms reference variables passed to the parent Message? #272

Open stasm opened 5 years ago

stasm commented 5 years ago
-wrong-user = (Not {$userName}? Click here.)
hello = Hello, {$userName}! {-wrong-user}

Or should we require that each variable be passed explicitly as a parameter? Related to #230.

-wrong-user = (Not {$userName}? Click here.)
hello = Hello, {$userName}! {-wrong-user(userName: $userName)}
eemeli commented 5 years ago

I asked a related issue about this earlier in the fluent.js repo, as I wasn't certain to start with if it was a spec or implementation issue: projectfluent/fluent.js#372.

My preference would be for variable's default values to be fetched from the parent message scope, rather than just assumed empty. That would probably be the least surprising thing to happen, from the point of view of a translator who's adding their first parameterised term.

stasm commented 5 years ago

Falling back to the calling message's scope might lead to unexpected naming conflicts when a term with a $foo parameter is used in a new message which also expects a $foo variable from the developer. This would make terms less portable; every reference would need to be verified against the list of variables passed to the message referencing the term. This is particularly dangerous given that this list may change overtime without any involvement from the localizer, for instance when the developer starts passing new/more variables to bundle.format.

eemeli commented 5 years ago

Is that sufficient reason to settle the answer to this issue's question as "no" then?

Pike commented 5 years ago

I think terms should be isolated from the message. That's giving more power to localizers, in particular in scenarios where we want to have language-specific terms. Examples here would be terms that depend on the platform just for a single language, like in Japanese.

I also think that most of the time, needing external variables in a term is probably a sign that you don't want a term, but translation memory. We're WET, after all ;-)

stasm commented 5 years ago

Is that sufficient reason to settle the answer to this issue's question as "no" then?

I think so, yes!

I'm leaving this open until I have a few tests in the reference implementation which verify the intended behavior.

caridy commented 2 years ago

Certainly I favor the explicit variable. Passing variables from the message to the term seems to be a recurrent topic, and IMO should be resolved. I understand that for selection, pluralization, and such passing the corresponding value as literal is sufficient for the terms to be useful, but for things as the example described here, or for any number/datetime formatting, passing the variable from the message to the term in an explicit way (including renaming of it) is certainly useful.