How to replace I18nVariableLanguageRealm controller? I have done custom module with .class.inc and .module file. Class file is added in module info file.

Inside class file:

/**
 * Controller for Language realms.
 */
class MyModuleI18nVariableLanguageRealm extends I18nVariableLanguageRealm {
  public function getKey() {
    return isset($this-&gt;current_key) ? $this-&gt;current_key : FALSE;
  }
}


Inside module file:

/**
 * Implements hook_variable_realm_info
 */
function mymodule_i18n_variable_variable_realm_info() {
  $realm['language'] = array(
    'title' =&gt; t('Language'),
    'weight' =&gt; 1,
    'controller class' =&gt; 'MyModuleI18nVariableLanguageRealm',
    'store class' =&gt; 'VariableStoreRealmStore',
    // Variables for this realm can be selected from a list.
    'select' =&gt; TRUE,
    'select path' =&gt; 'admin/config/regional/i18n/variable',
    // Name for variables that belong to this realm: 'multilingual' variable/s
    'variable name' =&gt; t('multilingual'),
    'variable class' =&gt; 'i18n-variable',
    // Automatically handle these variables in system settings forms.
    'form settings' =&gt; TRUE,
    'form switcher' =&gt; TRUE,
  );
  return $realm;
}


but debugging shows that custom controller isn't in use. What am I doing wrong here?
In the Drupal world 'replace' in your context is usually synonymous with 'alter'.

Try this:

function mymodule_i18n_variable_variable_realm_info_alter(&amp;$realm) {
  $realm['language']['controller class'] = 'MyModuleI18nVariableLanguageRealm';
}