1

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(&$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?

2 Answers 2

1

Check, if the variable is set, to avoid the error:

function theme_preprocess_block(&$variables) {
  if (isset($variables['content']['#links']['zh-hans']['title'])) {
    $variables['content']['#links']['zh-hans']['title'] = '中文';
  }
}
5
  • Of course, I changed. I described it in 2 nd line
    – Crantisz
    Jun 24, 2016 at 8:49
  • Did you use admin/config/regional/language/edit/zh-hans/**translate**?
    – 4uk4
    Jun 24, 2016 at 8:54
  • I tryed /admin/config/regional/language/edit/en/translate and /admin/config/regional/language/edit/zh-hans/translate
    – Crantisz
    Jun 24, 2016 at 8:54
  • OK, if this does not help, then you need the preprocess. You only have to check, if the variable is set, to avoid the error. I change my answer.
    – 4uk4
    Jun 24, 2016 at 9:06
  • thanx, a tryed this, errors doesn't appear until now
    – Crantisz
    Jun 24, 2016 at 9:12
1

Use this code for language switcher block with Language Icons module:

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

It just replaces language name and saves country flag. Insert this code in .theme file of your theme and change THEMENAME with name of your theme.

Your Answer

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

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