0

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?

0

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'] = '中文';
  }
}
  • Of course, I changed. I described it in 2 nd line – Crantisz Jun 24 '16 at 8:49
  • Did you use admin/config/regional/language/edit/zh-hans/**translate**? – 4k4 Jun 24 '16 at 8:54
  • I tryed /admin/config/regional/language/edit/en/translate and /admin/config/regional/language/edit/zh-hans/translate – Crantisz Jun 24 '16 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. – 4k4 Jun 24 '16 at 9:06
  • thanx, a tryed this, errors doesn't appear until now – Crantisz Jun 24 '16 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, privacy policy and cookie policy

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