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

Message key is lost by CLI when file has only one key #339

Closed
eemeli opened this issue Sep 12, 2021 · 3 comments
Closed

Message key is lost by CLI when file has only one key #339

eemeli opened this issue Sep 12, 2021 · 3 comments
Labels

Comments

@eemeli
Copy link
Member

eemeli commented Sep 12, 2021

The current behavior breaks the contract provided by structured KV pairs when compiling a module, at least from the CLI. I want the precise opposite of the OP.

Consider translations with just one key:

# en.yaml
greet: hello
# es.yaml
greet: hola

pnpx messageformat <dir>

yields =>

{
  en: () => 'hello',
  es: () => 'hola'
}

As shown above, greet is missing. By just adding another key,

# en.yaml
greet: hello
other: abc
# es.yaml
greet: hola
other: efg

The correct shape is omitted:

{
  en: { greet: () => 'hello', other: () => 'abc' },
  es: { greet: () => 'hola', other: () => 'efg' },
}

This broke me today unexpectedly where I had one translation with a single key. To keep the same structure, I now must artificially add an additional key so that the compiler does not drop valuable key/value pair information.

Is it agreed that this is/is not a problem? If this lossy behavior is desired, can it be opt-in only?

Originally posted by @cdaringe in #328 (comment)

@eemeli eemeli added the bug label Sep 12, 2021
@eemeli
Copy link
Member Author

eemeli commented Sep 12, 2021

@cdaringe Apologies for being so late getting to this, as it's actually an entirely separate issue from the one in the parent thread. There's an oblique reference to this "feature" in the CLI docs (in the --simplify option description), but I agree that it's surprising and should not be default.

@eemeli
Copy link
Member Author

eemeli commented Sep 12, 2021

I'm considering an additional minor-level fix for this by expanding the --simplify option to provide more choices, but keeping that to not also be a breaking change is currently blocked by yargs/yargs-parser#412.

@eemeli
Copy link
Member Author

eemeli commented Feb 10, 2023

Closing this, as the actual bug has long since been fixed and the upstream dependency has not shown any interest in making required changes.

@eemeli eemeli closed this as completed Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant