CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Civi seems not to recognise the language on a multilingual WP install
Pages: [1]

Author Topic: Civi seems not to recognise the language on a multilingual WP install  (Read 2075 times)

vavroom

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 4
    • Part of a Whole
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress
  • MySQL version: 5.6.11
  • PHP version: 5.5.3
Civi seems not to recognise the language on a multilingual WP install
April 10, 2014, 12:24:46 pm
WordPress 3.8.2
CiviCRM 4.4.4
WPML 3.1.5

I am running a site in both FR and EN. I had a problem with profiles not being recognised (if visitor was on FR, the EN version of a form was still showing). This got resolved as per here: http://forum.civicrm.org/index.php/topic,32086.msg137259.html#msg137259

However, it appears that the issue runs deeper than that.

  • If a profile is inserted in a donation page, the EN version is always the one showing
  • If someone follows an opt-out link from email, they get the EN version also
  • If there is an error in a submitted form, the profile reloads in EN, with error messages in EN.

If anyone has run into a similar issue, or has any idea how to resolve it, I would be eternally thankful!

« Last Edit: April 10, 2014, 01:56:05 pm by vavroom »

vavroom

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 4
    • Part of a Whole
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress
  • MySQL version: 5.6.11
  • PHP version: 5.5.3
Re: Civi seems not to recognise the language on a multilingual WP install
April 10, 2014, 01:56:22 pm
The fix proposed earlier for the profile added the following code to wordpress.php
Code: [Select]
  function getUFLocale() {

    // WPML plugin
    if (defined('ICL_LANGUAGE_CODE')) {
      $language = ICL_LANGUAGE_CODE;
    }

    // TODO: how to get language with others WordPress plugin ?

    if (isset($language)) {
      return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
    } else {
      return NULL;
    }

  }

I thought to add that if ICL_LANGUAGE_CODE (the language variable used by WPML) wasn't defined, then load FR. This might work for me as my default language on the site should be FR. Like so:
Code: [Select]
  function getUFLocale() {

    // WPML plugin
    if (defined('ICL_LANGUAGE_CODE')) {
      $language = ICL_LANGUAGE_CODE;
    } else {
$language = "fr_CA";
}

    // TODO: how to get language with others WordPress plugin ?

    if (isset($language)) {
      return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
    } else {
      return NULL;
    }

  }

This got me part way. With that in, if someone submits a profile in FR, with missing required field, they get the errors in FR, with all the field labels in FR.

However, if someone submits a profile in EN, with missing required fields, they get the field labels in EN, but the errors in FR. The drop down are also in FR.

It appears that pages with URLS that add "civi bits", like ?page=CiviCRM&q=civicrm/profile/create are where the language is being lost.

Also, with that bit of code added, the URL for the optout page via email now delivers a "could not connect to database" error message.

I've removed that hard coding of the language because it didn't really solve the issue, but it indicates further that CiviCRM isn't playing nice with WPML (or vice versa).

Any thoughts?
« Last Edit: April 10, 2014, 02:12:43 pm by vavroom »

vavroom

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 4
    • Part of a Whole
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress
  • MySQL version: 5.6.11
  • PHP version: 5.5.3
Re: Civi seems not to recognise the language on a multilingual WP install
April 14, 2014, 07:58:39 am
Getting closer to a solution, HUGE thanks to Mathieu.

He identified that it had to do with the order in which the plugins were loaded. Adding:
Code: [Select]
define('CIVICRM_LATE_LOAD', 1);
in wp-config.php solves part of the issue.

There is still the issue of the opt-out link causing a DB Connexion error, but that appears to be a separate bug:
https://issues.civicrm.org/jira/browse/CRM-14465

LJo

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: Wordpress
  • MySQL version: 5.6
  • PHP version: 5.4
Re: Civi seems not to recognise the language on a multilingual WP install
August 14, 2014, 10:04:38 am
Hi,

I'm having the same problem with minor variations.

I'm trying to run a Wordpress / CiviCRM site in FR and EN.  My site uses the Polylang plugin rather than WPML (it has used the Polylang plugin for some time before the CiviCRM integration).

I need a way to display the CiviCRM forms in French on the french pages.  I have tried exactly the below with this in wordpress.php:

Code: [Select]
  function getUFLocale() {

    // WPML plugin
    if (defined('ICL_LANGUAGE_CODE')) {
      $language = ICL_LANGUAGE_CODE;
    } else {
$language = "fr_CA";
}

    // TODO: how to get language with others WordPress plugin ?

    if (isset($language)) {
      return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
    } else {
      return NULL;
    }

And this in wp-config.php:

Code: [Select]
define('CIVICRM_LATE_LOAD', 1);
I have tried setting French as the default language in CiviCRM. 

Forms continue to display in English.

Can anyone advise me on how to proceed?

Thanks

LJo

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: Wordpress
  • MySQL version: 5.6
  • PHP version: 5.4
Re: Civi seems not to recognise the language on a multilingual WP install
August 14, 2014, 12:00:08 pm
Update!

It is working.  I didn't realize that you translate the fields with the little squares to the left of the fields.

Thanks for posting this solution.

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Civi seems not to recognise the language on a multilingual WP install
August 14, 2014, 01:58:18 pm
Thanks for posting, glad to hear it works :)
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

LJo

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: Wordpress
  • MySQL version: 5.6
  • PHP version: 5.4
Re: Civi seems not to recognise the language on a multilingual WP install
August 22, 2014, 07:08:58 am
Update:  this is the solution that is working for me with Polylang:

Code: [Select]
  /**
   * Get the locale set in the hosting CMS
   *
   * @return string  with the locale or null for none
   */
  function getUFLocale() {
    // WPML plugin

    if (defined('ICL_LANGUAGE_CODE')) {
      $language = ICL_LANGUAGE_CODE;
    } else {
 
    // Polylang plugin

        global $curlang;
      if($curlang == "en") {
     $language = ‘en-CA’;
      }elseif($curlang == "fr") {
     $language = ‘fr-CA’;
      }

}

    // TODO: set language variable for others WordPress plugin

    if (isset($language)) {
      return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
    } else {
      return NULL;
    }
  }

I wonder if anyone can think of the best way to adapt it for all languages so that I can submit a patch for Polylang users?

Thanks!
Laura

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Civi seems not to recognise the language on a multilingual WP install
August 26, 2014, 02:13:27 pm
Excellent! Would be great to support Polylang.

To avoid having if/elseif per language, the following civicrm function "longForShort" does most of the work:

Code: [Select]
global $curlang;
if (! empty($curlang)) {
  $language = $curlang;
}

// the function already has this:
return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));

For regional translations (ex: fr_CA, en_CA), the code of longForShortMapping() in CRM/Core/I18n/PseudoConstant.php checks if a constant has been defined. Ex:

Code: [Select]
$longForShortMapping['en'] = defined("CIVICRM_LANGUAGE_MAPPING_EN") ? CIVICRM_LANGUAGE_MAPPING_EN : 'en_US';

To use it, you can define the following constants in your civicrm.settings.php:

Code: [Select]
define('CIVICRM_LANGUAGE_MAPPING_FR', 'fr_CA');
define('CIVICRM_LANGUAGE_MAPPING_EN', 'en_CA');

CiviCRM 4.5 will be out very soon, but if you could test & send a pull-request, I'm sure we could get it in, worst case, 4.5.1 + backport after. :)
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Civi seems not to recognise the language on a multilingual WP install

This forum was archived on 2017-11-26.