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

JSON parser ignores tabStyle option #337

Closed
SkaceKamen opened this issue Jun 18, 2020 · 2 comments · Fixed by #338
Closed

JSON parser ignores tabStyle option #337

SkaceKamen opened this issue Jun 18, 2020 · 2 comments · Fixed by #338
Labels
bug Something isn't working

Comments

@SkaceKamen
Copy link
Contributor

Describe the bug

JSON parser ignores i18n.tabStyle option and always uses spaces when saving the translation file.

Extension Version
i18n Ally 2.2.6

To Reproduce

  1. Set i18n.tabStyle to tab
  2. Add new translation key
  3. JSON file is formatted using spaces

Solution?

I did a little digging and seems like these are the lines that cause this issue:

https://github.com/antfu/i18n-ally/blob/e2881d9f1f20ec4c849c9a0daed24d22d63eb773/src/parsers/json.ts#L21

https://github.com/antfu/i18n-ally/blob/e2881d9f1f20ec4c849c9a0daed24d22d63eb773/src/parsers/json.ts#L23

According to docs of both of these functions, you just have to specify tab char instead of number to use tabs to indent the result:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
https://www.npmjs.com/package/json-stable-stringify#space

So, all you have to do to fix this is something like this:

const indent = this.config.tab === '\t' ? this.config.tab : this.config.indent
@SkaceKamen SkaceKamen added the bug Something isn't working label Jun 18, 2020
@antfu
Copy link
Contributor

antfu commented Jun 18, 2020

Can you make a PR? Thanks!

@SkaceKamen
Copy link
Contributor Author

Sure, there it is :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants