Please add an ability to alter or override the language list in entity_translation_languages().
Multilanguage and multidomain site, requires to have a specified set of the languages per domain.
It is possible by using domain_locale module etc. But currently it is impossible to affect in any way the set of the languages used by entity_translation as well as impossible to affect the generic language_list() function.

I propose a small patch which also can help to implement an integration with other modules like i18n etc in the entity_translation_languages() function.

CommentFileSizeAuthor
#1 domain_locale_support-1742792.patch1.4 KBsbuts
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sbuts’s picture

Here is a tiny function for domain_locale:

/**
 * Filters the languages list according to domain_locale settings.
 * @param $languages
 *
 */
function yourmodule_entity_translation_languages_alter(&$languages) {
  if (module_exists('domain_locale') && function_exists('domain_locale_language_list')) {
    $languages = domain_locale_language_list($languages);
  }
}
noShowP’s picture

Subscribing. This is something that is very useful and very easy to add in.

stefanos.petrakis@gmail.com’s picture

Issue summary: View changes

Tested this and looks nice and clean. But, it's questionable if it is necessary.

Overriding the language_list can actually be done, it's a static variable that you can change from your code.
For a detailed code example of that, look at the domain_variable_locale.module of the Domain Variable Locale (sub-module of Domain Variable), it's quite self-explanatory.

Here is a shorter version of that code, that you can also use as a first step, it doesn't use Domain Variables:

function hook_init() {
  // Make sure language stuff is enabled and that we are not visiting the "Languages" config page.
  if ( (drupal_multilingual() || module_exists('locale') ) && $_GET['q'] != 'admin/config/regional/language') { 
    $languages = language_list();
  
    // Filter the languages, like you suggest in your code.
    $domain_languages = domain_locale_language_list($languages);
    // Empty the list of languages in static cache.
    drupal_static_reset('language_list');
    // Reset to domain-specific languages.
    // The reference operator is the most interesting thing here.
    // Gives you the ability to modify the - freshly emptied - static variable.
    $languages = &drupal_static('language_list');
    $languages['language'] = $domain_languages;
  }
}
plach’s picture

Status: Needs review » Closed (won't fix)

Altering the language_list() result by fiddling with its static cache is not ideal, but it should be core's responsibility to allow for a cleaner way to achieve that. So I guess the alter should go in core, @stefanos.petrakis suggested a good workaround as an interim solution.