Title: Bug with formal language code
Last modified: July 13, 2023

---

# Bug with formal language code

 *  Resolved [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/)
 * 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:
 *     ```wp-block-code
       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](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16892063)
 * 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](https://wordpress.org/support/users/malaiac/)
 * (@malaiac)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16892112)
 * 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](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16892174)
 * Thanks for your fast response. But this raises another issue after updating:
 *     ```wp-block-code
       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](https://jmp.sh/SvmB6ad1)
 * This gives this warning then:
 *     ```wp-block-code
       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](https://jmp.sh/iWZx4K4l)
 *  Thread Starter [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16892212)
 * 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](https://wordpress.org/support/users/malaiac/)
 * (@malaiac)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16893264)
 * This error :
 *     ```wp-block-code
       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()
 *     ```wp-block-code
       $locale = get_locale();
   
       		if( strpos( $locale, '_formal' ) != false ) {
       108:			$locale = substr( '_formal', '', $locale );
       		}
       ```
   
 * [get_locale ](https://developer.wordpress.org/reference/functions/get_locale/)
   should always return a string.
 * Could you list your plugins and/or your custom setup ?
 *  Thread Starter [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16894516)
 * 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:
 *     ```wp-block-code
       $locale = substr( '_formal', '', $locale );
       ```
   
 * please check [https://www.php.net/manual/en/function.substr](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:
 *     ```wp-block-code
       $locale = str_replace('_formal', '', $locale );
       ```
   
 *  Thread Starter [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16894622)
 * 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/YM5bqwOS)
   [https://jmp.sh/UYx0fand](https://jmp.sh/UYx0fand)
 *  Thread Starter [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16909104)
 * Hey, any news in this regard? The issue is not really resolved…
 *  Plugin Author [malaiac](https://wordpress.org/support/users/malaiac/)
 * (@malaiac)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16909326)
 * That was a brain fart. Fixed in 2.3.5
 *  Thread Starter [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * (@zitrusblau)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16909838)
 * Thanks!
   Still having this problem with empty language select boxes in plugin 
   settings then ([https://jumpshare.com/v/SEl5yTmdWwCdoBIzK72P](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/YM5bqwOS)
   > [https://jmp.sh/UYx0fand](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.

 * ![](https://s.w.org/plugins/geopattern-icon/wpdeepl.svg)
 * [Translation with DeepL API](https://wordpress.org/plugins/wpdeepl/)
 * [Support Threads](https://wordpress.org/support/plugin/wpdeepl/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdeepl/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdeepl/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdeepl/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [zitrusblau](https://wordpress.org/support/users/zitrusblau/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/bug-with-formal-language-code/#post-16909838)
 * Status: resolved