Hi all, James,

I have been playing with Gallery 2 for a couple of days now and still discovering new stuff each day :)
I like it!

Here is the bug.

Drupal 4.6.3
Gallery 2
gallery.module cvs (Revision: 1.10, Wed Sep 21)

Drupal works well alone and Gallery too, actually everything is perfert, except one thing.

The default language does not follow NOR gallery NOR Drupal settings.

In Gallery (alone), it is set to Français (French) and works.
In Drupal (alone), it is set to French and works.

But with the integration, Gallery is in English. Here are the urls so you can see for yourself.

drupal alone : http://www.salsamontreal.com/montrealsalsa/
gallery alone : http://www.salsamontreal.com/montrealsalsa/outils/gallery2/
together : http://www.salsamontreal.com/montrealsalsa/gallery/

Edit : Just to double check, I have removed the Site Admin URL rewrite. Since if you don't, Gallery redirect you to the admin of Drupal. The setting is still in Français as he his suppose to be.

Thanks.

Comments

pitpit’s picture

this bug stand is the _gallery_init() function:

  $params = array('embedUri' => $embedUri,
                  'embedPath' => $embedPath,
                  'relativeG2Path' => $relativeG2Path,
                  'loginRedirect' => url('user/login'),
                  'activeUserId' => $user->uid,
                  'activeLanguage' => $user->language,
                  'fullInit' => $full);

This piece of code set the gallery language getting the user language whether the visitor is logged in or not.
If not, $user->language retrieve a null string, which is not understood by Gallery as a right 'activeLanguage'.

we can put the following code instead of, to set the gallery language with the drupal default language

if ($user->uid==0) //this is a visitor
{
  $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1'); //get drupal's default language
  $row = db_fetch_object($result);
  $lang = $row->locale;
}
else
{
  $lang = $user->language;
}

$params = array('embedUri' => $embedUri,
                'embedPath' => $embedPath,
                'relativeG2Path' => $relativeG2Path,
                'loginRedirect' => url('user/login'),
                'activeUserId' => $user->uid,
                'activeLanguage' => $lang,
                'fullInit' => $full);
alexandreracine’s picture

This piece of code set the gallery language getting the user language whether the visitor is logged in or not.
If not, $user->language retrieve a null string, which is not understood by Gallery as a right 'activeLanguage'.

This is not totally true. Since when I did my tests, I was logged in and not. The results where the same.

I think that a fallback aproch would be better in this case, since I think the value you are talking about, the user locale language, is in Drupal only if the "profile" module is enable. Witch is not at the moment on my website.

Something like this would be more proactive, I think.

This is only an algo since my coding days are way behind me.

if ([get the user profile language now]) = null then
   if ([get the Drupal language now]) = null then
      [get the gallery default language]
   endif
endif

This would have to be tested thought.

pitpit’s picture

hi,

This is not totally true. Since when I did my tests, I was logged in and not. The results where the same.

the stand-alone Gallery (http://www.salsamontreal.com/montrealsalsa/outils/gallery2/) appears to be in english (except the content you type in), isn't it ? Are you sure you enabled the french translation in gallery2 settings ?

I think that a fallback aproch would be better in this case, since I think the value you are talking about, the user locale language, is in Drupal only if the "profile" module is enable.

actually the 'locale' module is needed, not the 'profile' module

The code I posted may be bugprone if 'locale' module is not enabled. Here the fixed version:

  if ($user->uid==0 && module_exist('locale')) //this is a visitor
  {
    $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1'); //get drupal's default language
    $row = db_fetch_object($result);
    $lang = $row->locale;
  }
  else
  {
    $lang = $user->language;
  }
  
  $params = array('embedUri' => $embedUri,
                  'embedPath' => $embedPath,
                  'relativeG2Path' => $relativeG2Path,
                  'loginRedirect' => url('user/login'),
                  'activeUserId' => $user->uid,
                  'activeLanguage' => $lang,
                  'fullInit' => $full);
Something like this would be more proactive, I think.
if ([get the user profile language now]) = null then
   if ([get the Drupal language now]) = null then
      [get the gallery default language]
   endif
endif

the only case when drupal default language can not be retrieve ([get the Drupal language now]) = null) is when 'locale' module is not enabled, which means that the webmaster did not use another language than english. So we do not have to set the gallery language (which is english too)

to summary, that's what my code does:
- if user is not defined and 'locale' module is enabled, set the gallery language according to the default language setting in drupal.
- if not, 2 cases :
- webmaster does not user another language than english, ('locale' module is not enabled), $lang will be set with a null string (gallery2 will provide the only installed language too: english)
- the user is defined, $lang will be set with $user->language

Is it right for you ?

Damien
ps : Forgive me, I'm not fluent in english

alexandreracine’s picture

Hi Damien,

the stand-alone Gallery (http://www.salsamontreal.com/montrealsalsa/outils/gallery2/) appears to be in english (except the content you type in), isn't it ? Are you sure you enabled the french translation in gallery2 settings ?

No, the stand alone is in French :)

You said that the "bug stand is the _gallery_init() function". But where is that fonction? I have search a couple of files, but haven't found it. I would like to test your patch.

Thanks.

profix898’s picture

I have got the same problem here.

Drupal 4.6.3 with locale.module installed. Default lang ist German (de).
Gallery2 with default lang set to German, as well.

I already replaced the _gallery_init() code piece with the one posted above (#3). But it still doesnt
work. The language of gallery2 is always switched to english when I open it from drupal and stays
so until I manually reset gallery2 settings back to german.

Any ideas?

Regards, Thilo

pitpit’s picture

hi,

alexandreracine> the _gallery_init is in gallery.module file

profix> can you give us your website url and provide us an demo account to have a look on the bug?

alexandreracine’s picture

Hi dpdev,

Are you sure you enabled the french translation in gallery2 settings ?

Just to let you know, that the multilanguage module (in gallery2) does not have to be activated for the translation of gallery2 to work. Also, yes my website in set in French. Here is the description of the module:

MultiLanguage 1.0.0 1.0.0 Support item captions in multiple languages

So this is only if you want, for example, to have multi-language gallery2 with multi-language captions (descriptions). I made some tests, and it is exactly that. So my Multilanguage module in gallery2 is now deactivated and my gallery2 (stand-alone) is still in French.

-On another note, I'll test the patch too :)

alexandreracine’s picture

Feedback.

Profix : did you clear your cookies?

dpdev : I have try the second patch by dpdev, and half is working.

Guest user, are now in French. So I would guest that this part of the code...

if ($user->uid==0 && module_exist('locale')) //this is a visitor
  {
    $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1'); //get drupal's default language
    $row = db_fetch_object($result);
    $lang = $row->locale;
  }

...is working.

But, when logging as a user, it is still in English.

So by putting only this code, that we will call "second code"...

  $params = array('embedUri' => $embedUri,
                  'embedPath' => $embedPath,
                  'relativeG2Path' => $relativeG2Path,
                  'loginRedirect' => url('user/login'),
                  'activeUserId' => $user->uid,
                  'activeLanguage' => $lang,
                  'fullInit' => $full);

  $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1'); //get drupal's default language
  $row = db_fetch_object($result);
  $lang = $row->locale;

Everything is working. Visitor or not.

I made some tests. I used the "second code" (works) while not a visitor, uploaded your second patch, and refresh the browser. Gallery2 switch to English.

profix898’s picture

Sorry for my very delayed response to your messages!

@dpdev
I'm currently working on a new site and of course can provide you access to play with
my configuration! Tell me your email-adress (in case you still want to gain access) to
send the login information to. But you should read the rest of my posting before.

@all
I was able to figure out, that its not necessarily the gallery.module's code causing the
error. I used the following code to trace variables from the code.

  if ($user->uid==0 && module_exist('locale'))
  {
    $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1');
    $row = db_fetch_object($result);
    $lang = $row->locale;
  } else {
    $lang = $user->language;
    //$lang = 'de';
  }
  
  // print variable's values) 
  trigger_error("language: $lang", E_USER_ERROR);
  
  $params = array('embedUri' => $embedUri, ...

Output of code piece above:
user error: language: in /www/htdocs/w005e099/modules/gallery.module on line 321.

It seems like $user->language is an empty variable. When setting $lang manually to
'de' (look above) all works fine. But why? Do you have any idea why this variable is empty?
I will try to find a clue, look through the locale.module, etc. in hope to reveal this secret ;)

profix898’s picture

I just examined my database and it seems like drupal does not fill the language field in table users,
when the user signs up with the default language. I put various language IDs in that field for testing
purposes and voila the gallery switched to according language.

-> the gallery module is works fine (but drupal or perhaps the locale.module does not)

profix898’s picture

The following piece of code extends the one posted above and checks $user->language. If its
empty (= user uses drupal's default language) get default language as you do for guests. It
seems to works with any tested combination of gallery+drupal languages. So try out this one:

  if ($user->uid==0 && module_exist('locale'))
  {
    $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1');
    $row = db_fetch_object($result);
    $lang = $row->locale;
  } else {
    $lang = $user->language;
    if(empty($lang))
    {
      $result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1');
      $row = db_fetch_object($result);
      $lang = $row->locale;    
    }
  }
  
  $params = array('embedUri' => $embedUri,
                  'embedPath' => $embedPath,
                  'relativeG2Path' => $relativeG2Path,
                  'loginRedirect' => url('user/login'),
                  'activeUserId' => $user->uid,
                  'activeLanguage' => $lang,
                  'fullInit' => $full);
alexandreracine’s picture

Interesting ideed.

I'll try that latest code and give you some feedback.

alexandreracine’s picture

profix: Actually, I don't really have some time to test the new code. But, the "second code" is working fine.

I just examined my database and it seems like drupal does not fill the language field in table users,

My users don't have the privilege to be able to change they language. So why would drupal change that user related value?

iHawk’s picture

Version: » 4.6.x-1.x-dev

profix: I had the same problem here, and the code you posted in comment #11 does work perfectly as of now. Thanks!

alexandreracine’s picture

Does someone has the code adapted for Drupal 4.6 and Gallery 2.1 ?

Thanks.

alexandreracine’s picture

Status: Active » Closed (won't fix)

Well, the solution seems to upgrade. Closing.