Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions guide/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ are only available to developers when they pre-format variables passed as
arguments to translations (see [Partially-formatted
variables](#partially-formatted-variables) below).

Any inline expression may be used as a positional argument,
but named argument values are limited to literal values in Fluent 1.0.
In Fluent 1.1, a variable reference may also be used as a named argument value.

## Built-in Functions

Built-in functions are very generic and should be applicable to any translation
Expand Down
3 changes: 2 additions & 1 deletion guide/terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ or they can interpolate other expressions, including variables. However,
while messages receive data for variables directly from the app, terms
receive such data from messages in which they are used. Such references take
the form of `-term(…)` where the variables available inside of the term are
defined between the parentheses, e.g. `-term(param: "value")`.
defined between the parentheses, e.g. `-term(param: "value")` or
`-term(param: $arg)` (starting from Fluent 1.1).

```
# A contrived example to demonstrate how variables
Expand Down
2 changes: 1 addition & 1 deletion spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CallArguments ::= blank? "(" blank? argument_list blank? ")"
argument_list ::= (Argument blank? "," blank?)* Argument?
Argument ::= NamedArgument
| InlineExpression
NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral)
NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral | VariableReference)

/* Block Expressions */
SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list
Expand Down
3 changes: 2 additions & 1 deletion syntax/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ let NamedArgument = defer(() =>
maybe(blank),
either(
StringLiteral,
NumberLiteral).abstract)
NumberLiteral,
VariableReference).abstract)
.map(keep_abstract)
.chain(list_into(FTL.NamedArgument)));

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/call_expressions.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ positional-args = {FUN(1, "a", msg)}
named-args = {FUN(x: 1, y: "Y")}
dense-named-args = {FUN(x:1, y:"Y")}
mixed-args = {FUN(1, "a", msg, x: 1, y: "Y")}
variable-args = {FUN($foo, arg: $bar)}

# ERROR Positional arg must not follow keyword args
shuffled-args = {FUN(1, x: 1, "a", y: "Y", msg)}
Expand Down
52 changes: 52 additions & 0 deletions test/fixtures/call_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,58 @@
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "variable-args"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "FunctionReference",
"id": {
"type": "Identifier",
"name": "FUN"
},
"arguments": {
"type": "CallArguments",
"positional": [
{
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "foo"
}
}
],
"named": [
{
"type": "NamedArgument",
"name": {
"type": "Identifier",
"name": "arg"
},
"value": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "bar"
}
}
}
]
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Comment",
"content": "ERROR Positional arg must not follow keyword args"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/term_parameters.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ key01 = { -term }
key02 = { -term () }
key03 = { -term(arg: 1) }
key04 = { -term("positional", narg1: 1, narg2: 2) }
key05 = { -term(arg: $foo) }
45 changes: 45 additions & 0 deletions test/fixtures/term_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,51 @@
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key05"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "term"
},
"attribute": null,
"arguments": {
"type": "CallArguments",
"positional": [],
"named": [
{
"type": "NamedArgument",
"name": {
"type": "Identifier",
"name": "arg"
},
"value": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "foo"
}
}
}
]
}
}
}
]
},
"attributes": [],
"comment": null
}
]
}