Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Parse error for input with plural variable and additional variables #1

Closed
ivannavarrete opened this issue Jul 18, 2018 · 3 comments
Closed

Comments

@ivannavarrete
Copy link

Hi. The library does not appear to correctly parse a yaml file with the following keys, specifically where there is a %{count} variable together with additional variables, %{model} in this case:

header:
  one: 1 error prohibited this %{model} from being saved
  other: "%{count} errors prohibited this %{model} from being saved"
ERROR in ./config/locales/en.yml
Module build failed: SyntaxError: Expected "#", "'", "'#", "''", "'{", "'}", "{", [^{}#\0-\x08\x0E-\x1F\x7F], or end of input but "}" found.
    at peg$buildStructuredError (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat-parser/parser.js:368:12)
    at peg$parse (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat-parser/parser.js:1605:11)
    at Compiler.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/compiler.js:157:13)
    at Compiler.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/compiler.js:163:26)
    at Compiler.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/compiler.js:163:26)
    at Compiler.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/compiler.js:163:26)
    at Compiler.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/compiler.js:163:26)
    at MessageFormat.compile (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat/lib/messageformat.js:333:22)
    at Object.module.exports (/Users/ivan/coding/work/tnc/prisma/node_modules/messageformat-yaml-loader/index.js:19:13)

The resulting object has the following keys:

template:
  {
    header: '{count, plural, one{1 error} other{{count} errors}}devas gnieb morf }ledom{ siht detibihorp ' }
  },

Removing the %{model} variable or renaming the other key to something different does remove the parse error.

@eemeli eemeli closed this as completed in d8226bc Jul 18, 2018
@eemeli
Copy link
Member

eemeli commented Jul 18, 2018

That was a bit embarrassing; the common suffix was getting reversed. Should be fixed now in the 0.2.0 release I just published. Also switched from js-yaml to yaml.

@ivannavarrete
Copy link
Author

Thanks a bunch! Would be cool if the yaml-loader package could be updated as well to use this latest version.

@eemeli
Copy link
Member

eemeli commented Jul 20, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants