theLee3 / flutter_auto_translator

A command-line tool to translate ARB files.
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

Problems with DeepL API key #14

Closed FluffyBunniesTasteTheBest closed 1 month ago

FluffyBunniesTasteTheBest commented 1 month ago

Thank you very much for providing flutter_auto_translator.

After setting it up, running dart run auto_translator prints the following error:

auto_translator v2.3.2
═════════════════════
NoSuchMethodError: The method 'map' was called on null.
Receiver: null
Tried calling: map(Closure: (dynamic) => dynamic)

Configuration:

The configuration in l10n.yaml lools like this:

arb-dir: lib/l10n
template-arb-file: awesome_app_en.arb
output-localization-file: s.dart
output-class: S
use-escaping: true
# untranslated-messages-file: missing_translations.txt

# flutter_auto_translator configuration:
translator:
  #Defaults to Google Translate.
  service: DeepL
  key_file: data/keys/auto_translator_keys.json

  targets:
    - es
    - fr

The keyfile at data/keys/auto_translator_keys.json contains:

{
    "google": "CLOUD_TRANSLATE_API_KEY",
    "deepL": "oooooooo-oooo-oooo-oooo-oooooooooooo:fx"
}

Some more details:

When removing the trailing :fx from DeepL API key, the error message disappears, and dart run auto_translator instead prints:

auto_translator v2.3.2
═════════════════════
Translated 0 entries from app_en to es using deepL.
Translated 0 entries from app_en to fr using deepL.
Finished translating to 2 languages.

So it looks like as if there's an issue with the : in the key. But what's also interesting is that ... from app_en to ... should actually read ... from awesome_app_en to ....

Do you have any ideas how to fix or workaround this?

theLee3 commented 1 month ago

Thanks for bringing this to my attention.

I have just tested with the same keyfile entries, with the ":fx", and it ran without issue. I am not actually using DeepL though, so I kept the "oooooooo-oooo-oooo-oooo-oooooooooooo:fx". Can you confirm that you have the issue with the fake key as well, or is it only with a real key?

As for the "app_en" in the output, it is only meant to output the language code.

auto_translator v2.3.2
═════════════════════
Translated 0 entries from en to es-ES using deepL.
Translated 0 entries from en to de using deepL.
Translated 0 entries from en to fr using deepL.
Translated 0 entries from en to ja using deepL.
Translated 0 entries from en to tr using deepL.
Translated 0 entries from en to uk using deepL.
Finished translating to 6 languages.

This will be fixed shortly.

theLee3 commented 1 month ago

Output has been fixed in repo. Please let me know if you find out more about the keyfile issue as I have been unable to replicate.

FluffyBunniesTasteTheBest commented 1 month ago

@theLee3 Thanks for the quick response.

Using the fake key "deepL": "oooooooo-oooo-oooo-oooo-oooooooooooo:fx", does not throw the error, but leads to an output similar to yours. Unfortunately it refuses to translate any of the messages... ;-)

Maybe something's wrong with the DeepL API key - it's a key from the free plan? I've already tried generating a new key, but same behavior...

theLee3 commented 1 month ago

Thanks @FluffyBunniesTasteTheBest (great name & avatar btw). I will try with a real key when I get the chance later today and report back.

FluffyBunniesTasteTheBest commented 1 month ago

This seems to be related to the key's : character.

Adding a second : to the (real) key - "deepL": "oooooooo-oooo-oooo-oooo-oooooooooooo::fx" also prevents the error, but also doesn't translate.

Does the key's : need to be escaped?

theLee3 commented 1 month ago

Actually, I think that it has to do with the format (or an unexpected null value) in the response from DeepL. The reason it's only occurring with the correct key is bc that is the only time translations are returned.

theLee3 commented 1 month ago

The problem lies with the error handling from DeepL. I was able to reproduce the issue by using an unsupported language code. You may have a different error occurring, but the error info will now be provided in the console.

Please update your pubspec.yaml file as follows:

auto_translator: # 2.3.2
  git:
    url: https://github.com/theLee3/flutter_auto_translator

Then run dart pub get to grab the latest changes. Afterward, you should be able to track down the issue. Please let me know what you find.

FluffyBunniesTasteTheBest commented 1 month ago

Awesome! It's working with the github link:

Building package executable... 
Built auto_translator:auto_translator.
auto_translator v2.3.2
═════════════════════
hereslating from en to es using deepL ⠦
hereslating from en to es using deepL ⠹
hereslating from en to es using deepL ⠏
hereslating from en to es using deepL ⠴
hereslating from en to es using deepL ⠼
hereslating from en to es using deepL ⠙
Translated 538 entries from en to es using deepL.
hereslating from en to fr using deepL ⠦
hereslating from en to fr using deepL ⠸
hereslating from en to fr using deepL ⠋
hereslating from en to fr using deepL ⠇
hereslating from en to fr using deepL ⠦
hereslating from en to fr using deepL ⠸
Translated 538 entries from en to fr using deepL.
Finished translating to 2 languages.

The French translation contains plenty of unescaped apostrophes, but beside that, it's looking pretty good.

Just to verify, I've reverted pubspec.yaml back to auto_translator: ^2.3.2 and the issue came back.

Again, thank you very much.

theLee3 commented 1 month ago

Great! Version 2.3.3 has been published to pub.dev.

Thank you for your help @FluffyBunniesTasteTheBest.

FluffyBunniesTasteTheBest commented 1 month ago

Awesome! Thank you!