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
@formatjs/cli
Can't use a custom formatter to extract messages to a non-JSON format
#4149
Comments
@formatjs/cli
Can't use a custom formatter to extract messages to a non-JSON format
FWIW, @longlho, if you're open to accepting a PR to address this, I'd be willing to submit one. |
Yeah i'd be open to that |
@longlho, do you have any preference for the naming of the CLI flag? |
Actually, another way to go here might be that if the formatter result is a string, just return that string directly with no |
I guess we can infer based on output extension? |
that's not a bad idea. Are you thinking anything with |
I think json should be the default and then *.csv uses the csv formatter |
I wasn't looking to add a CSV formatter to the core project -- different usages might need different column names and CSV generation options. Also, doing CSV correctly would probably require adding a new dependency, which I'm sure you don't take lightly. |
Hmm I thought we already support custom formatter? |
you do, but the point here is that the result of the custom formatter currently gets stringified by the extract function, which prevents it from working with non-JSON output formats (contaminates a valid CSV string). https://github.com/formatjs/formatjs/blob/main/packages/cli-lib/src/extract.ts#L250 |
Kk hmm then maybe I can extend the formatter API to allow custom stringify? Does that work for u? |
absolutely! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
(bumping to keep the stale bot away) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@longlho, thanks for addressing this! |
Which package?
@formatjs/cli
Describe the bug
The extract script runs
stringify
on the formatted extracted result, which produces invalid results for non-JSON based formats. In my case, I created a custom formatter to convert the extracted messages to CSV, since none of the JSON-based formats that our TMS (Phrase) accepts as an import/push source supports message descriptions.As a workaround, I had to write an additional script to transform the output file's content to CSV format.
Expected behavior
I expected the resulting formatted file to contain the exact content produced by my custom formatter.
To address this issue while avoiding a breaking change to existing users, perhaps an optional flag can be introduced for the
extract
command to indicate that the supplied formatter's output should be written directly as an unformatted string (bypassing thestringify
call).The text was updated successfully, but these errors were encountered: