• Resolved zitrusblau

    (@zitrusblau)


    Hey,

    when translating content (with a defined source language set via dropdown as well as with automatic mode), the following error occurs when using a language with formality, like de_DE_formal:

    production.ERROR: Undefined array key "de_DE_formal" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key \"de_DE_formal\" at /site/wp-content/plugins/wpdeepl/deepl-configuration.class.php:128)

    How can this be resolved (unfortunately we cannot switch to default “de_DE”)?
    Using Polylang (Pro) with WP 6.1.x

    Thanks in advance!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter zitrusblau

    (@zitrusblau)

    Just checked the plugin settings again and found a setting for default formality level which I set to formal. But then the same error comes up as noted above and I’m unable to access this settings page now.
    Also the select dropdown field labels are totally empty. Values are set but since there’s no label, the fields seem empty even though they’re selectable.

    Plugin Author malaiac

    (@malaiac)

    I added the Polylang locale de_DE_formal (I had no DE locale set up before on my site)
    The DE language is set to formal in my DeepL settings.
    I created a German article from a French article, saved the draft, then translated from FR to DE.
    I had no problem.

    To solve potential conflicts, I added a function to stripe the _formal or_informal suffix of Polylang locales in the context of the WPDeepL behaviour.
    v2.3.3 has been uploaded and should solve your problem

    Thread Starter zitrusblau

    (@zitrusblau)

    Thanks for your fast response. But this raises another issue after updating:

    production.ERROR: substr(): Argument #2 ($offset) must be of type int, string given {"userId":1,"exception":"[object] (TypeError(code: 0): substr(): Argument #2 ($offset) must be of type int, string given at /site/public/wp-content/plugins/wpdeepl/deepl-configuration.class.php:108)

    I’d suggest to use str_replace() instead of substr() here.
    Did that to fix it temporarily for my local test site and tried to translate again: https://jmp.sh/SvmB6ad1

    This gives this warning then:

    production.ERROR: Array to string conversion {"userId":1,"exception":"[object] (ErrorException(code: 0): Array to string conversion at /site/public/wp-content/plugins/wpdeepl/client/deeplapi-translate.class.php:154)

    And still, the language select boxes on settings page seem to be empty:

    https://jmp.sh/iWZx4K4l

    Thread Starter zitrusblau

    (@zitrusblau)

    Sorry to bother again. In order to check if it’s only happening on certain steps involved I proceeded the way you wrote earlier:

    I created a German article from a French article, saved the draft, then translated from FR to DE.
    I had no problem.

    I added a native english content then duplicated that content for a german translation, saved this as draft but had the exact same error.

    BTW: I found that when saving a draft the plugin’s metabox tells me to save or publish the post first (via block editor). Need to reload the editor view in order to show the translation interface.

    Plugin Author malaiac

    (@malaiac)

    This error :

    production.ERROR: substr(): Argument #2 ($offset) must be of type int, string given {"userId":1,"exception":"[object] (TypeError(code: 0): substr(): Argument #2 ($offset) must be of type int, string given at /site/public/wp-content/plugins/wpdeepl/deepl-configuration.class.php:108)
    

    show a problem with your installation. It’s situated just after get_locale()

    $locale = get_locale();
    
    		if( strpos( $locale, '_formal' ) != false ) {
    108:			$locale = substr( '_formal', '', $locale );
    		}

    get_locale should always return a string.

    Could you list your plugins and/or your custom setup ?

    Thread Starter zitrusblau

    (@zitrusblau)

    Hey,

    no problem with the return value of get_locale(), I get a valid string “de_DE_formal”.
    It’s actually this line in your code which is causing trouble:

    $locale = substr( '_formal', '', $locale );

    please check https://www.php.net/manual/en/function.substr for reference. 2nd parameter ($offset) needs to be string.
    So I fixed it for me like this:

    $locale = str_replace('_formal', '', $locale );
    Thread Starter zitrusblau

    (@zitrusblau)

    Ok, and then there’s another small issue. The selected languages on settings page are correctly translated but those in the editor UI are not:

    https://jmp.sh/YM5bqwOS
    https://jmp.sh/UYx0fand

    Thread Starter zitrusblau

    (@zitrusblau)

    Hey, any news in this regard? The issue is not really resolved…

    Plugin Author malaiac

    (@malaiac)

    That was a brain fart. Fixed in 2.3.5

    Thread Starter zitrusblau

    (@zitrusblau)

    Thanks!

    Still having this problem with empty language select boxes in plugin settings then (https://jumpshare.com/v/SEl5yTmdWwCdoBIzK72P) and this thing:

    Ok, and then there’s another small issue. The selected languages on settings page are correctly translated but those in the editor UI are not:

    https://jmp.sh/YM5bqwOS
    https://jmp.sh/UYx0fand

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Bug with formal language code’ is closed to new replies.