fluent.js icon indicating copy to clipboard operation
fluent.js copied to clipboard

[Question] How can a variable be referenced in terms params?

Open moaali opened this issue 1 year ago • 0 comments

I'm trying to add translation to Arabic project, in arabic there are 6 versions of the same word that is variable of both gender and count for example:

[female]
  [1] v1
  [2] v2
  [other] v3
[male]
  [1] v4
  [2] v5
  [other] v6

the FTL I used to achieve the result:

-add-text-female = {
  $count ->
    [1] اضافت
    [2] اضافتا
    *[other] اضفن
}

-add-text-male = {
  $count ->
    [1] اضاف
    [2] اضافا
    *[other] اضافوا
}

notification-body = {$members} {
  $gender ->
    [male] {-add-text-male(count: $membersCount)}
    [female] {-add-text-female(count: $membersCount)}
    *[other] {-add-text-male}
} {
  $count ->
    [one] منتج واحد
    [two] منتجين
    [few] {$countDisplay} منتجات
    [many] {$countDisplay} منتج
    *[other] {$countDisplay} منتج
}

the above works fine only if I passed the value of $membersCount variable to the term (i.e. {-add-text-male(count: 2)}) but when I use the variable name it doesn't work, I tried to search in the docs on how to reference variable in terms but I didn't find anything.

So my question is, is it possible achieve the result I'm after using the dynamic value of $membersCount in terms? if so, what is the correct syntax? If not possible how similar result could be achieved?

moaali avatar Mar 16 '24 15:03 moaali