Answers.Body: <p>Ah that does help. It's likely one of the contacts has a malformed preferred_language on their contact where it has EN instead of en_SOMETHING.</p>
  <p>From <a href="https://github.com/civicrm/civicrm-core/blob/c3a9a0894c3702d961d4bcaf61a3404e66c56371/CRM/Core/BAO/MessageTemplate.php#L343" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/c3a9a0894c3702d961d4bcaf61a3404e66c56371/CRM/Core/BAO/MessageTemplate.php#L343</a></p>
  <p>You can run a query on the database like <code>SELECT id FROM civicrm_contact WHERE preferred_language = 'EN'</code> to find the contact id.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-02T21:02:45.577Z
Answers.Text: Thank you! Seems like every English  contact was set as EN. It must have been acceptable on the previous server. Changed every one to en_US and now documents generate fine.
Answers.UserDisplayName: kapn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-02T20:54:28.067Z
Answers.LastActivityDate: 2023-10-02T20:54:28.067Z
Answers.UserDisplayName: Demerit
Body: <p>We're using CiviCase as a project tracker and document generator. It has been working fine, but I had to recently move the site to a new server. The directory structure, domain, database all stayed the same, but it's a new OS install on a new VPS.
  When we run &quot;Print/Merge Document&quot; on the &quot;Manage Case&quot; page, the task fails with the error &quot;Cannot instantiate malformed locale: EN&quot;. There is a little more info in the CiviCRM log, but it doesn't tell me anything more that I can make sense of. I assume there is some issue with the php or system locale, but I can't figure out what.</p>
  <p>Any thoughts?</p>
  <p>CiviCRM log:</p>
  <pre><code>Oct 02 16:21:24  [error]
  $Fatal Error Details = array:3 [
    &quot;message&quot; =&gt; &quot;Cannot instantiate malformed locale: EN&quot;
    &quot;code&quot; =&gt; null
    &quot;exception&quot; =&gt; CRM_Core_Exception {#11809
      -errorData: array:1 [
        &quot;error_code&quot; =&gt; 0
      ]
      #cause: null
      -_trace: null
      #message: &quot;Cannot instantiate malformed locale: EN&quot;
      #code: 0
      #file: &quot;/var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/Locale.php&quot;
      #line: 177
      trace: {
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/Locale.php:177 {
          Civi\Core\Locale::negotiate(string $preferred): Locale
          › if (!preg_match(';^[a-z][a-z]_[A-Z][A-Z]$;', $preferred)) {
          ›   throw new \CRM_Core_Exception(&quot;Cannot instantiate malformed locale: $preferred&quot;);
          › }
        }
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Subscriber/I18nSubscriber.php:61 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:251 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:73 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/CiviEventDispatcher.php:260 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php:249 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php:157 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Api4/Generic/AbstractAction.php:249 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:484 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:345 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:271 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Contact/Form/Task/PDFTrait.php:240 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Form.php:612 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php:153 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php:120 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Controller.php:203 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Page.php:103 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Controller.php:355 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Utils/Wrapper.php:98 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:292 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:69 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:36 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm.php:1199 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php:310 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php:334 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/plugin.php:517 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-admin/admin.php:259 { …}
      }
    }
  ]
  
  
  Oct 02 16:21:24  [debug] $backTrace = #0 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(443): CRM_Core_Error::backtrace(&quot;backTrace&quot;, TRUE)
  #1 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(CRM_Core_Exception))
  #2 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm.php(1199): CRM_Core_Invoke::invoke((Array:4))
  #3 /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php(310): CiviCRM_For_WordPress-&gt;invoke(&quot;&quot;)
  #4 /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php(334): WP_Hook-&gt;apply_filters(&quot;&quot;, (Array:1))
  #5 /var/www/civi.waccglobal.org/wordpress/wp-includes/plugin.php(517): WP_Hook-&gt;do_action((Array:1))
  #6 /var/www/civi.waccglobal.org/wordpress/wp-admin/admin.php(259): do_action(&quot;toplevel_page_CiviCRM&quot;)
  #7 {main}
  </code></pre>
  <p>We're running on WordPress 6.3.1 on Debian 12 (bookworm).
  CiviCRM version 5.63.2. Yes I do need to upgrade. However, experience has shown I should fix errors before doing so.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-28T23:44:40.750Z
Comments.Text: It's expecting something like en_US not just "en". The question is where is it getting that from. The rest of the stacktrace might actually be helpful.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-02T20:33:31.087Z
Comments.Text: Thanks @demerit I've included the full trace now
Comments.UserDisplayName: kapn
Tags: <civicase><printmerge>
Title: "malformed locale" error when merging document
ThreadText: # "malformed locale" error when merging document
  
  (Asked by: username_0 on 2023-09-28)
  
  We're using CiviCase as a project tracker and document generator. It has been working fine, but I had to recently move the site to a new server. The directory structure, domain, database all stayed the same, but it's a new OS install on a new VPS.
  When we run "Print/Merge Document" on the "Manage Case" page, the task fails with the error "Cannot instantiate malformed locale: EN". There is a little more info in the CiviCRM log, but it doesn't tell me anything more that I can make sense of. I assume there is some issue with the php or system locale, but I can't figure out what.
  
  Any thoughts?
  
  CiviCRM log:
  
  ```
  Oct 02 16:21:24  [error]
  $Fatal Error Details = array:3 [
    "message" => "Cannot instantiate malformed locale: EN"
    "code" => null
    "exception" => CRM_Core_Exception {#11809
      -errorData: array:1 [
        "error_code" => 0
      ]
      #cause: null
      -_trace: null
      #message: "Cannot instantiate malformed locale: EN"
      #code: 0
      #file: "/var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/Locale.php"
      #line: 177
      trace: {
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/Locale.php:177 {
          Civi\Core\Locale::negotiate(string $preferred): Locale
          › if (!preg_match(';^[a-z][a-z]_[A-Z][A-Z]$;', $preferred)) {
          ›   throw new \CRM_Core_Exception("Cannot instantiate malformed locale: $preferred");
          › }
        }
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Subscriber/I18nSubscriber.php:61 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:251 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php:73 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Core/CiviEventDispatcher.php:260 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php:249 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php:157 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/Civi/Api4/Generic/AbstractAction.php:249 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:484 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:345 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/MessageTemplate.php:271 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Contact/Form/Task/PDFTrait.php:240 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Form.php:612 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php:153 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php:120 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Controller.php:203 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/packages/HTML/QuickForm/Page.php:103 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Controller.php:355 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Utils/Wrapper.php:98 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:292 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:69 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php:36 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm.php:1199 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php:310 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php:334 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-includes/plugin.php:517 { …}
        /var/www/civi.waccglobal.org/wordpress/wp-admin/admin.php:259 { …}
      }
    }
  ]
  
  Oct 02 16:21:24  [debug] $backTrace = #0 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(443): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(CRM_Core_Exception))
  #2 /var/www/civi.waccglobal.org/wordpress/wp-content/plugins/civicrm/civicrm.php(1199): CRM_Core_Invoke::invoke((Array:4))
  #3 /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php(310): CiviCRM_For_WordPress->invoke("")
  #4 /var/www/civi.waccglobal.org/wordpress/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters("", (Array:1))
  #5 /var/www/civi.waccglobal.org/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action((Array:1))
  #6 /var/www/civi.waccglobal.org/wordpress/wp-admin/admin.php(259): do_action("toplevel_page_CiviCRM")
  #7 {main}
  
  ```
  
  We're running on WordPress 6.3.1 on Debian 12 (bookworm).
  CiviCRM version 5.63.2. Yes I do need to upgrade. However, experience has shown I should fix errors before doing so.
  
  **Tags:** civicase, printmerge
  
  > **Comments:**
  > **username_1**: It's expecting something like en_US not just "en". The question is where is it getting that from. The rest of the stacktrace might actually be helpful.  
  > **username_0**: Thanks @username_1 I've included the full trace now  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-02. Score: 1 | Accepted answer
  
  Ah that does help. It's likely one of the contacts has a malformed preferred\_language on their contact where it has EN instead of en\_SOMETHING.
  
  From <https://github.com/civicrm/civicrm-core/blob/c3a9a0894c3702d961d4bcaf61a3404e66c56371/CRM/Core/BAO/MessageTemplate.php#L343>
  
  You can run a query on the database like `SELECT id FROM civicrm_contact WHERE preferred_language = 'EN'` to find the contact id.
  
  > **Comments:**
  > **username_0**: Thank you! Seems like every English  contact was set as EN. It must have been acceptable on the previous server. Changed every one to en_US and now documents generate fine.  
  
  ---
  
  