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) »
  • Switch language to the users language
Pages: [1] 2

Author Topic: Switch language to the users language  (Read 8207 times)

cronix

  • Guest
Switch language to the users language
August 30, 2009, 11:13:21 am
I am very impressed by CiviCRM and I will use it in my new website (CiviCRM 2.2 and Drupal 6). I have one question for wich I cannot find an answer on the site. My site will run in three different languages. For that I have two questions:
1. Is it possible to post an event in only one language? For example. How do I display Dutch events only on the Dutch pages of my site.
2. How can I make CiviCRM switch it's language together with the language of my Drupal site? I am using langue prefixed in Drupal. CiviCRM is now showing it's interface in CiviCRM's default language regardless of the language that is set by the Drupal user.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Switch language to the users language
August 31, 2009, 08:49:21 am
Quote from: cronix on August 30, 2009, 11:13:21 am
1. Is it possible to post an event in only one language? For example. How do I display Dutch events only on the Dutch pages of my site.

I think you might need to use some custom code here, and/or categorise your events by language (and display only events of a given category).

Quote
2. How can I make CiviCRM switch it's language together with the language of my Drupal site? I am using langue prefixed in Drupal. CiviCRM is now showing it's interface in CiviCRM's default language regardless of the language that is set by the Drupal user.

I don’t think this is possible in CiviCRM 2.2, but I’ll fix this for CiviCRM 3.0 – and if the fix is trivial, I’ll backport it so 2.2.9 (or 2.2.10) has this functionality.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

guelder

  • Guest
Re: Switch language to the users language
October 19, 2009, 09:02:11 am
Hallo Piotr,

is it already possible to use the language of my drupal site in civiCRM? I have civiCRM 3.0.1 and drupal 6.14

Dimitri

guelder

  • Guest
Re: Switch language to the users language
October 22, 2009, 05:54:42 am
Didn't anybody do that? That's the base necessity for multilanguage sites on drupal.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Switch language to the users language
October 22, 2009, 08:03:57 am
I’m very busy with a main feature for the 3.1 release right now, but I’ll check this early next week and if it’s still not fixed (I’m pretty sure I fixed CiviCRM so that we properly inherit the language from the locale module, though…) I’ll fix that for 3.0.2.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

sinasquax

  • Guest
Re: Switch language to the users language
November 10, 2009, 11:21:16 am
Hello, is this feature done ?

I try to sync the drupal language with the civicrm language but i don't find the solution.

I tried :

global $tsLocale;
global $language;
$tsLocale = ($language->language != 'en') ? 'en_US' : 'fr_FR'; // Why we must invert the test ???

in the civicrm_initialize() function and it works (partially) but not for profile added in the drupal user form (and it's what i need  :()

(sorry for my bad english)

sinasquax

  • Guest
Re: Switch language to the users language
November 10, 2009, 12:19:18 pm
I finally get it working with this code (in civicrm_initialize of civicrm.module (drupal)) :

global $language;

$locale = ($language->language == 'en') ? 'en_US' : 'fr_FR';
$session =& CRM_Core_Session::singleton();
$session->set('lcMessages', $locale);

But it must be better implemented for $locale <-> $language conversion.

Is somebody can tell me if this code will not create possible bad behaviors ?

Thank you
« Last Edit: November 10, 2009, 01:06:01 pm by sinasquax »

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Switch language to the users language
November 12, 2009, 05:33:46 am
I’m sorry, I was very busy with my 3.1 issues before pushing 3.1.alpha1 out the door. I’ll look into this problem by the end of the week and fix for 3.0.3/3.1.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Switch language to the users language
November 18, 2009, 08:52:41 am
Hi, I finally fixed this for the next CiviCRM release (and it will make it into 3.1.alpha2). If you want to backport to 3.0, r25112 added the language inheritance from Drupal and r25142 made the inheritance an option.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Switch language to the users language
December 04, 2009, 09:20:02 am
So I've just applied the patch http://fisheye2.atlassian.com/changelog/CiviCRM/?cs=25112 to my 3.0.2 version, but using the locale module's language switcher does not effectively change the CiviCRM locale. It moves from http://mydomain.ca/fr/civicrm to http://mydomain.ca/en/civicrm, changing the language of my menus but none of the CiviCRM stuff. Shouldn't it pick that up right away?

I've been considering writing a small module to do this by using hook_translation_link_alter(&$links, $path), and changing the links so that they invoked a function that would
  • load CiviCRM
  • do whatever processing deals with &lcMessages=fr_FR in a CiviCRM page, and then
  • redirect to the appropriate language page.

But I haven't gone so far as to find what CiviCRM function to call.

I'm worried I'm repeating work you may have already done, Piotr, but want to contribute if there is still an issue here or just pick up what you have done in terms of a fix.

Cheers,
Joe
« Last Edit: December 04, 2009, 09:23:43 am by JoeMurray »
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Switch language to the users language
December 04, 2009, 11:12:11 am
Playing around a bit more reveals that the lcMessages=xx_XX key-value pair is properly processed by Drupal without further work, so I'll just rewrite the language changing urls using the hook to add this to them.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Switch language to the users language
December 04, 2009, 01:25:15 pm
Adding the following code to drupal/civicrm.module fixes the language switching problem I had. It makes the Drupal locale module's language switching block work to change CiviCRM's as well as Drupal's locale.

I'll post as a patch shortly to JIRA.

function civicrm_translation_link_alter( &$links, $path ) {
    if ( ! civicrm_initialize( ) ) {
        return;
    }
   // an array of xx_YY locales
   static $locales = null;
   if ($locales === null) {
      require_once 'CRM/Core/I18n/PseudoConstant.php';
      $locales = array_keys(CRM_Core_I18n_PseudoConstant::languages());
      sort($locales);
   }

   // an array of xx to xx_YY mappings (naive, as pt_PT will trump pt_BR
   // and en_US will trump other English entries, but works in our case)
   static $prefixes = null;
   if ($prefixes === null) {
      foreach ($locales as $locale) {
         $prefixes[substr($locale, 0, 2)] = $locale;
      }
   }

   // modify the links so that an appropriate query string is added to them to cause
   // CiviCRM's locale to be updated
   // Take first CiviCRM locale that either matches Drupal’s xx_YY
   // or begins with Drupal’s xx (so Drupal’s pt_BR will return
   // CiviCRM’s pt_BR, while Drupal’s pt will return CiviCRM’s pt_PT)
   global $language;   
   foreach ( $links as $langkey => $link ) {
       if (in_array( $link['language']->language, $locales)) {
         $links[$langkey]['query'] =  array( 'lcMessages' => $link['language']->language);
      } elseif (in_array($link['language']->language, array_keys($prefixes))) {
         $links[$langkey]['query'] =  array( 'lcMessages' =>  $prefixes[$link['language']->language] );
      } else {
         drupal_set_message( t('CiviCRM does not have @lc locale enabled.', array('@lc' => $link['language']->language) ), 'warning' );
      }
   }

}
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Switch language to the users language
December 07, 2009, 04:44:17 am
Thanks a lot, Joe, for taking care of it! It’s most appreciated. I’ll fix our codebase to do the right thing for 3.1.beta2.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Switch language to the users language
December 07, 2009, 09:48:14 am
My pleasure.

Note that I've provided a slightly improved patch that will also retain the query string in the JIRA issue: http://issues.civicrm.org/jira/browse/CRM-5493 (it's the Dec 7 3kb attachment).
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

wdouglascampbell

  • Guest
Re: Switch language to the users language
May 05, 2010, 10:27:44 am
Two issues.  The above posts indicate that this patch should have been applied to version 3.1 but it is not in there.  I am running version 3.1.4 and the functions don't exist in the civicrm.module file.

2nd issue is that Civicrm and Drupal use different strings to define languages.  For example, Chinese in Drupal is zh-hans while in Civicrm it is zh_CN.  Civicrm is handling this better but it would be good to integrate more seamlessly with Drupal so I recommend putting the following line in the previously submitted function.

Code: [Select]
   // an array of xx to xx_YY mappings (naive, as pt_PT will trump pt_BR
   // and en_US will trump other English entries, but works in our case)
   static $prefixes = null;
   if ($prefixes === null) {
      foreach ($locales as $locale) {
         $prefixes[substr($locale, 0, 2)] = $locale;
      }
   }
   // support Drupal's tag for simplified chinese
   $prefixes['zh-hans']='zh_CN';

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Switch language to the users language

This forum was archived on 2017-11-26.