fluent icon indicating copy to clipboard operation
fluent copied to clipboard

Can Terms reference variables passed to the parent Message?

Open stasm opened this issue 6 years ago • 6 comments

-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)}

stasm avatar Jun 07 '19 14:06 stasm

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.

eemeli avatar Jun 09 '19 06:06 eemeli

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.

stasm avatar Jun 13 '19 07:06 stasm

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

eemeli avatar Jun 13 '19 13:06 eemeli

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 ;-)

Pike avatar Jun 27 '19 14:06 Pike

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.

stasm avatar Jul 03 '19 17:07 stasm

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.

caridy avatar Nov 24 '21 21:11 caridy