0

I'm working on the php code of someone else and have a problem with the user/menu language. This is the code of the page with the dynamic price list for banner ads on this website. Depending on the selected menu language, the user can see the price of the banner ads which are for each menu language different.

Whenever the user is coming to this page the active banner ads price should be for the users menu language. Right now it's fixed on russian language and I don't know how to make it dynamicly or at least change/fix it to english.

Please have a look and let me konw if you might see a solution. Thanks!

<?php
class reklama_content
{
private $db;
private $cms;
private $valid;
private $data;
private $tools;

public function __construct()
{
$reg = Registry::getInstance();
$this->db = $reg->get('db');
$this->cms = $reg->get('cms');
$this->valid = $reg->get('Validate');
$this->data = $reg->get('methodData');
$this->tools = $reg->get('tools');
}

public function get_reklama_content()
{
$lang = language::getLang();

if ($_GET['ryb'])
  $ryb = $_GET['ryb'];
else
  $ryb = 'banners';

if ($ryb == 'banners')
  $ret = $this->getBanner($lang);
elseif ($ryb == 'classifieds')
  $ret = $this->getClassifieds($lang); 
return $ret;
}

 public function getClassifieds($lang)
 {
$contetn = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'classifieds_content'"));
$ret = $contetn['content_' . $lang];
return $ret;
}

public function getBanner($lang)
{
$header = array();
$top = array();
$center = array();
$bottom = array();

$banners = $this->db->selectAssoc($this->db->Select('*', 'banners', false, 'page_id', false, true));
$contetn_top = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'reklams_baner_top'"));
$contetn_bottom = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'reklams_baner_bottom'"));

foreach ($banners as $x => $y) {
  if ($y['position'] == 'header')
    $header[$x] = $y;
  elseif ($y['position'] == 'top')
    $top[$x] = $y; elseif ($y['position'] == 'center')
    $center[$x] = $y; elseif ($y['position'] == 'bottom')
    $bottom[$x] = $y;
}

$ret = $contetn_top['content_' . $lang];


$langs = ($this->tools->getAllLang(true));

$ret .= '
        <hr style="width: 100%; margin: 40px 0;" />
       <div class="rek_banner_conteiner header_conteiner">
            <span class="ban_title">' . l::top_banner1() . '</span>
            <img src="styles/them_01/img/banner_468x60.jpg" class="header_example" />
            <div class="lang_menu">' . l::menu_language1() . '<br />';

$ret .= '<span id="eng_header" >' . l::english() . '</span>';
$ret .= '<span id="de_header" >' . l::german() . '</span>';
$ret .= '<span id="rus_header" >' . l::russian() . '</span>';
$ret .= '<span id="tr_header" >' . l::turkish() . '</span>';
$ret .= '</div>';
foreach ($langs as $z => $g) {
  $ret .= '
            <div id="' . $g['name'] . '_header_box" class="hide">
                <table>
                    <tr class="order_table_title">
                        <td class="order_table_position">' . l::location() . '</td>
                        <td class="order_table_size">' . l::size1() . '</td>
                        <td class="order_table_date">' . l::fee_per_month() . '</td>
                    </tr>
                    ';
  foreach ($header as $z => $f) {
    $page = $this->db->selectArray($this->db->Select('title_' . $lang, 'pages', "`id` = '" . $f['page_id'] . "'"));
    $ret .= '<tr>
                                <td>' . $page['title_' . $lang] . '</td>
                                <td>' . $f['size'] . '</td>
                            ';
    if ($f['price' . '_header_' . $g['name']])
      $ret .= '<td>$ ' . $f['price' . '_header_' . $g['name']] . '</td>';
    else
      $ret .= '<td></td>';
    $ret .= '

                            </tr>';
  }
  $ret .= '
                </table>  
            </div>
        ';
}
$ret .= '</div>';

$ret .= $contetn_bottom['content_' . $lang];
return $ret;
}
}

?>
Stefan Weiss
  • 313
  • 1
  • 6
  • 15
  • what does language::getLang() return? – dudewad Jun 20 '13 at 20:46
  • It seems that `$ret` will contain text in all four languages. Is there a separate process (Javascript? CSS?) that hides the language-specific spans that are not needed? – George Cummins Jun 20 '13 at 20:49
  • @George Cummins As mentioned it's a code of someone else and I just noticed some additional style in the CSS. It's obvious that the work is not very good and I will try to stick to AbsoluteƵERØ idea... But thanks for your feedback & interest. – Stefan Weiss Jun 21 '13 at 15:52

1 Answers1

0

I have code in an answer about language detection here. It contains a cool little easily modifiable snippet I use to check who's coming from where based on their browser preferences for language. In short, you'll need to either detect the language from $_SERVER['HTTP_ACCEPT_LANGUAGE'] or detect a user preference (eg. ?lang=de ) to override their default language preference in their browser. That's if you're not using a custom URL like tr.example.com. Then you can do a switch(). Right now it looks like you're concatenating all of the language <span> tags together.

switch($lang){
  case "ru":
  //Russian
     $ret .= '<span id="rus_header" >' . l::russian() . '</span>';
  break;

  case "de":
  //German
     $ret .= '<span id="de_header" >' . l::german() . '</span>';
  break;

  case "tr":
  //Turkish
     $ret .= '<span id="tr_header" >' . l::turkish() . '</span>';
  break;

  default:
  //English
     $ret .= '<span id="eng_header" >' . l::english() . '</span>';

}

As my other post says (there's a video from Google). Ideally it's best if you have the content all in one language on a specific URL for that language. Then all of this magical language translation stuff happens without the user having to make a selection or guess if they're clicking the correct link in a language they're not familiar with.

Community
  • 1
  • 1
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35
  • Thanks a lot for your feedback, my PHP skills are not very good but I think you showed me the right direction. I will try to implement your suggestion to fix it. – Stefan Weiss Jun 21 '13 at 15:33