1

I'm using entity translation module for node localization and dpm($language_content) always gives english, which is my default language. This outcome is for all languages, I don't understand what is the problem.

1 Answer 1

2

The $language_content variable is not set to the language used for the currently shown node, but it contains the value set by the language negotiation providers.

See language_initialize(), which is the function that initialize that and other variables, and that is called from the following code.

  // Ensure the language is correctly returned, even without multilanguage
  // support. Also make sure we have a $language fallback, in case a language
  // negotiation callback needs to do a full bootstrap.
  // Useful for eg. XML/HTML 'lang' attributes.
  $default = language_default();
  foreach ($types as $type) {
    $GLOBALS[$type] = $default;
  }
  if (drupal_multilingual()) {
    include_once DRUPAL_ROOT . '/includes/language.inc';
    foreach ($types as $type) {
      $GLOBALS[$type] = language_initialize($type);
    }
    // Allow modules to react on language system initialization in multilingual
    // environments.
    bootstrap_invoke_all('language_init');
  }

The language negotiation providers are the ones you set in admin/config/regional/language/configure.

screenshot

If none of the provider is enabled, which what happens by default, that variable will be set with an object for English language.

2
  • Thanks. The Url row of Content language detection of disabled. Apr 4, 2016 at 11:22
  • Its strange that all was working correctly(nodes, menu translations) inspite of metatag module. Apr 4, 2016 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.