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

Add option to set JSON indentation depth #231

Open
Cielquan opened this issue Nov 10, 2022 · 7 comments
Open

Add option to set JSON indentation depth #231

Cielquan opened this issue Nov 10, 2022 · 7 comments

Comments

@Cielquan
Copy link

🚀 Feature Proposal

Add an option to specify the indentation of the JSON file when converting from po to JSON files.

Motivation

I use a simple custom script which uses i18next-conv to convert my po files to JSON files. I also use prettier for auto-formatting via pre-commit. prettier by default indents JSON files by 2 spaces, but i18next-conv creates them with 4 spaces. Thus the pre-commit hook fails once because of this.
If there was the option to set the indentation to 2 this issue would be resolved.

Example

The indentation would be able to be set via CLI and the API in custom scripts.

@perrin4869
Copy link
Contributor

I'll merge a PR implementing this :)
Maybe add the ability to specify a json formatter?

@Cielquan
Copy link
Author

I'll merge a PR implementing this :)

Thanks :)

Maybe add the ability to specify a json formatter?

That sound also like a good idea. Maybe both? You can either set a number or a string containing a formatter wich then gets mapped to a number?

@perrin4869
Copy link
Contributor

I think one of the two is better? I can go with either!
Can't think of a name for a combined option, it would be something like jsonFormatter or jsonTabWidth I think?

@Cielquan
Copy link
Author

Well the naming sure is a problem indeed.

I guess then when both options are being implemented two separate options should be created, but then there would be the issue of which takes precedence and so on. So yeah, I guess one would be better?

But when only one is implemented I would propose to take the more general one with jsonTabWidth as it is more flexible and the user can do everything the jsonFormatter option would allow and more.

What do you think?

@perrin4869
Copy link
Contributor

perrin4869 commented Nov 10, 2022

Well, jsonFormatter is the more general option.
You could specify something like --jsonFormatter ./jsonFormatter.js which could look something like:

import beautify from "json-beautify";

export default (obj) => beatufy(obj, null, 2, 100));

This is using something like https://www.npmjs.com/package/json-beautify
In this case you can also set the maximum line width.

@Cielquan
Copy link
Author

Ah ok, I had a different approach in mind. I thought that the formatter option would just be a string, which then would get mapped into a number. But your approach is much better. Yes with this I would agree with you, that this would be the more general option. I like it.

@paulschreiber
Copy link

I hit the same problem with prettier vs the converter. Would also like to see this.

paulschreiber added a commit to techmatters/terraso-mobile-client that referenced this issue Sep 26, 2024
this matches what i18n-conv does, and avoids thrash

See i18next/i18next-gettext-converter#231
paulschreiber added a commit to techmatters/terraso-mobile-client that referenced this issue Oct 1, 2024
this matches what i18n-conv does, and avoids thrash

See i18next/i18next-gettext-converter#231
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

No branches or pull requests

3 participants