Skip to content

Fix #5. Allow select-expression with an empty selector #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2017
Merged
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: 2 additions & 2 deletions fluent.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module Fluent
pat = Pattern(expr* elements, bool quoted)

expr = Selector(sel)
| SelectExpression(sel sel, mem* vars)
| SelectExpression(sel? sel, mem* vars)

sel = MessageReference(iden id)
| ExternalArgument(iden id)
| CallExpression(iden callee, expr* args)
| MemberExpression(expr obj, memkey key)
| VariantExpression(expr obj, memkey key)
| KeyValueArgument(iden name, argval val)
| Number(string value)
| String(string value)
Expand Down
4 changes: 2 additions & 2 deletions fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ quoted-text ::= ([^{"] | '\{' | '\"')+
block-text ::= NL __ '|' unquoted-pattern

placeable ::= '{' __ expression __ '}'
expression ::= selector-expression | select-expression
expression ::= selector-expression | select-expression | variants-list
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add variant-list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's... right there. in the line you commented on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reference to it is, but the definition is nowhere to be found. Did I miss something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah :) it's defined in line 23; not part of this patch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow github hid it from me


selector-expression ::= quoted-pattern
| number
Expand All @@ -43,7 +43,7 @@ selector-expression ::= quoted-pattern
| placeable

select-expression ::= selector-expression __ ' ->' __ variants-list
member-expression ::= identifier '[' keyword ']'
variant-expression ::= identifier '[' keyword ']'
call-expression ::= builtin '(' __ arglist? __ ')'
arglist ::= argument (__ ',' __ arglist)?
argument ::= expression
Expand Down
50 changes: 22 additions & 28 deletions guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ select a string variant depending on its output. In case of the
``available-users`` entity, we used the ``LEN`` builtin and select the variant
of the string depending on its output.

In the ``unread-emails`` example ``0`` is used explicitly as a member key to
In the ``unread-emails`` example ``0`` is used explicitly as a variant key to
specify a special case for when there are no unread emails.

Additionally, the code specifies the default variant to be used if none of the
Expand All @@ -228,41 +228,35 @@ Variants

::

brand-name =
brand-name = {
*[nominative] Aurora
[genitive] Aurore
[dative] Aurori
[accusative] Auroro
[locative] Aurori
[instrumental] Auroro
}

about-old = O brskalniku { brand-nam }
about = O { brand-name[locative] }

As we stated at the beginning of this guide, an entity primarely consist
a string value. But there are cases, in which it makes sense to store multiple
variants of the value. The ``brand-name`` example, in languages that use noun
declension, may need to be declined when referred from other entities.

Select expression, introduced in one of the previous chapters, does not provide
a way to easily refer to a particular variant of the value from another entity.
Instead, FTL lets you define traits, which are variants of the whole value that
can be externally referred to using the ``key[trait]`` syntax.

For instance, in many inflected languages (e.g. German, Finnish, Hungarian, all
Slavic languages), the *about* preposition governs the grammatical case of the
complement. It might be the accusative (German), ablative (Latin) or locative
(Slavic languages). In Slovenian, the ideal string would inflect the noun,
like so: *O Aurori*. However, since we want the name of the browser to be
stored in the ``brand-name`` entity, we can't modify it.
As we stated at the beginning of this guide, messages primarely consist of
string values. A single string value can have multiple branches, or variants,
which are chosen based on the value of a selector. In some cases, however, we
don't need any selector and instead just want to define multiple variants of
the message and use them from within other messages. For instance. in
languages that use noun declension, ``brand-name`` may need to be declined when
referred to from other messages.

The work-around is to inflect an auxiliary noun complement, e.g. browser, to
give *About the Aurora browser*. Needless to say, this ends up being long and
often unnaturally-sounding to the native speakers. See ``about-old`` for the
example in Slovenian.
FTL lets you define variants without a selector. Think of them as facets of
the same message. You can refer to them using the ``message[variant key]``
syntax.

This problem can be easily solved by defining multiple variants of the
``brand-name`` entity, to match different grammatical cases of the noun.
For instance, in many inflected languages (e.g. German, Finnish, Hungarian, all
Slavic languages), the *about* preposition governs the grammatical case of the
complement. It might be the accusative (German), the ablative (Latin) or the
locative (Slavic languages). The grammatical cases can be defined as variants
without a selector and referred to from other messages, like the ``about``
message above.


Storing Additional Information
Expand All @@ -278,8 +272,8 @@ Storing Additional Information
[feminine] { brand-name } otworzyla nowe okno.
}

Traits are useful beyond just value variants. They can be also used to describe
parameters of the entity that can be then used in other selectors.
Traits can be used to describe parameters of the entity that can be then
used in other selectors.

Imagine an entity ``brand-name`` that can be either *Firefox* or *Aurora*. The
former is *masculine*, while the latter is *feminine*, so sentences that refer
Expand All @@ -296,7 +290,7 @@ HTML/XUL Attributes
[html/aria-label] Login input value
[html/title] Type your login email

Finally, traits can also be very useful when using FTL for localization of more
Traits can also be very useful when using FTL for localization of more
complex UI elements, such as HTML components.

Those elements often contain multiple translatable messages per one widget. For
Expand Down