Skip to content
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

Introduce private messages. #68

Merged
merged 2 commits into from
Nov 30, 2017
Merged

Conversation

stasm
Copy link
Contributor

@stasm stasm commented Nov 14, 2017

Fix #62.

Private messages are similar to regular messages but they can only be
used as references in other messages. Their identifiers start with at
least one dash -, e.g. -brand-name. The runtime cannot retrieve
private messages directly. They are best used to define glossary terms
which can be used consistently across the localization of the entire
product.

Private messages can store some grammatical information about themselves
in tags. Private messages are not allowed to have attributes.

@stasm stasm requested review from Pike and zbraniecki November 14, 2017 13:38
| Section(symb name, comment? comment)
| Comment(comment)
| Junk(str content)
attributes (annot* annotations, span? span)

base_message = Message(pat? value, attr* attributes)
| PrivateMessage(pat value, tag* tags)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes it a requirement that PrivateMessages have a non-null value. Should we enforce this for now or keep it consistent with public Messages?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok enforcing it.

spec/fluent.ebnf Outdated
identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*
public-identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*
private-identifier ::= '-'+ public-identifier
identifier ::= public-identifier | private-identifier
external ::= '$' identifier
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you need to change external to only accept public-identifier. Or, maybe I'd even change public-identifier to identifier, and then create message-identifier ::= identifier | private-identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I like this approach better. Thanks.

spec/fluent.ebnf Outdated
@@ -41,7 +43,9 @@ tag-list ::= NL (__ tag)+
attribute ::= NL __ '.' identifier value
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here.

@stasm stasm mentioned this pull request Nov 23, 2017
3 tasks
Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

The asdl changes are a bit above my head, mostly because I don't know if there's a difference between a param thingie and an attributes thingie.

I'd really like ensure that we don't expose attributes on private messages, probably already in this patch.

For the general patch queue, the change log might end up being confusing by adding private messages with some properties, and then removing them again in the next patch. Is that a concern?

and are called placeables.

It's common to used placeables to interpolate an external argument, provided
by the developer, into the string.
Copy link
Contributor

Choose a reason for hiding this comment

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

to used -> to use, also, I'd put the provided by the developer to the end, the sentence is really broken up right now.

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 common to use placeables to interpolate an external argument into the string, provided by the developer doesn't sound right either. I'll go with It's common to use placeables to interpolate external arguments into the translation. External arguments are provided by the developer and may change on runtime.

spec/fluent.ebnf Outdated
@@ -69,8 +73,8 @@ block-expression ::= select-expression
| variant-list

select-expression ::= inline-expression __ '->' __ variant-list
attribute-expression ::= identifier '.' identifier
variant-expression ::= identifier '[' _? variant-key _? ']'
attribute-expression ::= message-identifier '.' identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is just identifier, the syntax defines that we can't dereference attributes of private messages?

That'd make inline-expression safe, and we could use an unsafe-inline-expression that adds private-indentifier.identifier as selector-expression instead of inline-expression?

Copy link
Contributor Author

@stasm stasm Nov 29, 2017

Choose a reason for hiding this comment

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

Nice, I like this approach. It makes syntax work for us without adding more... syntax.

We could even go further and define selector-expression which would be different from inline-expression and block-expression and could comprise of:

inline-expression    ::= quoted-text
                       | number
                       | identifier
                       | external
                       | variant-expression
                       | public-attribute-expression
                       | call-expression
                       | placeable

block-expression     ::= select-expression
                       | variant-list

selector-expression  ::= quoted-text
                       | number
                       | identifier
                       | external
                       | public-attribute-expression
                       | private-attribute-expression
                       | call-expression

Compare it with:

inline-expression ::= quoted-text

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agreed, allowing placeable or variant-expression doesn't make much sense in a selector-expression

@stasm
Copy link
Contributor Author

stasm commented Nov 30, 2017

The asdl changes are a bit above my head, mostly because I don't know if there's a difference between a param thingie and an attributes thingie.

attributes can be used to avoid repetition of fields in unions. The following two notations are equivalent:

prod = Foo(string name)
     | Bar(string name)

prod = Foo
     | Bar
     attributes (string name)

The relevant excerpt from The Zephyr Abstract Syntax Description Language, p. 5, § 2.6:

Often several constructors of a type share a set of common values. To make this explicit, ASDL includes an attribute notation. Since all variants of a type carry the values of an attribute, its fields can be accessed without having to discriminate between the various constructors. Attributes can be seen as providing some limited features of inheritance

@stasm stasm requested a review from Pike November 30, 2017 12:24
@stasm stasm force-pushed the private-messages branch 2 times, most recently from 1f4b490 to 7619b5c Compare November 30, 2017 12:36
Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

I wonder if we should open a ticket to allow selectors based on translated text. We had numerous requests for that in the past. Or do we only want to allow that in GLOBALS?

guide/private.md Outdated
Private messages are similar to regular messages but they can only be used as
references in other messages. Their identifiers start with at least one dash
`-` like in the example above: `-brand-name`. The runtime cannot retrieve
private messages directly. They are best used to define glossary terms which
Copy link
Contributor

Choose a reason for hiding this comment

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

Just dropping the glossary here alltogether sounds good enough for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make sure I understand this comment, you'd rather see …to define terms which…?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes.

@@ -40,19 +44,16 @@ module Fluent
| Placeable(expr expression, span? span)

-- Expressions
expr = InlineExpression(inline_expr)
| BlockExpression(block_expr)
inline_expr = StringExpression(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

inline_expr is still used in line 70?

arg = Expression(inline_expr)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

spec/fluent.ebnf Outdated
selector-expression ::= quoted-text
| number
| external-identifier
| public-identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private-identifier instead of public-identifier, as tags are only on private messages, and I guess the intent is to not select based on translation value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch and yes, that's the intent. At least for now.

Fix projectfluent#62.

Private messages are similar to regular messages but they can only be
used as references in other messages. Their identifiers start with at
least one dash `-`, e.g. `-brand-name`. The runtime cannot retrieve
private messages directly. They are best used to define glossary terms
which can be used consistently across the localization of the entire
product.

Private messages can store some grammatical information about themselves
in tags. Private messages are not allowed to have attributes.
The new `selector-expression` EBNF symbol restricts which expressions
can be selectors.  The following expressions are now illegal as
selectors:

  - references to public messages,
  - attribute expressions on public messages,
  - variant expressions,
  - select expressions (even when wrapped in a placeable).
@stasm stasm requested a review from Pike November 30, 2017 13:56
@stasm stasm merged commit af600be into projectfluent:master Nov 30, 2017
@stasm stasm deleted the private-messages branch November 30, 2017 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants