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

Display the translated text in a dialog window #1

Open
windirt opened this issue Apr 21, 2020 · 4 comments
Open

Display the translated text in a dialog window #1

windirt opened this issue Apr 21, 2020 · 4 comments

Comments

@windirt
Copy link

windirt commented Apr 21, 2020

Thank you for making such a good plug-in, it is really fast, but when a large amount of text is translated at once, the content displayed will be particularly long, even beyond the width of the screen, I tried to make some changes on the codes via applescript to display a dialog window. I am not very familiar with the php language. The syntax may be wrong, but basically there is not much problem. Hope you can understand my intention and add it to the new version.

known issue: If there are double quotes in the translated text, the output will be empty, I don’t know how to deal with this issue.

below is the sample of dialog window and code
截屏2020-04-21 下午6 40 12

  $result = array_reduce($json[0], function($carry, $item) {
   if (isset($item[0])) {
     $carry .= $item[0];
     return $carry;
   }
  }, '');
  $cmd = "/usr/bin/osascript -e \"display dialog \\\" {$result} \\\"\"";
  exec($cmd);
  echo " ";
@thang-nm
Copy link
Owner

Thank you so much for the idea. I will investigate soon!

@thang-nm
Copy link
Owner

thang-nm commented Apr 21, 2020

Hey @windirt.
I fixed the double quotes problem, and changed a little bit the dialog.
But I can't disable loading spinner (seem like PopClip doesn't support for the actual long running).
You can check out this branch and I hope you like it!

@windirt
Copy link
Author

windirt commented Apr 22, 2020

Thanks for the new commit. the plug-in is working as I desire now.
About the spiner, it seems Popclip was waiting a POSIX output.
Then I added the code at the end. it will display translated text via old method. This code can save the translated content to the clipboard.

echo $result

If you can process the applescript and echo commands at the same time through an asynchronous thread, there should be no problem with the spiner.

After consulting the development documentation of Popclip, I found that after changing the show-result in config.plist to copy-result (requires restarting Popclip), I can avoid the embarrassing scene of the translated text appearing again, and can also copy the text to the clipboard.

@thang-nm
Copy link
Owner

Did you create new thread?

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

2 participants