Skip to content

Commit 5637e71

Browse files
committed
Fix projectfluent#7. Introduce tags
Tags are binary values attached to messages. They are language-specific and can be used to describe grammatical characteristics of the message. brand-name = Firefox #masculine brand-name = Aurora #feminine #vowel Tags can be used in select expressions by matching a hashtag name to the message: has-updated = { brand-name -> [masculine] … [feminine] … *[other] … } Tags can only be defined on messages which have a value and don't have any attributes.
1 parent 45cb43a commit 5637e71

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

guide/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [External Data](external.md)
77
* [Selectors](selectors.md)
88
* [Variants](variants.md)
9+
* [Tags](tags.md)
910
* [Attributes](attributes.md)
1011
* [Sections](sections.md)
1112
* [Comments](comments.md)

guide/tags.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Tags
2+
3+
```
4+
brand-name = Aurora
5+
#żeński
6+
7+
has-updated = { brand-name ->
8+
[męski] { brand-name} został zaktualizowany.
9+
[żeński] { brand-name } została zaktualizowana.
10+
*[inny] Program { brand-name } został zaktualizowany.
11+
}
12+
```
13+
14+
Sometimes translations might vary depending on some grammatical trait of
15+
another message. In the example above the form of the past tense of _has been
16+
updated_ depends on the grammatical gender of `brand-name`.
17+
18+
In such cases you can _tag_ messages with simple one-word _hashtags_ and then
19+
define different translations based on these tags. You define them with `#`
20+
which must start on a new line under the message, indented.
21+
22+
Hashtags are specific to your language's grammar and don't have to be in
23+
English. In the example above, _żeński_ means _feminine_, _męski_ is
24+
_masculine_ and _inny_ is _other_.
25+
26+
Both tags and variants discussed in the previous chapter can be used to provide
27+
more information about a message that is specific to your language. There
28+
a number of differences between them, however.
29+
30+
- Tags don't have a value; they _are_ the value.
31+
32+
- Tags can only be used for matching. They cannot be inserted into another
33+
translation.
34+
35+
- Tags describe grammatical traits; they should answer the question _Is this
36+
message <tagname>_? For instance, _Is this message feminine?_
37+
38+
- On the other hand, variants define different _facets_ of the message. It's
39+
the same value, just in slightly different forms to make it grammatically
40+
correct when used inside of other messages.

spec/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
## Unreleased
44

5+
- Introduce tags for language-specific grammatical information.
6+
7+
Tags are binary values attached to messages. They are language-specific and
8+
can be used to describe grammatical characteristics of the message.
9+
10+
brand-name = Firefox
11+
#masculine
12+
13+
brand-name = Aurora
14+
#feminine
15+
#vowel
16+
17+
Tags can be used in select expressions by matching a hashtag name to the
18+
message:
19+
20+
has-updated = { brand-name ->
21+
[masculine] …
22+
[feminine] …
23+
*[other] …
24+
}
25+
26+
Tags can only be defined on messages which have a value and don't have any
27+
attributes.
28+
529
- Require the message body to be indented.
630

731
Quoted strings are now only valid in placeables and cannot contain other

spec/fluent.asdl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Fluent
2323
{
2424
res = Resource(entry* body, comment? comment)
2525

26-
entry = Message(iden id, pat? value, attr* attributes, comment? comment)
26+
entry = Message(iden id, pat? value, attr* attributes, tag* tags, comment? comment)
2727
| Section(symb name, comment? comment)
2828
| Comment(comment)
2929
| Junk(string content)
@@ -45,6 +45,9 @@ module Fluent
4545
-- Attributes of Message
4646
attr = Attribute(iden id, pat value)
4747

48+
-- Tags of Message
49+
tag = Tag(symb name)
50+
4851
-- Variants of SelectExpression
4952
var = Variant(varkey key, pat value, bool default)
5053
varkey = Number(number)

spec/fluent.ebnf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ variant ::= NL __ '[' _? variant-key _? ']' __ pattern
3434
default-variant ::= NL __ '*[' _? variant-key _? ']' __ pattern
3535
variant-list ::= variant* default-variant variant*
3636

37+
tag ::= '#' word
38+
tag-list ::= NL (__ tag)+
39+
3740
attribute ::= NL __ '.' identifier value
3841
attribute-list ::= attribute+
3942

40-
message ::= identifier (value attribute-list? | attribute-list)
43+
message ::= identifier ((value tag-list?) | (value? attribute-list))
4144
value ::= _? '=' __? pattern
4245
pattern ::= (text | placeable)+
4346
text ::= ((char - line-break) - special | break-indent | '\' special)+

0 commit comments

Comments
 (0)