j-fbriere / squawker

An open-source privacy oriented Twitter/X client
MIT License
799 stars 16 forks source link

Allow custom LibreTranslate instance #319

Closed zihu12 closed 2 weeks ago

zihu12 commented 3 weeks ago

Currently the translation API endpoints are predefined/hardcoded as follows: https://github.com/j-fbriere/squawker/blob/b0f95723086f21fda805c8b8fbe0f443f9547125/lib/utils/translation.dart#L37 This will work most of the time, but sometimes not, especially for users in special network condition (also while testing for this PR libretranslate.de had undergone 502/Connection Refused sometimes :(

What this PR does:

  1. add an option in settings that allows to set customized LibTranslate Instance(with one default instance translate.fedilab.app)
  2. Provide an option to enter API KEY to use when a custom instance is defined(Mainly for who use Official Instance or running private instances)

Don't know why so many whitespace-related changed in lib/settings/_general.dart through not shown in VS Code. :( editor.formatOnSave in .vscode/settings.json filled my diff with whitespace changes :(

j-fbriere commented 2 weeks ago

Merged, thank you!

This is a great idea.

I decided to let a list of LibreTranslate instances do the translation, like before, and not only one instance. The list can be reordered, instances can be added and removed from the list. Each instance can have it's own API key.

zihu12 commented 2 weeks ago

Having read the commit(https://github.com/j-fbriere/squawker/commit/f69516b722bb97650b7273a8aaed0cbe37ec2127) suggested that this is already implemented ;)


BTW there's something that comes to my mind:

  1. With the latest release after configuring something (custom instance)? and delete the default ones, when app restart it will not work until I come to settings and save again(through those instances are kept). ↑While reproducing this I even seen that the app uses different instances for /languages(check if lang supported?) and /translate(for translation) and libretranslate.de was down again :( photo_2024-06-18_09-41-30

2.With root access to my device, I did some research to FlutterSharedPreferences.xml for prefs change or so on. In this process I found those:

<string name="flutter.content1718674994translation.ja.en.1782438806043656588">{&quot;translatedText&quot;:[&quot;Bang!&quot;,&quot;\n&quot;,&quot; \n&quot;]}</string>
<string name="flutter.type1718674994translation.ja.en.1782438806043656588">String</string>
<string name="flutter.translation.ja.en.1782438806043656588">{&quot;content&quot;:&quot;content1718674994translation.ja.en.1782438806043656588&quot;,&quot;type&quot;:&quot;type1718674994translation.ja.en.1782438806043656588&quot;}</string>
<string name="flutter.content1718674992translation.supported_languages"></string> <!-- Redacted to save space -->
<string name="flutter.type1718674986translation.supported_languages">String</string>

I guess those are responses from the translation instance. The problem is that they seems not automatically cleared (sorry if I wrong as I suspect this because after a sed /translation/d it reduced from 700+kb to 7+kb) I don't know if it's intentional but if not, maybe a bug?


Or maybe I should say them in another issue?

j-fbriere commented 2 weeks ago

I just did the following test:

So everything works fine for me.

I'm not sure I understand what is your issue.

Could you please describe your issue in detail. Could you please provide the precise steps to reproduce your issue.

It will help me debug it. Thank you.

zihu12 commented 2 weeks ago

I just did the following test:

  • I opened the Squawker application
  • I opened the Translators list window
  • I added the new host translate.lotigara.ru and saved
  • I deleted the 3 default hosts by swap/delete
  • I saved the list with only the new host in it
  • I closed the Squawker application
  • I reopened the Squawker application
  • I opened the Translators list: it was still only with the new host
  • I translated a tweet with success

So everything works fine for me.

I'm not sure I understand what is your issue.

Could you please describe your issue in detail. Could you please provide the precise steps to reproduce your issue.

It will help me debug it. Thank you.

You need a traffic inspector(pcapdroid will work) to reproduce this.

  1. in the app set translators as you said.
  2. stop the app then enable the inspector
  3. open the app, then try to translate something immedicately(the translator window will show correctly).
  4. See where the inspector says the traffic goes

I will try to make a screeb record to illustrate this problem. github complains that the video is too big, hope the description is enough :(

or you may just remove all the entries and the app should complain on attempt to translate ;)

zihu12 commented 2 weeks ago

I just did the following test:

  • I opened the Squawker application
  • I opened the Translators list window
  • I added the new host translate.lotigara.ru and saved
  • I deleted the 3 default hosts by swap/delete
  • I saved the list with only the new host in it
  • I closed the Squawker application
  • I reopened the Squawker application
  • I opened the Translators list: it was still only with the new host
  • I translated a tweet with success

So everything works fine for me. I'm not sure I understand what is your issue. Could you please describe your issue in detail. Could you please provide the precise steps to reproduce your issue. It will help me debug it. Thank you.

You need a traffic inspector(pcapdroid will work) to reproduce this.

  1. in the app set translators as you said.
  2. stop the app then enable the inspector
  3. open the app, then try to translate something immedicately(the translator window will show correctly).
  4. See where the inspector says the traffic goes

~I will try to make a screeb record to illustrate this problem.~ github complains that the video is too big, hope the description is enough :(

or you may just remove all the entries and the app should complain on attempt to translate ;)

Hope these info enough to reproduce, or ask me to record and use zip to send(didn't realize this method until make that issue ;) )

j-fbriere commented 2 weeks ago

Like I said, there is no issue for me.

I described earlier in detail the test I did with success.

If I cannot reproduce an issue, I cannot find the bug to fix it.

You're talking about using an inspector to analyze "something", but it's not clear what it is that I have to analyze and more importantly, what is the issue to begin with.

Maybe you should create a new issue in which you describe what is the problem. In your description please specify the steps in Squawker to reproduce the issue. No need to write about the tools used to try to resolve the issue for now, especially since I don't understand what the problem is.

Thank you.

zihu12 commented 2 weeks ago

Like I said, there is no issue for me.

I described earlier in detail the test I did with success.

If I cannot reproduce an issue, I cannot find the bug to fix it.

You're talking about using an inspector to analyze "something", but it's not clear what it is that I have to analyze and more importantly, what is the issue to begin with.

Maybe you should create a new issue in which you describe what is the problem. In your description please specify the steps in Squawker to reproduce the issue. No need to write about the tools used to try to resolve the issue for now, especially since I don't understand what the problem is.

Thank you.

Sorry for the inaccurate response :( An issue for this problem is created at #324 with a screenshot and a screen recording(and more detailed step)

Hope no offence, when I say we need inspectors I mean that's required to reveal the problem, since the embedded instances along with the retry mechanism will let it work behind the scene, and only with those is most likely to see which instance is actually being used.

Or if you mean that "solution", deleted and apologize for being too hurry