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

targetLang="en" is deprecated, please use "en-GB" or "en-US" instead #44

Open
kalebheitzman opened this issue Mar 4, 2024 · 3 comments

Comments

@kalebheitzman
Copy link

Execute scheduled task: Autotranslation Fetch (filter_autotranslate\task\autotranslate_task)
... started 22:06:02. Current memory use 29.1 MB.
Debugging increased temporarily due to faildelay of 60
Executing autotranslation fetch jobs...
200 jobs found...
fetching en translation for d41d8cd98f00b204e9800998ecf8427e key...
... used 4 dbqueries
... used 0.015782117843628 seconds
Scheduled task failed: Autotranslation Fetch (filter_autotranslate\task\autotranslate_task),targetLang="en" is deprecated, please use "en-GB" or "en-US" instead.
Backtrace:
* line 156 of /filter/autotranslate/vendor/deeplcom/deepl-php/src/Translator.php: call to DeepL\Translator->buildBodyParams()
* line 108 of /filter/autotranslate/classes/task/autotranslate_task.php: call to DeepL\Translator->translateText()
* line 405 of /lib/classes/cron.php: call to filter_autotranslate\task\autotranslate_task->execute()
* line 208 of /lib/classes/cron.php: call to core\cron::run_inner_scheduled_task()
* line 125 of /lib/classes/cron.php: call to core\cron::run_scheduled_tasks()
* line 186 of /admin/cli/cron.php: call to core\cron::run_main_process()

This isn't technically a bug but it broke our entire app. The Readme might need updated to notify users of this. We have a custom plugin on Moodle that's based entirely on 2 letter locale codes and I haven't gotten into the internals yet to see if it will give us the en-US format. There might be other software out there that suffers from the same problem.

@JanEbbing
Copy link
Member

JanEbbing commented Mar 5, 2024

Hi, what is the bug here exactly? The information is in the readme:

Some target languages also include the regional variant according to ISO 3166-1, for example 'en-US', or 'pt-BR'. The source language also accepts null, to enable auto-detection of the source language.

and this is not a recent change, we haven't accepted en as a target language for years.

You can use Translator::getSourceLanguages() and Translator::getTargetLanguages() to query the currently accepted languages from the API, or use the constants we define in the library, note the comments for english:


    /** English language code, may only be used as a source language. */
    public const ENGLISH = 'en';

    /** British English language code, may only be used as a target language. */
    public const ENGLISH_BRITISH = 'en-GB';

    /** American English language code, may only be used as a target language. */
    public const ENGLISH_AMERICAN = 'en-US';

@kalebheitzman
Copy link
Author

@JanEbbing that's weird. Our plugin was working fine when using just en as a target language code and it just broke in the last few weeks with that deprecation notice. The documentation states that you have to pass a locale code in order for the glossary to work and unless we change our Moodle install to use regional variants we'll have to hardcode locales into the plugin to make it work with DeepL now.

On the readme it shows $translationResult = $translator->translateText('Hello, world!', 'en', 'fr'); but my understanding is that I now have to use en-US or en-GB, etc and that I cannot use en. Am I misunderstanding something here?

@JanEbbing
Copy link
Member

Hi @kalebheitzman - not sure why it broke, but we did not change anything in this regard. DeepL differentiates between a sourceLanguage (language the text is in, can be null in order to be inferred) and a targetLanguage (language to translate the text into) - the targetLanguage needs the regional variant to be specified, else it will throw an error (unfortunately only once you actually call the function, as we want users of older library versions to be able to use languages released after the library version).

In the example

$translationResult = $translator->translateText('Hello, world!', 'en', 'fr');

we call translate with a sourceLanguage of 'en' and a targetLanguage of 'fr', which is fine. On the other hand,

$translationResult = $translator->translateText('Bonjour, le monde!', 'fr', 'en');

would throw an error, you would need to write something like

$translationResult = $translator->translateText('Bonjour, le monde!', 'fr', 'en-GB');

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