Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

Узнать текущий язык


Recommended Posts

Как можно узнать выбранный язык? Т.е. хочу в зависимости от выбранного языка в header-е показывать разные логотипы.

Спасибо.

Link to post
Share on other sites

catalog/controller/common/header.php

<?php
class ControllerCommonHeader extends Controller {
	protected function index() {
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['language_code'])) {
			$this->session->data['language'] = $this->request->post['language_code'];
			
			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect(HTTP_SERVER . 'index.php?route=common/home');
			}
		}

т.е. язык пишется в сессию.

берите оттуда значение

  • +1 2
Link to post
Share on other sites

Спасибо, получилось!

Сделал так:

<?php if ($language_code=="ru") { ?>
      <a href="<?php echo str_replace('&', '&', $home); ?>"><img src="image/data/logo_ru.png" title="<?php echo $store; ?>" alt="<?php echo $store; ?>" /></a>
      <?php } else { ?>
	  <a href="<?php echo str_replace('&', '&', $home); ?>"><img src="image/data/logo_ua.png" title="<?php echo $store; ?>" alt="<?php echo $store; ?>" /></a>
	  <?php } ?>
Link to post
Share on other sites

файл/контроллера

if ($this->session->data['language'] == "ru") {
$this->data['logo_image_file'] = "logo_ru.png";
} else {
$this->data['logo_image_file'] = "logo_ua.png";
}

файл/шаблона

<a href="<?php echo str_replace('&', '&', $home); ?>">
<img src="image/data/<?php echo $logo_image_file; ?>" title="<?php echo $store; ?>" alt="<?php echo $store; ?>" />
</a>

имхо компактнее (;

  • +1 2
Link to post
Share on other sites

имхо компактнее (;

Спасибо!

Link to post
Share on other sites

  • 8 years later...

Добрый день. Подскажите, как можно получить id или название текущего языка сайта в header.tpl. Эти данные мне необходимо использовать в js.

Link to post
Share on other sites

Вопрос закрыт. Решение:

function getCookie(name) {
  var value = "; " + document.cookie;
  var parts = value.split("; " + name + "=");
  if (parts.length == 2) return parts.pop().split(";").shift();
}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.