projectfluent / fluent

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

Term's attributes can't be used as placeable #339

Open caridy opened 2 years ago

caridy commented 2 years ago

It seems that some symmetry between messages and terms are missing, intentionally or not, and I will like to understand better the "why". Let's see the example from the documentation:

login-input = Predefined value
    .placeholder = email@example.com
    .aria-label = Login input value
    .title = Type your login email

-brand-name = Aurora
    .gender = feminine
    .anadrome = Arorua

x = { login-input.title }
y = { -brand-name.anadrome }

In this example, the message login-input can have attributes that are placeables, while -brand-name term can only have metadata (values for selection and such). The specific parsing error is: E0019: Attributes of terms cannot be used as placeables.

I might be missing some fundamental design principle that makes terms a lot more more restrictive than messages, but in principle, it looks to me that the ability to group information (of various kind) should be common for both. This issue is also in the same realm as https://github.com/projectfluent/fluent/issues/338.

cc @gonzalocordero

Pike commented 2 years ago

You're looking for parametrized terms, https://projectfluent.org/fluent/guide/terms.html.

FWIW, terms are not to group information, but to encapsulate terms that might change on context. Branding is one example, and the purpose of Terms doesn't go far beyond that.

zbraniecki commented 2 years ago

FWIW, terms are not to group information, but to encapsulate terms that might change on context.

That's the use case scenario Caridy has in his project but for a lot of terms like "Account", "Product", "User" etc. that they want to parametrize per product/consumer.

Pike commented 2 years ago

I smell #80?

zbraniecki commented 2 years ago

I'm not sure how they want to define relations between terms - @caridy is Dynamic References proposal fitting here for you?

caridy commented 2 years ago

@zbraniecki I'm not sure yet, let me dig deeper.

@Pike I got very confused, the dynamic references proposal by @stasm (in the issue description) explicitly adds information to the term making them more message-like, at least at first glance that's what I'm getting. I understand that that part is not necessary the core of the dynamic reference proposal, but nevertheless it is there.

stasm commented 2 years ago
-brand-name = Aurora
    .gender = feminine
    .anadrome = Arorua

Term's attributes were meant to capture metadata. The grammatical gender is a good example. However, the anadrome is not. Arorua is a facet of the brandname's value, a variant which depends on some grammatical or some other feature. It's translatable content, just like the main value, Aurora.

I'd suggest something like the following:

-brand-name =
    { $spelling->
       *[forwards] Aurora
        [backwards] Arorua
    }
    .gender = feminine

You can the use both variants in placeables:

hello = Hello, {-brand-name(spelling: "backwards")}!