google_ml_kit_flutter icon indicating copy to clipboard operation
google_ml_kit_flutter copied to clipboard

On Device Translation crashes app when translating multiple words

Open SuperWes opened this issue 2 years ago • 9 comments

Rather than crashing the app with no information about why I would expect to get an error message back or an exception thrown that could be caught with a try/catch.

This should be reproducible in the sample project. That is where I found it.

SuperWes avatar Aug 07 '23 22:08 SuperWes

Hi @fbernaly Can i handle this.. seem to be a try-and-catch block needed

bensonarafat avatar Aug 11 '23 02:08 bensonarafat

@bensonarafat : go ahead, give it a try, make sure to provide testing steps in the PR.

fbernaly avatar Aug 11 '23 20:08 fbernaly

great

bensonarafat avatar Aug 12 '23 07:08 bensonarafat

@fbernaly this crash seems to happen only in IOS and the emulator

bensonarafat avatar Aug 15 '23 14:08 bensonarafat

@SuperWes : could you confirm that you reproduce this in the simulator? or in a real device?

fbernaly avatar Aug 15 '23 17:08 fbernaly

Any updates on this? I am facing the same issue on iOS simulator. It works fine on android emulator tho

mechaadi avatar Sep 13 '23 16:09 mechaadi

Sorry, I have been busy with work, I do not have an ETA for now. However, contributions are always welcome. Submit your PRs and I will review them.

fbernaly avatar Sep 13 '23 16:09 fbernaly

Hello, I will try to find the right solution as soon as I get some free time but for the time being I used this nasty hack. I think it's not that good from performance perspective but does the job for now.

Since this only breaks on iOS, i did a platform check and then iterated over the whole string word by word, then translated each word instead of the whole line string at once.

Here's the code if someone wants to use it until we get a proper fix:

// it crashes on iOS when multi-word line is passed
if (Platform.isIOS) {
  String translated = "";
  for (var substr in text.split(" ")) {
    translated =
        "$translated ${await onDeviceTranslator.translateText(substr)}";
  }
  return translated;
} else {
  return await onDeviceTranslator.translateText(text);
}

mechaadi avatar Sep 14 '23 15:09 mechaadi

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 07 '24 19:10 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Feb 12 '25 12:02 github-actions[bot]