formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

rules for named arguments #73

Closed redbugz closed 5 years ago

redbugz commented 9 years ago

Periods are not allowed in arguments names, but dashes are. I tried reading the ICU Message docs, but they don't seem very clear to me about what a valid identifier is. It just mentions :Pattern_Syntax: which I couldn't find a definitive answer for that I could understand. messageformat.js in their parser comments this rule as "only allow valid javascript identifiers" but the dash is not allowed in a valid javascript identifier.

I was just curious where the rules come from about what a valid identifier syntax is.

I would love to use hierarchal properties or key paths in my expressions, but it's not allowed, and I was trying to understand if it's a limitation of the ICU Message "spec" or just a design decision of this implementation. I know it can lead to ambiguities and implementation headaches.

> parser.parse('{parent}')
{ type: 'messageFormatPattern',
  elements: [ { type: 'argumentElement', id: 'parent', format: null } ] }
> parser.parse('{parent.child}')
SyntaxError: Expected ",", "}" or [^ \t\n\r,.+={}#] but "." found.
> parser.parse('{parent-child}')
{ type: 'messageFormatPattern',
  elements: [ { type: 'argumentElement', id: 'parent-child', format: null } ] }
caridy commented 9 years ago

there isn't such thing as ICU Message "spec", that's the first problem we have :), @ericf used the reference implementations, and did his best to try to keep it simple, if you want to extend or clarify anything about ICU messages, we can probably reach out to them directly.

redbugz commented 9 years ago

I think that would be a good idea to reach out to them and get some clarification. If you are striving for interoperability with the Java/C implementations then it needs to be known. If that's not a primary concern, then I suppose you can decide what you want to do and document it. We have a bunch of legacy systems we are considering moving over to this, and we have keys in a wide variety of formats, so it's important that we understand what will work and what won't so we know what we have to change.

guilhermesimoes commented 8 years ago

Why aren't periods allowed in message variables? In the format-message package they are allowed. On the other hand, the messageformat package does not allow them as well.

Usually a dot is used to separate properties when a nested object is flattened.

let data = {
  "world.city": "Las Vegas"
};

new IntlMessageFormat("Hello {world.city}", "en").format(data)

This seems valid to me but it's throwing a SyntaxError.

longlho commented 5 years ago

dupe of #72

raghavbk commented 4 years ago

is this issue fixed ?

longlho commented 4 years ago

it is