In future versions of this module, would it be conceivable to store the redirect page in the variables table instead? This would make redirecting to language specific pages possible.

Comments

frankcarey’s picture

How did I store it? By adding a field to the contact table?

You may want to have a different redirect per page, so how about storing a default redirect that can be set?

what is the limit (roadblock) to translation as it is now?

d.sibaud’s picture

+1

jmlavarenne’s picture

If you store it with variable_get() and variable_set(), with a variable for each page, instead of in the contact table, we can add those variables as multilingual variables in the settings file, and a separate variable will be stored in the variables table for each language. See this : http://drupal.org/node/313272

You wouldn't need an .install file with the module anymore.

db_query() in contact_redirect_contact_admin_edit_submit() and contact_redirect_get() would need to be modified to do variable_get().

At this point I would not know how to preform translation on the redirection. I used a trick - the destination pages have the same path but because the language prefix gets added before the path alias, a different page can be reached for each language.

frankcarey’s picture

Trying to get this feature in core.
http://drupal.org/node/306662

One option put forth is use of d6 triggers instead. Would that work for the multi-lingual folks moving forward?

In general, doesn't one of the new translation modules handle this better now where folks are redirected to translated content if it exists?

jmlavarenne’s picture

I don't think it will work as suggested. I replied in the thread here :

http://drupal.org/node/306662#comment-1389966

I don't have any experience with triggers and actions yet, so I can't make suggestions on that matter.

If you don't want to use the variables table but would like to provide multilingual support, my other suggestion is that your module could have it's own table instead of adding a field to the contact table, with cid, language, and redirect fields.

It seems more complicated than using the variables table because i18n module takes care of translating variables.

Your module could query this table with a method similar to this :

function contact_redirect_get($cid = FALSE) {
  global $language;
  if ($cid) {
    $redirect = db_result(db_query("SELECT redirect FROM {TABLE_NAME} WHERE cid = %d AND language = %s", $cid, $language->language));           
  }
  else {
    $redirect = '';
  }
  return $redirect;
}

It would require lots of changes elsewhere too, maybe with redirect fields for each language, one for each item returned by language_list().

frankcarey’s picture

I would be more keen to having a separate table instead of a variable for every contact form than a separate variable for every contact form. I would certainly want to make it easy as possible for users to have content be translatable, but I'm not sure we want to do something kind of weird to fill this limited use case, where you would want multiple redirect destinations based on language. Having a separate table would mean that this remains a contrib module. My ears are still open though.

jmlavarenne’s picture

Sure - if you build your module to use it's own table, and said table includes a field for language, I can help with the language detection process.

I recommend making these changes available only with the 6.x version, because language support is somewhat different in core with 5.x. I've used the 6.x patch in the other issue and it works well.

frankcarey’s picture

Is there a way to handle language specific stuff outside of this module? I don't mind creating hooks and the like, but i think a specific implementation would be out of scope for this module. I understand that system variables instead of storing values in the table directly would allow for this, but I've expressed my reservations about that method above. Any other ideas?

I'm moving forward with the 6.1.x patch that was submitted quite a while ago that uses the existing model instead of one of the proposed methods. A solution would then be in a 6.2.x version. Again, this module should work for multiple languages, but i just want us to make a good decision on how do do that.

frankcarey’s picture

Title: Redirect url as variable? » Add multi language support

changing title to better represent general issue.

frankcarey’s picture

Does the active translation module solve some issues?
http://drupal.org/project/active_translation

it looks like it would handle missing translations by providing untranslated content as a backup.

jmlavarenne’s picture

I don't think another module is needed if we find a way that is simple to implement and maintain using the core API.

What about calling translation_path_get_translations() on the path you retrieve from your query, then selecting the appropriate path from the array according to the user selected language, as defined by $language?

That way your module does not need to store the other language path, just the default language. Core provides the translation path.

frankcarey’s picture

I'll take a look at this function. Do you know of a contrib module that uses it?

It just seems like this should be abstracted out better, probably in core or with another module to handle the path translation. What I would expect is for this module to store 1 path only, and that some other module would intercept the redirect to change it on it's own based on language. This would mean that if I am in spanish and I go to /mypage that I would be immediately redirected to /myspanishpage instead. I think another module does this no? If it doesn't should that be written for this general use case of translating paths on the fly?

jmlavarenne’s picture

That would be great - store one path, and when your module retrieves it, use translation_path_get_translations() to get the paths for all translations to that content, then determine which one to use by looking at the current user's language in the $language variable.

frankcarey’s picture

seems like some other module should exist to do the second part. (use translation_path_get_translations() to get the paths for all translations to that content, then determine which one to use by looking at the current user's language in the $language variable)

What i would like to do is just hook into that module, let it's logic make the decisions as to where if any loaction to change the redirect to, and then just shove whatever it gives me into the #redirect field.

This is what I have in mind


$mypath = '<front>';


if (module_exists('path_translate')) {

  //all module then have this hook available
  $mypath = path_translate($mypath);
}

...
$form[#redirect] = $mypath;

jmlavarenne’s picture

I don't know if there is such a module - but here's what I think you could do without too much more code. No other module required but core modules.

/**
 * get the contact redirect for a particular contact category
 */

function contact_redirect_get($cid = FALSE) {
  if ($cid) {
    $redirect = db_result(db_query("SELECT redirect FROM {contact} WHERE cid = %d", $cid));
    // new code using the function and variable mentioned above
    if (module_exists('translation')) {
      // get the system path
      $source = drupal_lookup_path('source', $redirect);
      // get all translation paths for that system path
      $paths = translation_path_get_translations($source);
      // choose which path to use according to user language
      $systemPath = $paths[$language->language];
      // now get the path alias for that system path
      $redirect = drupal_get_path_alias($systemPath);     
    }   
  }
  else {
    $redirect = '';
  }
  return $redirect;
}

---------------------------------------------------------------------------------------

This is how I tested the functions in a template file to figure out exactly what is needed for this module

// check out how drupal_lookup_path() works;
echo $_GET['q'] . '<br/>';
$alias = drupal_lookup_path('alias', $_GET['q']);
echo $alias . '<br/>';;
$source = drupal_lookup_path('source', $alias);
echo $source . '<br/>';

// check out how translation_path_get_translations() works;
$paths = translation_path_get_translations($_GET['q']);
echo '<pre>';
print_r($paths);
print_r($language);
echo '</pre>';
echo $paths[$language->language] . '<br/>';
echo drupal_get_path_alias($paths[$language->language]);

The output will be something like this :

node/1620
zoom-coming-your-neighbourhood
node/1620

Array
(
    [en] => node/1620
    [fr] => node/1621
)
stdClass Object
(
    [language] => en
    [name] => English
    [native] => English
    [direction] => 0
    [enabled] => 1
    [plurals] => 0
    [formula] => 
    [domain] => 
    [prefix] => en
    [weight] => 0
    [javascript] => 
    [dir] => ltr
)

node/1620
zoom-coming-your-neighbourhood