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) »
  • Drupal language switcher
Pages: [1]

Author Topic: Drupal language switcher  (Read 4871 times)

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Drupal language switcher
November 13, 2013, 06:37:49 am
Some time ago, I published a Drupal theme snippet to make the language switcher work with CiviCRM:
http://www.bidon.ca/fr/node/584

Koumbit made a module out of it:
https://redmine.koumbit.net/projects/civicrm-public/repository/revisions/master/entry/civi-modules/civicrm_languageswitcher/civicrm_languageswitcher.module

In short, if we used the language switcher on a CiviCRM contribution/event page, Drupal removes the page arguments (?id=1&reset=1) from the URL, so it would cause a fatal error. In multi-lingual sites, using the CiviCRM language switcher isn't very practical either, since usually it's better for CiviCRM to inherit the language from the CMS.

I'm strongly inclined to propose to include that directly in CiviCRM. Anyone familiar with Drupal good practices could comment on whether this is a good or bad idea?

Here is the patch:

Code: [Select]
diff --git a/civicrm.module b/civicrm.module
index adf42ec..68000c7 100644
--- a/civicrm.module
+++ b/civicrm.module
@@ -839,6 +839,11 @@ function civicrm_theme_registry_alter(&$theme_registry) {
     // Now add it on at the end of the array so that it runs last.
     $theme_registry['page']['preprocess functions'][] = 'civicrm_preprocess_page';
   }
+
+  // Allow rewrite of theme_links__locale_block from this module, as it is not a theme modification.
+  $path = drupal_get_path('module', 'civicrm');
+  $theme_registry['links__locale_block']['theme path'] = $path;
+  $theme_registry['links__locale_block']['function'] = 'civicrm_languageswitcher_links__locale_block';
 }
 
 /**
@@ -876,6 +881,26 @@ function civicrm_preprocess_page(&$variables) {
 }
 
 /**
+ * Rewrite theme_links__locale_block()
+ *
+ * Make the language switcher work with civicrm, e.g. copy over the request arguments,
+ * which Drupal drops by default, otherwise the language switcher will cause errors when
+ * used on, for example, a contribution page, event registration, etc, because the 'id'
+ * request argument will be lost.
+ */
+function civicrm_languageswitcher_links__locale_block($variables) {
+  if (arg(0) == 'civicrm') {
+    foreach ($variables['links'] as $lang => $attr) {
+      $query = $_REQUEST;
+      unset($query['IDS_request_uri']);
+      unset($query['IDS_user_agent']);
+      $variables['links'][$lang]['query'] = $query;
+    }
+  }
+  return theme('links', $variables);
+}
+
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Drupal language switcher
November 13, 2013, 09:19:31 am
so right now, if you use the native drupal language switcher, it's broken right (well, at least for pages that have get params, so pretty much any page)?

Then it's a bug and should be fixed.

X+

P.S. not sure if symfony has a url router, but might be good we keep an eye on moving to nicer urls (eg. less ?reset=1, less id=42 and put the id in the /civicrm/whatever/{id})
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: Drupal language switcher
November 13, 2013, 10:03:16 am
Well, it never worked, so in a way, it was never supported. :)

CiviCRM has its own language switcher, but I find it really confusing for users, at least in Drupal. It has some use cases, but not that many. (and I don't know what Wordpress/Joomla users usually do, if there are any WP/J multi-lingual users out there)

However, as far as I know, multi-lingual sites are using either the theme snippet hack, or the Koumbit module, so may as well integrate it into core, imho. I'll PR for 4.5 and hopefully any bugs will be caught early on.
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

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: Drupal language switcher
November 18, 2013, 12:06:09 pm
So the suggested patch looks to me like it should work on 4.4.x. We'll try it out and let you know if it causes us grief on a site with args for event pages, petitions, and profiles.
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: Drupal language switcher
November 20, 2013, 09:18:25 am
We applied patch on a 4.4.1 site and found the error was not resolved.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

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: Drupal language switcher
November 20, 2013, 02:28:05 pm
Just in case: you did flush the Drupal cache?

Can you debug whether the function is being called? (ex: add a dsm/watchdog statement)
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

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: Drupal language switcher
May 03, 2014, 04:24:07 pm
We've had lots of trouble on a site where another provider was in charge of Drupal and we were doing CiviCRM. We think in the end that a complicating factor was our use of memcached on the site. If you have included this snippet in core, it would be useful to check if a CiviCRM caching system is being used and then to purge the cache when switching language. While this would be a performance hit and likely purge a bunch of data that is not localized, it would be relatively easy to implement and functionality is more than performance. Mathieu, if you point us in the right direction we could hopefully add this for memcache/memcached in the next little while.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

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: Drupal language switcher
May 07, 2014, 11:13:39 am
I thought memcached was broken for multi-lingual sites?
https://issues.civicrm.org/jira/browse/CRM-10250
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

btc97

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.5.4
  • CMS version: Drupal
  • MySQL version: 5.5.37
  • PHP version: 5.3.3
Re: Drupal language switcher
November 28, 2014, 06:54:43 pm
Was this patch ever committed to core?

I'd like to be able to remove the confusing CiviCRM language switcher block...

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: Drupal language switcher
December 01, 2014, 12:22:48 pm
@btc97: it has not yet been committed. I had not received much feedback and forgot about it. Want to give it a try?

I use the patch pretty much on all my civicrm sites.
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

btc97

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.5.4
  • CMS version: Drupal
  • MySQL version: 5.5.37
  • PHP version: 5.3.3
Re: Drupal language switcher
December 05, 2014, 07:21:05 am
Thanks @mathieu. I will definitely give it a try once I next have an event set up (won't be for a while), and report back. Good to have this as an option!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Drupal language switcher

This forum was archived on 2017-11-26.