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

Allow custom LibreTranslate instance #319

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

zihu12
Copy link

@zihu12 zihu12 commented Jun 12, 2024

Currently the translation API endpoints are predefined/hardcoded as follows:

static final translation_hosts = ['libretranslate.de', 'translate.fedilab.app', 'translate.argosopentech.com'];

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 :(

Copy link

@TheHCJ TheHCJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine, can be merged

@j-fbriere j-fbriere merged commit f69516b into j-fbriere:master Jun 17, 2024
@j-fbriere
Copy link
Owner

j-fbriere commented Jun 17, 2024

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 zihu12 deleted the feat-customtrans branch June 18, 2024 01:14
@zihu12
Copy link
Author

zihu12 commented Jun 18, 2024

Having read the commit(f69516b) 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
Copy link
Owner

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.

@zihu12
Copy link
Author

zihu12 commented Jun 18, 2024

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
Copy link
Author

zihu12 commented Jun 18, 2024

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
Copy link
Owner

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
Copy link
Author

zihu12 commented Jun 18, 2024

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

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

Successfully merging this pull request may close these issues.

3 participants