Skip to content

reusing terms to create more complex terms #337

Open

Description

@caridy

When terms inside other terms, there is a limitation around passing variables down to other terms, but I'm not sure about the nature of such limitation. Here is an example:

-bar = { $n -> 
    [0] some
    *[1] another
}
-foo = before { -bar(n: $x) } after

-foo is just an abstraction around -bar, delegating to it a piece of the message, but passing $x down to -bar is forbidden, with parsing error E0014: Expected literal.

cc @gonzalocordero

Activity

  1. zbraniecki commented on Nov 5, 2021

    @zbraniecki
    Collaborator

    @stasm - can you recall the rationale?

  2. stasm commented on Nov 10, 2021

    @stasm
    Contributor

    I have a vague memory of wanting to forbid exactly this kind of use-cases. IIRC, my argument was that this increases the complexity, makes the translations harder to reason about, and is generally something that programmers like to do, because we like factoring things out in the name of DRY. Whereas Fluent was based around WET: write everything twice, because we assumed WET would easier for translators, translation memories, and machine translation systems.

    When you're saying -foo is just an abstraction around -bar, it sounds like a red flag to me. Can you provide a more concrete example of what you're trying to achieve?

  3. dolezvo1 commented on Dec 27, 2025

    @dolezvo1

    I would like to see something like this, and I was quite surprised you can't actually parameterise a term with a runtime value.

    I think a good use case would be the reuse of pluralisation. For example if you have hundreds of messages like this, copy-pasting the pluralisation code would be unbearable, not to mention if you have inflected variants and whatnot:

    -terms-item = { $count ->
       [one] { $count } item
      *[other] { $count } items
    }
    replace-items = Replace { -terms-item(count: $countOld) } with { -terms-item(count: $countNew) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions