mololab / json-translator

jsontt 💡 - AI JSON Translator with GPT + other FREE translation modules to translate your json/yaml files into other languages ✅ Check Readme ✌ Supports GPT / DeepL / Google / Bing / Libre / Argos
https://mololab.org/jsontt/npm
MIT License
465 stars 60 forks source link

How to rename for output file? #41

Closed ttnbtfy closed 10 months ago

ttnbtfy commented 1 year ago

Hi, I want to give a different name to the output files, for example below, is this possible? jsontt your/path/to/file.json --translator google --from en --to fr-my-custom-name.json

ParvinEyvazov commented 1 year ago

Hi @ttnbtfy

Unfortunately, it is not supported yet. Also because of the translating into multiple language in the same time feature, we did not add it. I am adding it to feature list. Thank you.

javix64 commented 1 year ago

Hey @ParvinEyvazov I am here because also I want that feature and I can help to achive it.

For example, in my case, I am using a JSON file called: resume.en.json. I need two different languages: es & de. So my CLI script is: jsontt resume.en.json --translator google --from en --to de es.

What it is name of the file? The main problem is the file name. If you want to keep the same name: For example: file.json => file.en.json. If you want to change the name: For example: file.json => newFile.en.json

What do you think?

javix64 commented 1 year ago

Hey @ttnbtfy. Also if you want to change the name, you can create a script for do this task, I have created mine, here it is:

import { writeFileSync, readFileSync, existsSync, unlinkSync } from "fs";
(function rename() {
  const files = ["de.json", "es.json"];
  try {
    files.map((file) => {
      if (!existsSync(file)) {
        console.log(`File ${file} does not exist`);
        return;
      }
      writeFileSync(`resume.${file}`, readFileSync(file));
      unlinkSync(file);
    });
  } catch (err) {
    console.info("err", err);
  }
})();
ttnbtfy commented 1 year ago

Thank @javix64 for your suggest, can i use this with CLI usage? I don't really understand how to work with Packages

ParvinEyvazov commented 1 year ago

Hi @javix64

Actually, I got an idea from your comment. Maybe what we can do is take a name from the user in the CLI (will be optional) and use it as a prefix

for example in your case:

jsontt resume.en.json --translator google --from en --to de es --name banana

will create a new files wit

what do you think guys? Would this also solve your problem @ttnbtfy ?

javix64 commented 1 year ago

Yes. In this moment it is the best solution. May I do the changes and after PR? and collaborate in somehow :smiley:

ttnbtfy commented 1 year ago

I will definitely try it, I can't test the code right now. Once again thank you very much for those suggestions :)

ParvinEyvazov commented 1 year ago

Sure @javix64, give it a shot!

javix64 commented 1 year ago

hey @ttnbtfy I think now you can update to the latest version because I have added the implementation. 😄 and also someone can close this issue!

ParvinEyvazov commented 1 year ago

@javix64 @ttnbtfy Unfortunately not yet.

Noticed an issue while testing. I will fix it soon and will inform you guys when the new release will be published.

javix64 commented 1 year ago

perfect :)

ttnbtfy commented 1 year ago

Still waiting until there is a new version release so it can be used with CLI command

ParvinEyvazov commented 10 months ago

Hi guys, new version of jsontt now support output name feature. (Thanks to @javix64 )

you can use --name

jsontt <your/path/to/file.json> --translator google --from en --to ar fr zh-CN --name myFiles