The correct way to change the name of the language in the language switch I try to change the name of language in language switcher from Chinese, Simplified(简体中文) to 中文. Changing name in admin/config/regional/language/edit/zh-hans affects only English. So the language switcher looks like this:


  en/Chinese, Simplified(简体中文)


I created a function, but on some pages (e.g. node/1), it causes errors.

function theme_preprocess_block(&amp;$variables) {
   $variables['content']['#links']['zh-hans']['title'] = '中文';
}


The error I get is the following one.


  Fatal error: Call to a member function getText() on array in /var/www/mysite/core/includes/theme.inc on line 1697


How can I fix this?
Check, if the variable is set, to avoid the error:

function theme_preprocess_block(&amp;$variables) {
  if (isset($variables['content']['#links']['zh-hans']['title'])) {
    $variables['content']['#links']['zh-hans']['title'] = '中文';
  }
}