String translations not working after setting language in page preprocess function

drupal.stackexchange https://drupal.stackexchange.com/questions/233676

  •  27-12-2020
  •  | 
  •  

سؤال

I am using the domains module (D6) with multiple domains on a 1 site, and we have multiple languages on 1 domain. (We have to have this set up with no other option). Internationalization string translations is enabled and the translated strings in the t() function are in the database.

The domian language setting overrides the node language setting which causes the string translations not to work when having multiple languages on 1 domain.

I have overridden the domain language setting with the node language setting in the theme template_preprocess_page() function and works well but I think it happens too late in the process as the string translations still don't work.

What do I need to do to get the string translations to work?

function phptemplate_preprocess_page(&$vars, $hook) {
  global $language;

  // Reset Language to Page Node Level
  // Get the list of languages
  $languages = language_list();

  // Set up the new language code
  $new_lang_code = $vars['node']->language;

  // Make sure the required language object is actually set
  if (isset($languages[$new_lang_code])) {

    // Overwrite the global language object
    $language = $languages[$new_lang_code];
  }
  var_dump($language) // $language = node language setting
}
هل كانت مفيدة؟

المحلول

I have got this working now by moving the code into the preprocess_node() function instead.


function phptemplate_preprocess_node(&$vars, $hook) {
global $language;
$languages = language_list();
$new_lang_code = $vars['node']->language;

 if (isset($languages[$new_lang_code])) {  
  $language = $languages[$new_lang_code];  
 }
}

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى drupal.stackexchange
scroll top